mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-14 23:31:13 -07:00
feat(plan): create metrics for usage of AskUser tool (#18820)
Co-authored-by: Jerop Kipruto <jerop@google.com>
This commit is contained in:
@@ -337,6 +337,14 @@ describe('AskUserTool', () => {
|
||||
expect(JSON.parse(result.llmContent as string)).toEqual({
|
||||
answers: { '0': 'Quick fix (Recommended)' },
|
||||
});
|
||||
expect(result.data).toEqual({
|
||||
ask_user: {
|
||||
question_types: [QuestionType.CHOICE],
|
||||
dismissed: false,
|
||||
empty_submission: false,
|
||||
answer_count: 1,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should display message when user submits without answering', async () => {
|
||||
@@ -368,6 +376,14 @@ describe('AskUserTool', () => {
|
||||
'User submitted without answering questions.',
|
||||
);
|
||||
expect(JSON.parse(result.llmContent as string)).toEqual({ answers: {} });
|
||||
expect(result.data).toEqual({
|
||||
ask_user: {
|
||||
question_types: [QuestionType.CHOICE],
|
||||
dismissed: false,
|
||||
empty_submission: true,
|
||||
answer_count: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle cancellation', async () => {
|
||||
@@ -405,6 +421,12 @@ describe('AskUserTool', () => {
|
||||
expect(result.llmContent).toBe(
|
||||
'User dismissed ask_user dialog without answering.',
|
||||
);
|
||||
expect(result.data).toEqual({
|
||||
ask_user: {
|
||||
question_types: [QuestionType.CHOICE],
|
||||
dismissed: true,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -192,16 +192,35 @@ export class AskUserInvocation extends BaseToolInvocation<
|
||||
}
|
||||
|
||||
async execute(_signal: AbortSignal): Promise<ToolResult> {
|
||||
const questionTypes = this.params.questions.map(
|
||||
(q) => q.type ?? QuestionType.CHOICE,
|
||||
);
|
||||
|
||||
if (this.confirmationOutcome === ToolConfirmationOutcome.Cancel) {
|
||||
return {
|
||||
llmContent: 'User dismissed ask_user dialog without answering.',
|
||||
returnDisplay: 'User dismissed dialog',
|
||||
data: {
|
||||
ask_user: {
|
||||
question_types: questionTypes,
|
||||
dismissed: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const answerEntries = Object.entries(this.userAnswers);
|
||||
const hasAnswers = answerEntries.length > 0;
|
||||
|
||||
const metrics: Record<string, unknown> = {
|
||||
ask_user: {
|
||||
question_types: questionTypes,
|
||||
dismissed: false,
|
||||
empty_submission: !hasAnswers,
|
||||
answer_count: answerEntries.length,
|
||||
},
|
||||
};
|
||||
|
||||
const returnDisplay = hasAnswers
|
||||
? `**User answered:**\n${answerEntries
|
||||
.map(([index, answer]) => {
|
||||
@@ -219,6 +238,7 @@ export class AskUserInvocation extends BaseToolInvocation<
|
||||
return {
|
||||
llmContent: JSON.stringify({ answers: this.userAnswers }),
|
||||
returnDisplay,
|
||||
data: metrics,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user