fix: complete traces on idle, improve dashboard span/event/analytics views
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "opencode-agentlens",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"description": "OpenCode plugin for AgentLens — trace your coding agent's decisions, tool calls, and sessions",
|
||||
"type": "module",
|
||||
"main": "./dist/index.cjs",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user