From fda2fa8c2a7509211d109b29c295f0789e9ba747 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 9 Jul 2026 22:16:13 +0200 Subject: [PATCH] fix: accept AgentRun Kafka session authority in Workbench --- web/hwlab-cloud-web/src/stores/workbench.ts | 27 +++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/web/hwlab-cloud-web/src/stores/workbench.ts b/web/hwlab-cloud-web/src/stores/workbench.ts index 01c6ad3a..10412fb8 100644 --- a/web/hwlab-cloud-web/src/stores/workbench.ts +++ b/web/hwlab-cloud-web/src/stores/workbench.ts @@ -1203,39 +1203,46 @@ export const useWorkbenchStore = defineStore("workbench", () => { return firstNonEmptyString(currentRequest.value?.traceId, activeTraceIdFromMessages(messages.value, turnStatusAuthority.value)); } + function normalizeTraceAuthoritySessionId(value: unknown): string | null { + const sessionId = normalizeWorkbenchSessionId(value); + const match = sessionId?.match(/^ses_agentrun_([0-9a-f]{8})_([0-9a-f]{4})_([0-9a-f]{4})_([0-9a-f]{4})_([0-9a-f]{12})$/iu); + if (!match) return sessionId; + return `ses_${match.slice(1).join("-").toLowerCase()}`; + } + function realtimeEventSessionId(event: WorkbenchRealtimeEvent): string | null { const turn = recordValue(event.turn); const snapshot = recordValue(event.snapshot); const traceEvent = recordValue(event.event); - return normalizeWorkbenchSessionId(firstNonEmptyString(event.sessionId, turn?.sessionId, snapshot?.sessionId, traceEvent?.sessionId)); + return normalizeTraceAuthoritySessionId(firstNonEmptyString(event.sessionId, turn?.sessionId, snapshot?.sessionId, traceEvent?.sessionId)); } function traceResultSessionId(result: AgentChatResultResponse | TraceSnapshot | Record | null | undefined): string | null { const value = recordValue(result); const runnerTrace = recordValue(value?.runnerTrace); const session = recordValue(value?.session); - return normalizeWorkbenchSessionId(firstNonEmptyString(value?.sessionId, runnerTrace?.sessionId, session?.sessionId)); + return normalizeTraceAuthoritySessionId(firstNonEmptyString(value?.sessionId, runnerTrace?.sessionId, session?.sessionId)); } function messageSessionAuthority(message: ChatMessage | null | undefined): string | null { - return normalizeWorkbenchSessionId(firstNonEmptyString(message?.sessionId, message?.runnerTrace?.sessionId)); + return normalizeTraceAuthoritySessionId(firstNonEmptyString(message?.sessionId, message?.runnerTrace?.sessionId)); } function traceOwnerSessionId(traceId: string | null | undefined, authoritySessionId: string | null | undefined): string | null { - const sessionId = normalizeWorkbenchSessionId(authoritySessionId); + const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId); if (sessionId) return sessionId; const id = firstNonEmptyString(traceId); if (!id) return activeSessionId.value; for (const [candidateSessionId, candidateMessages] of Object.entries(serverState.value.messagesBySessionId)) { - if (candidateMessages.some((message) => firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) === id)) return normalizeWorkbenchSessionId(candidateSessionId); + if (candidateMessages.some((message) => firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) === id)) return normalizeTraceAuthoritySessionId(candidateSessionId); } return activeSessionId.value; } function messageMatchesTraceAuthority(message: ChatMessage, traceId: string, authoritySessionId: string | null | undefined, ownerSessionId: string | null | undefined): boolean { if (message.role !== "agent" || firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) !== traceId) return false; - const sessionId = normalizeWorkbenchSessionId(authoritySessionId); - const ownerId = normalizeWorkbenchSessionId(ownerSessionId); + const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId); + const ownerId = normalizeTraceAuthoritySessionId(ownerSessionId); const messageSessionId = messageSessionAuthority(message); if (sessionId && ownerId && sessionId !== ownerId) return false; if (messageSessionId && ownerId && messageSessionId !== ownerId) return false; @@ -1246,7 +1253,7 @@ export const useWorkbenchStore = defineStore("workbench", () => { function shouldApplyActiveTraceAuthority(traceId: string | null | undefined, authoritySessionId: string | null | undefined): boolean { const id = firstNonEmptyString(traceId); const activeId = activeSessionId.value; - const sessionId = normalizeWorkbenchSessionId(authoritySessionId); + const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId); if (!activeId) return false; if (sessionId && sessionId !== activeId) return false; if (!id) return Boolean(sessionId && sessionId === activeId); @@ -1254,7 +1261,7 @@ export const useWorkbenchStore = defineStore("workbench", () => { const messageSessionId = messageSessionAuthority(message); if (messageSessionId && messageSessionId !== activeId) return false; if (sessionId && messageSessionId && sessionId !== messageSessionId) return false; - const knownSessionId = normalizeWorkbenchSessionId(firstNonEmptyString(turnStatusAuthority.value[id]?.sessionId, traceAuthorityById.value[id]?.sessionId)); + const knownSessionId = normalizeTraceAuthoritySessionId(firstNonEmptyString(turnStatusAuthority.value[id]?.sessionId, traceAuthorityById.value[id]?.sessionId)); if (knownSessionId && knownSessionId !== activeId) return false; if (sessionId && knownSessionId && sessionId !== knownSessionId) return false; return Boolean(sessionId || messageSessionId || knownSessionId || message); @@ -1263,7 +1270,7 @@ export const useWorkbenchStore = defineStore("workbench", () => { function shouldApplyTraceToMessage(message: ChatMessage, traceId: string, authoritySessionId: string | null | undefined): boolean { if (message.role !== "agent" || firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) !== traceId) return false; const activeId = activeSessionId.value; - const sessionId = normalizeWorkbenchSessionId(authoritySessionId); + const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId); const messageSessionId = messageSessionAuthority(message); if (activeId && messageSessionId && messageSessionId !== activeId) return false; if (sessionId && activeId && sessionId !== activeId) return false;