Fix group chat agent connection failures (#900)
This commit is contained in:
@@ -23,6 +23,15 @@ export interface RoomAgent {
|
||||
invited: number
|
||||
}
|
||||
|
||||
export interface AgentAddResult {
|
||||
profile: string
|
||||
ok: boolean
|
||||
agent?: RoomAgent
|
||||
code?: string
|
||||
error?: string
|
||||
reason?: string
|
||||
}
|
||||
|
||||
export interface ChatMessage {
|
||||
id: string
|
||||
roomId: string
|
||||
@@ -133,7 +142,7 @@ export async function createRoom(data: {
|
||||
inviteCode: string
|
||||
agents?: { profile: string; name?: string; description?: string; invited?: boolean }[]
|
||||
compression?: { triggerTokens?: number; maxHistoryTokens?: number; tailMessageCount?: number }
|
||||
}): Promise<{ room: RoomInfo; agents: RoomAgent[] }> {
|
||||
}): Promise<{ room: RoomInfo; agents: RoomAgent[]; agentResults?: AgentAddResult[] }> {
|
||||
return request('/api/hermes/group-chat/rooms', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -141,7 +150,7 @@ export async function createRoom(data: {
|
||||
})
|
||||
}
|
||||
|
||||
export async function cloneRoom(roomId: string, data?: { name?: string; inviteCode?: string }): Promise<{ room: RoomInfo; agents: RoomAgent[] }> {
|
||||
export async function cloneRoom(roomId: string, data?: { name?: string; inviteCode?: string }): Promise<{ room: RoomInfo; agents: RoomAgent[]; agentResults?: AgentAddResult[] }> {
|
||||
return request(`/api/hermes/group-chat/rooms/${roomId}/clone`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
@@ -64,12 +64,36 @@ function generateCode(): string {
|
||||
return code
|
||||
}
|
||||
|
||||
function formatAgentFailures(results?: Array<{ ok: boolean; profile: string; error?: string; reason?: string }>): string | null {
|
||||
const failed = results?.filter(result => !result.ok) || []
|
||||
if (failed.length === 0) return null
|
||||
const details = failed.map(result => result.reason || result.error || result.profile).join('; ')
|
||||
return t('groupChat.agentAddFailedCount', { count: failed.length, details })
|
||||
}
|
||||
|
||||
function extractApiErrorMessage(err: any): string {
|
||||
const raw = err?.message || ''
|
||||
const jsonStart = raw.indexOf('{')
|
||||
if (jsonStart >= 0) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw.slice(jsonStart))
|
||||
if (parsed?.code === 'PROFILE_AGENT_CONNECT_FAILED' && parsed?.error) {
|
||||
return parsed.reason ? `${parsed.error}: ${parsed.reason}` : parsed.error
|
||||
}
|
||||
if (parsed?.error) return parsed.error
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
return raw || t('common.saveFailed')
|
||||
}
|
||||
|
||||
async function handleCreateRoom(name: string, inviteCode: string, userName: string, description: string, compression: { triggerTokens: number; maxHistoryTokens: number; tailMessageCount: number }) {
|
||||
try {
|
||||
store.setUserInfo(userName, description)
|
||||
const res = await store.createNewRoom(name, inviteCode, undefined, compression)
|
||||
showCreateModal.value = false
|
||||
message.success(t('groupChat.roomCreated'))
|
||||
const failureMessage = formatAgentFailures(res.agentResults)
|
||||
if (failureMessage) message.warning(failureMessage)
|
||||
else message.success(t('groupChat.roomCreated'))
|
||||
await store.joinRoom(res.room.id)
|
||||
} catch {
|
||||
message.error(t('common.saveFailed'))
|
||||
@@ -105,7 +129,9 @@ async function confirmCloneRoom() {
|
||||
cloneRoomName.value = ''
|
||||
cloneInviteCode.value = ''
|
||||
await store.joinRoom(res.room.id)
|
||||
message.success(t('groupChat.roomCloned'))
|
||||
const failureMessage = formatAgentFailures(res.agentResults)
|
||||
if (failureMessage) message.warning(failureMessage)
|
||||
else message.success(t('groupChat.roomCloned'))
|
||||
} catch {
|
||||
message.error(t('common.saveFailed'))
|
||||
}
|
||||
@@ -170,7 +196,7 @@ async function confirmAddAgent() {
|
||||
if (err.message?.includes('already')) {
|
||||
message.warning(t('groupChat.agentAlreadyInRoom'))
|
||||
} else {
|
||||
message.error(t('common.saveFailed'))
|
||||
message.error(extractApiErrorMessage(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1104,6 +1104,7 @@ jobTriggered: 'Job ausgelost',
|
||||
selectProfile: 'Wahlen Sie ein Profil',
|
||||
agentAdded: 'Agent hinzugefugt',
|
||||
agentAlreadyInRoom: 'Agent ist bereits in diesem Raum',
|
||||
agentAddFailedCount: '{count} Agent(en) wurden nicht hinzugefugt: {details}',
|
||||
noAgents: 'Keine Agenten in diesem Raum',
|
||||
members: 'Mitglieder',
|
||||
roomCreated: 'Raum erstellt',
|
||||
|
||||
@@ -1053,6 +1053,7 @@ export default {
|
||||
selectProfile: 'Select a profile',
|
||||
agentAdded: 'Agent added',
|
||||
agentAlreadyInRoom: 'Agent already in this room',
|
||||
agentAddFailedCount: '{count} agent(s) were not added: {details}',
|
||||
noAgents: 'No agents in this room',
|
||||
members: 'members',
|
||||
roomCreated: 'Room created',
|
||||
|
||||
@@ -1104,6 +1104,7 @@ jobTriggered: 'Job ejecutado',
|
||||
selectProfile: 'Seleccione un perfil',
|
||||
agentAdded: 'Agente agregado',
|
||||
agentAlreadyInRoom: 'El agente ya esta en esta sala',
|
||||
agentAddFailedCount: 'No se agregaron {count} agente(s): {details}',
|
||||
noAgents: 'No hay agentes en esta sala',
|
||||
members: 'Miembros',
|
||||
roomCreated: 'Sala creada',
|
||||
|
||||
@@ -1104,6 +1104,7 @@ jobTriggered: 'Job declenche',
|
||||
selectProfile: 'Selectionnez un profil',
|
||||
agentAdded: 'Agent ajoute',
|
||||
agentAlreadyInRoom: "L'agent est deja dans ce salon",
|
||||
agentAddFailedCount: "{count} agent(s) n'ont pas ete ajoutes : {details}",
|
||||
noAgents: 'Aucun agent dans ce salon',
|
||||
members: 'Membres',
|
||||
roomCreated: 'Salon cree',
|
||||
|
||||
@@ -1104,6 +1104,7 @@ export default {
|
||||
selectProfile: 'プロファイルを選択',
|
||||
agentAdded: 'エージェントが追加されました',
|
||||
agentAlreadyInRoom: 'このエージェントは既にルームにいます',
|
||||
agentAddFailedCount: '{count} 件のエージェントを追加できませんでした: {details}',
|
||||
noAgents: 'このルームにエージェントはいません',
|
||||
members: 'メンバー',
|
||||
roomCreated: 'ルームが作成されました',
|
||||
|
||||
@@ -1104,6 +1104,7 @@ export default {
|
||||
selectProfile: '프로필 선택',
|
||||
agentAdded: '에이전트가 추가되었습니다',
|
||||
agentAlreadyInRoom: '해당 에이전트가 이미 방에 있습니다',
|
||||
agentAddFailedCount: '{count}개의 에이전트를 추가하지 못했습니다: {details}',
|
||||
noAgents: '이 방에 에이전트가 없습니다',
|
||||
members: '멤버',
|
||||
roomCreated: '방이 생성되었습니다',
|
||||
|
||||
@@ -1104,6 +1104,7 @@ jobTriggered: 'Job acionado',
|
||||
selectProfile: 'Selecione um perfil',
|
||||
agentAdded: 'Agente adicionado',
|
||||
agentAlreadyInRoom: 'O agente ja esta nesta sala',
|
||||
agentAddFailedCount: '{count} agente(s) nao foram adicionados: {details}',
|
||||
noAgents: 'Nenhum agente nesta sala',
|
||||
members: 'Membros',
|
||||
roomCreated: 'Sala criada',
|
||||
|
||||
@@ -1056,6 +1056,7 @@ export default {
|
||||
selectProfile: '選擇一個設定檔',
|
||||
agentAdded: '智慧代理已新增',
|
||||
agentAlreadyInRoom: '該智慧代理已在房間中',
|
||||
agentAddFailedCount: '{count} 個智慧代理未新增:{details}',
|
||||
noAgents: '目前房間無智慧代理',
|
||||
members: '成員',
|
||||
roomCreated: '房間已建立',
|
||||
|
||||
@@ -1055,6 +1055,7 @@ export default {
|
||||
selectProfile: '选择一个配置',
|
||||
agentAdded: '智能体已添加',
|
||||
agentAlreadyInRoom: '该智能体已在房间中',
|
||||
agentAddFailedCount: '{count} 个智能体未添加:{details}',
|
||||
noAgents: '当前房间暂无智能体',
|
||||
members: '成员',
|
||||
roomCreated: '房间已创建',
|
||||
|
||||
Reference in New Issue
Block a user