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
10 changes: 10 additions & 0 deletions packages/core/src/code_assist/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ describe('telemetry', () => {
prompt_id: 'p1',
traceId: 'trace-1',
},
response: {
resultDisplay: {
diffStat: {
model_added_lines: 5,
model_removed_lines: 3,
},
},
},
outcome: ToolConfirmationOutcome.ProceedOnce,
status: 'success',
} as unknown as CompletedToolCall,
Expand All @@ -327,6 +335,8 @@ describe('telemetry', () => {
traceId: 'trace-1',
status: ActionStatus.ACTION_STATUS_NO_ERROR,
interaction: ConversationInteractionInteraction.ACCEPT_FILE,
acceptedLines: '5',
removedLines: '3',
isAgentic: true,
});
});
Expand Down
26 changes: 24 additions & 2 deletions packages/core/src/code_assist/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import { EDIT_TOOL_NAMES } from '../tools/tool-names.js';
import { getErrorMessage } from '../utils/errors.js';
import type { CodeAssistServer } from './server.js';
import { ToolConfirmationOutcome } from '../tools/tools.js';
import {
computeModelAddedAndRemovedLines,
getFileDiffFromResultDisplay,
} from '../utils/fileDiffUtils.js';

export async function recordConversationOffered(
server: CodeAssistServer,
Expand Down Expand Up @@ -110,6 +114,8 @@ function summarizeToolCalls(

// Treat file edits as ACCEPT_FILE and everything else as unknown.
let isEdit = false;
let acceptedLines = 0;
let removedLines = 0;

// Iterate the tool calls and summarize them into a single conversation
// interaction so that the ConversationOffered and ConversationInteraction
Expand All @@ -136,7 +142,18 @@ function summarizeToolCalls(

// Edits are ACCEPT_FILE, everything else is UNKNOWN.
if (EDIT_TOOL_NAMES.has(toolCall.request.name)) {
isEdit ||= true;
isEdit = true;

if (toolCall.status === 'success') {
const fileDiff = getFileDiffFromResultDisplay(
toolCall.response.resultDisplay,
);
if (fileDiff?.diffStat) {
const lines = computeModelAddedAndRemovedLines(fileDiff.diffStat);
acceptedLines += lines.addedLines;
removedLines += lines.removedLines;
}
}
}
}
}
Expand All @@ -149,6 +166,8 @@ function summarizeToolCalls(
isEdit
? ConversationInteractionInteraction.ACCEPT_FILE
: ConversationInteractionInteraction.UNKNOWN,
isEdit ? String(acceptedLines) : undefined,
isEdit ? String(removedLines) : undefined,
)
: undefined;
}
Expand All @@ -157,15 +176,18 @@ function createConversationInteraction(
traceId: string,
status: ActionStatus,
interaction: ConversationInteractionInteraction,
acceptedLines?: string,
removedLines?: string,
): ConversationInteraction {
return {
traceId,
status,
interaction,
acceptedLines,
removedLines,
isAgentic: true,
};
}

function includesCode(resp: GenerateContentResponse): boolean {
if (!resp.candidates) {
return false;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/code_assist/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export interface ConversationInteraction {
status?: ActionStatus;
interaction?: ConversationInteractionInteraction;
acceptedLines?: string;
removedLines?: string;
language?: string;
isAgentic?: boolean;
}
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/utils/fileDiffUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import type { FileDiff } from '../tools/tools.js';
import type { DiffStat, FileDiff } from '../tools/tools.js';
import type { ToolCallRecord } from '../services/chatRecordingService.js';

/**
Expand All @@ -23,17 +23,14 @@ export function getFileDiffFromResultDisplay(
typeof resultDisplay.diffStat === 'object' &&
resultDisplay.diffStat !== null
) {
const diffStat = resultDisplay.diffStat as FileDiff['diffStat'];
if (diffStat) {
if (resultDisplay.diffStat) {
return resultDisplay;
}
}
return undefined;
}

export function computeModelAddedAndRemovedLines(
stats: FileDiff['diffStat'] | undefined,
): {
export function computeModelAddedAndRemovedLines(stats: DiffStat | undefined): {
addedLines: number;
removedLines: number;
} {
Expand Down
Loading