Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/lib/api/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function getConversationSpans(
);

if (page === 0) {
stats = data.stats;
stats = data.stats ?? undefined;
title = data.title;
}
spans.push(...data.spans);
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/types/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
type InferOutput,
looseObject,
nullable,
nullish,
number,
object,
optional,
Expand Down Expand Up @@ -120,8 +121,11 @@ export const AgentConversationDetailsSchema = looseObject({
conversationId: string(),
title: nullable(string()),
spans: array(AgentConversationSpanSchema),
/** Added after the original envelope; optional for older self-hosted servers. */
stats: optional(ConversationStatsSchema),
/**
* Added after the original envelope; missing on older self-hosted servers.
* The server sends `null` on every page after the first.
*/
stats: nullish(ConversationStatsSchema),
});

export type AgentConversationDetails = InferOutput<
Expand Down
29 changes: 29 additions & 0 deletions packages/cli/test/lib/api/conversations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,35 @@ describe("getConversationSpans", () => {
expect(getCapturedUrls()[1]).toContain("cursor=page-2-cursor");
});

test("keeps first-page stats when later pages send stats: null", async () => {
const stats: ConversationStats = {
errors: 2,
llmCalls: 3,
toolCalls: 4,
toolErrors: 1,
totalCost: 0.5,
totalTokens: 900,
};
mockSequential([
{
body: makeEnvelope([makeSpan("span-page-1-aa11")], "Long run", stats),
headers: linkHeader("page-2-cursor"),
},
{
body: {
...makeEnvelope([makeSpan("span-page-2-bb22")], null),
stats: null,
},
},
]);

const result = await getConversationSpans(ORG, CONV_ID);

expect(result.spans).toHaveLength(2);
expect(result.stats).toEqual(stats);
expect(result.title).toBe("Long run");
});

test("returns truncated=true when pagination limit reached", async () => {
// Create responses that always have more pages
const responses = Array.from({ length: MAX_PAGINATION_PAGES }, (_, i) => ({
Expand Down
Loading