fix: complete traces on idle, improve dashboard span/event/analytics views

This commit is contained in:
Vectry
2026-02-10 13:25:19 +00:00
parent 7534c709f5
commit 638a5d2640
5 changed files with 105 additions and 33 deletions

View File

@@ -111,11 +111,16 @@ export class SessionState {
metadata: safeJsonValue({ ...toolMeta, rawMetadata: metadata }),
});
const reasoningText =
title !== call.tool && title
? `Selected ${call.tool}: ${title}`
: `Selected tool: ${call.tool}`;
trace.addDecision({
type: DecisionType.TOOL_SELECTION,
chosen: call.tool as JsonValue,
alternatives: [],
reasoning: title,
reasoning: reasoningText,
durationMs,
parentSpanId: rootSpanId,
});
@@ -186,17 +191,29 @@ export class SessionState {
return Array.from(this.traces.keys());
}
/**
* Send the current trace state without ending the session.
* This creates a snapshot so data isn't lost if the process exits unexpectedly.
*/
flushSession(sessionId: string): void {
const trace = this.traces.get(sessionId);
if (!trace) return;
const rootSpanId = this.rootSpans.get(sessionId);
if (rootSpanId) {
trace.addSpan({
id: rootSpanId,
name: "session",
type: SpanType.AGENT,
status: SpanStatus.COMPLETED,
endedAt: nowISO(),
});
}
trace.end({ status: "COMPLETED" });
const transport = getClient();
if (transport) {
transport.add(trace.toPayload());
}
this.traces.delete(sessionId);
this.rootSpans.delete(sessionId);
}
}