Merge pull request #2459 from pikasTech/fix/workbench-kafka-session-filter
Pipelines as Code CI / hwlab-nc01-v03-ci-poll- Success
Pipelines as Code CI / hwlab-nc01-v03-ci-poll- Success
修复 Workbench Kafka 实时事件会话归属
This commit is contained in:
@@ -1203,39 +1203,46 @@ export const useWorkbenchStore = defineStore("workbench", () => {
|
|||||||
return firstNonEmptyString(currentRequest.value?.traceId, activeTraceIdFromMessages(messages.value, turnStatusAuthority.value));
|
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 {
|
function realtimeEventSessionId(event: WorkbenchRealtimeEvent): string | null {
|
||||||
const turn = recordValue(event.turn);
|
const turn = recordValue(event.turn);
|
||||||
const snapshot = recordValue(event.snapshot);
|
const snapshot = recordValue(event.snapshot);
|
||||||
const traceEvent = recordValue(event.event);
|
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<string, unknown> | null | undefined): string | null {
|
function traceResultSessionId(result: AgentChatResultResponse | TraceSnapshot | Record<string, unknown> | null | undefined): string | null {
|
||||||
const value = recordValue(result);
|
const value = recordValue(result);
|
||||||
const runnerTrace = recordValue(value?.runnerTrace);
|
const runnerTrace = recordValue(value?.runnerTrace);
|
||||||
const session = recordValue(value?.session);
|
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 {
|
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 {
|
function traceOwnerSessionId(traceId: string | null | undefined, authoritySessionId: string | null | undefined): string | null {
|
||||||
const sessionId = normalizeWorkbenchSessionId(authoritySessionId);
|
const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId);
|
||||||
if (sessionId) return sessionId;
|
if (sessionId) return sessionId;
|
||||||
const id = firstNonEmptyString(traceId);
|
const id = firstNonEmptyString(traceId);
|
||||||
if (!id) return activeSessionId.value;
|
if (!id) return activeSessionId.value;
|
||||||
for (const [candidateSessionId, candidateMessages] of Object.entries(serverState.value.messagesBySessionId)) {
|
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;
|
return activeSessionId.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function messageMatchesTraceAuthority(message: ChatMessage, traceId: string, authoritySessionId: string | null | undefined, ownerSessionId: string | null | undefined): boolean {
|
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;
|
if (message.role !== "agent" || firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) !== traceId) return false;
|
||||||
const sessionId = normalizeWorkbenchSessionId(authoritySessionId);
|
const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId);
|
||||||
const ownerId = normalizeWorkbenchSessionId(ownerSessionId);
|
const ownerId = normalizeTraceAuthoritySessionId(ownerSessionId);
|
||||||
const messageSessionId = messageSessionAuthority(message);
|
const messageSessionId = messageSessionAuthority(message);
|
||||||
if (sessionId && ownerId && sessionId !== ownerId) return false;
|
if (sessionId && ownerId && sessionId !== ownerId) return false;
|
||||||
if (messageSessionId && ownerId && messageSessionId !== 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 {
|
function shouldApplyActiveTraceAuthority(traceId: string | null | undefined, authoritySessionId: string | null | undefined): boolean {
|
||||||
const id = firstNonEmptyString(traceId);
|
const id = firstNonEmptyString(traceId);
|
||||||
const activeId = activeSessionId.value;
|
const activeId = activeSessionId.value;
|
||||||
const sessionId = normalizeWorkbenchSessionId(authoritySessionId);
|
const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId);
|
||||||
if (!activeId) return false;
|
if (!activeId) return false;
|
||||||
if (sessionId && sessionId !== activeId) return false;
|
if (sessionId && sessionId !== activeId) return false;
|
||||||
if (!id) return Boolean(sessionId && sessionId === activeId);
|
if (!id) return Boolean(sessionId && sessionId === activeId);
|
||||||
@@ -1254,7 +1261,7 @@ export const useWorkbenchStore = defineStore("workbench", () => {
|
|||||||
const messageSessionId = messageSessionAuthority(message);
|
const messageSessionId = messageSessionAuthority(message);
|
||||||
if (messageSessionId && messageSessionId !== activeId) return false;
|
if (messageSessionId && messageSessionId !== activeId) return false;
|
||||||
if (sessionId && messageSessionId && sessionId !== messageSessionId) 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 (knownSessionId && knownSessionId !== activeId) return false;
|
||||||
if (sessionId && knownSessionId && sessionId !== knownSessionId) return false;
|
if (sessionId && knownSessionId && sessionId !== knownSessionId) return false;
|
||||||
return Boolean(sessionId || messageSessionId || knownSessionId || message);
|
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 {
|
function shouldApplyTraceToMessage(message: ChatMessage, traceId: string, authoritySessionId: string | null | undefined): boolean {
|
||||||
if (message.role !== "agent" || firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) !== traceId) return false;
|
if (message.role !== "agent" || firstNonEmptyString(message.traceId, message.runnerTrace?.traceId) !== traceId) return false;
|
||||||
const activeId = activeSessionId.value;
|
const activeId = activeSessionId.value;
|
||||||
const sessionId = normalizeWorkbenchSessionId(authoritySessionId);
|
const sessionId = normalizeTraceAuthoritySessionId(authoritySessionId);
|
||||||
const messageSessionId = messageSessionAuthority(message);
|
const messageSessionId = messageSessionAuthority(message);
|
||||||
if (activeId && messageSessionId && messageSessionId !== activeId) return false;
|
if (activeId && messageSessionId && messageSessionId !== activeId) return false;
|
||||||
if (sessionId && activeId && sessionId !== activeId) return false;
|
if (sessionId && activeId && sessionId !== activeId) return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user