mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 06:31:01 -07:00
Send accepted/removed lines with ACCEPT_FILE telemetry. (#19670)
This commit is contained in:
committed by
GitHub
parent
ce03156c9f
commit
788a40c445
@@ -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,
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +166,8 @@ function summarizeToolCalls(
|
||||
isEdit
|
||||
? ConversationInteractionInteraction.ACCEPT_FILE
|
||||
: ConversationInteractionInteraction.UNKNOWN,
|
||||
isEdit ? String(acceptedLines) : undefined,
|
||||
isEdit ? String(removedLines) : undefined,
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -295,6 +295,7 @@ export interface ConversationInteraction {
|
||||
status?: ActionStatus;
|
||||
interaction?: ConversationInteractionInteraction;
|
||||
acceptedLines?: string;
|
||||
removedLines?: string;
|
||||
language?: string;
|
||||
isAgentic?: boolean;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
} {
|
||||
|
||||
Reference in New Issue
Block a user