feat: group chat session lifecycle, typing recovery, mention highlighting (#186)
* feat: restore group chat system with Socket.IO and SQLite persistence - GroupChatServer: Socket.IO server with room management, message history, typing indicators - SQLite storage for rooms, messages, and agent configuration - AgentClients: manages AI agent connections via socket.io-client, forwards @mentions to Hermes gateway - REST API: room CRUD, agent management, invite codes - Agent auto-restoration on server restart - Tests for all REST endpoints Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: add context-engine design document for group chat compression Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: handle special-character session search * fix: keep unicode dotted session search on quoted FTS path * feat: add context engine and group chat frontend UI - Context engine: three-zone compression (head/tail/summary) with LLM summarization, incremental updates, TTL cache, and graceful degradation - Frontend: group chat page with Socket.IO client, room sidebar, message list, agent/member display, create/join-by-code modals - Integration: wire context engine into agent-clients before /v1/runs - Refactor ChatStorage to use global DB (getDb/ensureTable) with gc_ prefix - Add i18n keys for group chat to all 8 locales - Add sidebar nav entry and router for group chat page Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove leftover main branch code from merge conflict resolution The `isNumericQuery`, `hasUnsafeChars`, and `runLikeContentSearch` functions no longer exist — they were replaced by HEAD's `shouldUseLiteralContentSearch` and `runLiteralContentSearch`. This dead code block caused a TypeScript compile error after the merge. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: install missing socket.io dep and type ack params Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: enable WebSocket proxy and fix socket.io transport for group chat - Add ws: true to Vite proxy config so WebSocket upgrade requests are forwarded to the backend - Allow both polling and websocket transports on server and client (polling as fallback when WebSocket upgrade fails through proxy) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: separate socket.io path from REST routes for group chat socket.io was mounted at /api/hermes/group-chat which intercepted all REST requests to /api/hermes/group-chat/rooms etc, returning "Transport unknown". Changed socket.io path to /api/hermes/group-chat/ws to avoid conflicts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: improve group chat UI, agent management, and socket.io reliability - Redesign GroupChatPanel with Naive UI, stacked agent avatars, and popover management - Match GroupChatInput style with single chat input, add IME composition handling - Add agent add/remove per room with profile selection and duplicate prevention - Use @multiavatar for SVG avatar generation with caching - Decouple joinRoom from socket.io, use REST API for data loading - Switch socket.io to default path with /group-chat namespace to avoid proxy conflicts - Restore agent connections after server is listening - Add getRoomDetail REST endpoint and duplicate agent prevention (409) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: server-side @mention routing with context compression status and queue - Move @mention detection from agent socket listeners to server-side processMentions() - Add per-room processing lock to block mention dispatch during compression - Queue mentions during processing, drain only the latest when ready - Emit context_status events (compressing/replying/ready) to room via Socket.IO - Frontend displays compression status indicator above input - Token-based compression trigger (100k threshold) with CJK-aware estimation - Fix compressor type errors (countTokens parameter type) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: improve group chat profile handling and session sync Refine group chat room/session behavior with per-room compression controls, sidebar updates, and better stale session cleanup so multi-profile group chat state stays consistent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: group chat improvements — session lifecycle, typing recovery, mention highlighting - Fix cross-profile session deletion with deferred delete queue - Move saveSessionProfile to after gateway response confirmation - Replace all console.log with logger in group-chat modules - Add server-side typing/context_status state tracking for room rejoin - Fix @ mention popup position to follow cursor - Add @ mention highlighting (blue) in chat message content - Fix mention regex to match all occurrences after HTML tags - Enable esbuild minify and treeShaking - Move @multiavatar/multiavatar to devDependencies - Add i18n keys for group chat features - Update tests for new functionality Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: bump version to 0.4.5 and move @multiavatar to devDependencies Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Zhicheng Han <zhicheng.han@mathematik.uni-goettingen.de>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
// ─── Agent Identity Instructions ────────────────────────────
|
||||
|
||||
import type { MemberInfo } from './types'
|
||||
|
||||
interface AgentInstructionsParams {
|
||||
agentName: string
|
||||
roomName: string
|
||||
agentDescription: string
|
||||
memberNames: string[]
|
||||
members: MemberInfo[]
|
||||
}
|
||||
|
||||
export function buildAgentInstructions(params: AgentInstructionsParams): string {
|
||||
let memberSection: string
|
||||
if (params.members.length > 0) {
|
||||
memberSection = params.members
|
||||
.map(m => m.description ? `- ${m.name}: ${m.description}` : `- ${m.name}`)
|
||||
.join('\n')
|
||||
} else if (params.memberNames.length > 0) {
|
||||
memberSection = params.memberNames.map(n => `- ${n}`).join('\n')
|
||||
} else {
|
||||
memberSection = '- 未知'
|
||||
}
|
||||
|
||||
return `你是"${params.agentName}",群聊房间"${params.roomName}"中的 AI 助手。
|
||||
|
||||
你的角色:${params.agentDescription}
|
||||
|
||||
当前房间成员:
|
||||
${memberSection}
|
||||
|
||||
规则:
|
||||
- 有人用 @${params.agentName} 提及你时才需要回复,重点回应提及你的人。
|
||||
- 回答简洁、对群聊有帮助。
|
||||
- 不要假装是人类,需要时明确表明自己是 AI。
|
||||
- 对话历史中包含多个人的消息,每条消息前标有发送者名字。
|
||||
- 对话开头可能包含之前的对话摘要,用于提供更早的上下文。
|
||||
- 回复最新一条提及你的消息。
|
||||
- 如果需要其他 agent 协作或明确回复某个人,使用 @名字 来提及对方。
|
||||
- 自行判断对话是否已经结束——如果问题已解决、达成共识、或对方只是陈述不需要回复,则不要再 @任何人,直接结束回复,避免产生无意义的循环对话。`
|
||||
}
|
||||
|
||||
// ─── Summarization Prompts ─────────────────────────────────
|
||||
|
||||
export function buildSummarizationSystemPrompt(): string {
|
||||
return `你是一个群聊对话的摘要助手。请创建一份结构化摘要,帮助 AI 助手快速理解完整的对话上下文并智能回复。
|
||||
|
||||
使用以下格式:
|
||||
|
||||
当前话题:
|
||||
- 现在在聊什么,目标是什么
|
||||
|
||||
已知结论:
|
||||
- 已达成哪些共识,哪些问题已经回答过
|
||||
|
||||
待回复消息:
|
||||
- 还剩谁的问题没回,下一步要做什么
|
||||
|
||||
关键人物:
|
||||
- 人名、角色、引用关系
|
||||
|
||||
重要上下文:
|
||||
- 不要丢时间线和立场变化
|
||||
- 少写废话,多保留"可行动信息"
|
||||
- 重点保留:谁说了什么、结论是什么、下一步是什么
|
||||
- 关键的 URL、代码片段、错误信息、约束条件
|
||||
|
||||
规则:
|
||||
- 基于事实,不要编造信息。
|
||||
- 保持简洁(500 字以内)。
|
||||
- 聚焦于帮助 AI 回复下一条消息的可行动信息。
|
||||
- 使用与对话相同的语言。
|
||||
- 不要回复对话内容,只输出摘要。`
|
||||
}
|
||||
|
||||
export function buildFullSummaryPrompt(): string {
|
||||
return '请对上方对话创建一份简洁的摘要。只输出摘要内容。'
|
||||
}
|
||||
|
||||
export function buildIncrementalUpdatePrompt(): string {
|
||||
return '对话自上次摘要后有了新的内容。请更新摘要,整合新消息。保持相同格式,更新所有部分。只输出更新后的摘要。'
|
||||
}
|
||||
Reference in New Issue
Block a user