From 7581f0aec295ddd278fc9d39c711bc78a0d83b57 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 3 Nov 2025 11:02:56 -0800 Subject: [PATCH 1/3] feat: add insightSetId to performance_analyze_insight --- src/tools/performance.ts | 8 +++++++- src/trace-processing/parse.ts | 22 ++++++---------------- tests/tools/performance.test.ts | 3 +++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/tools/performance.ts b/src/tools/performance.ts index 420a62132..a8b24903c 100644 --- a/src/tools/performance.ts +++ b/src/tools/performance.ts @@ -121,12 +121,17 @@ export const stopTrace = defineTool({ export const analyzeInsight = defineTool({ name: 'performance_analyze_insight', description: - 'Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording.', + 'Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.', annotations: { category: ToolCategory.PERFORMANCE, readOnlyHint: true, }, schema: { + insightSetId: zod + .string() + .describe( + 'The id for the specific insight set. Only use the ids given in the "Available insight sets" list.', + ), insightName: zod .string() .describe( @@ -144,6 +149,7 @@ export const analyzeInsight = defineTool({ const insightOutput = getInsightOutput( lastRecording, + request.params.insightSetId, request.params.insightName as InsightName, ); if ('error' in insightOutput) { diff --git a/src/trace-processing/parse.ts b/src/trace-processing/parse.ts index 23e195764..cbd79462e 100644 --- a/src/trace-processing/parse.ts +++ b/src/trace-processing/parse.ts @@ -97,6 +97,7 @@ export type InsightOutput = {output: string} | {error: string}; export function getInsightOutput( result: TraceResult, + insightSetId: string, insightName: InsightName, ): InsightOutput { if (!result.insights) { @@ -105,27 +106,16 @@ export function getInsightOutput( }; } - // Currently, we do not support inspecting traces with multiple navigations. We either: - // 1. Find Insights from the first navigation (common case: user records a trace with a page reload to test load performance) - // 2. Fall back to finding Insights not associated with a navigation (common case: user tests an interaction without a page load). - const mainNavigationId = - result.parsedTrace.data.Meta.mainFrameNavigations.at(0)?.args.data - ?.navigationId; - - const insightsForNav = result.insights.get( - mainNavigationId ?? TraceEngine.Types.Events.NO_NAVIGATION, - ); - - if (!insightsForNav) { + const insightSet = result.insights.get(insightSetId); + if (!insightSet) { return { - error: 'No Performance Insights for this trace.', + error: + 'No Performance Insights for the given insight set id. Only use ids given in the "Available insight sets" list.', }; } const matchingInsight = - insightName in insightsForNav.model - ? insightsForNav.model[insightName] - : null; + insightName in insightSet.model ? insightSet.model[insightName] : null; if (!matchingInsight) { return { error: `No Insight with the name ${insightName} found. Double check the name you provided is accurate and try again.`, diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts index b8ac55338..0c3cb6584 100644 --- a/tests/tools/performance.test.ts +++ b/tests/tools/performance.test.ts @@ -158,6 +158,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'LCPBreakdown', }, }, @@ -178,6 +179,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'MadeUpInsightName', }, }, @@ -197,6 +199,7 @@ describe('performance', () => { await analyzeInsight.handler( { params: { + insightSetId: '8463DF94CD61B265B664E7F768183DE3', insightName: 'LCPBreakdown', }, }, From 5a61ea1d3dc6c730b3ba400ad082404c24957013 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 3 Nov 2025 11:14:05 -0800 Subject: [PATCH 2/3] docs --- docs/tool-reference.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index 72a41da7c..aa9c15987 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -215,11 +215,12 @@ ### `performance_analyze_insight` -**Description:** Provides more detailed information on a specific Performance Insight that was highlighted in the results of a trace recording. +**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording. **Parameters:** - **insightName** (string) **(required)**: The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown" +- **insightSetId** (string) **(required)**: The id for the specific insight set. Only use the ids given in the "Available insight sets" list. --- @@ -278,15 +279,16 @@ so returned values have to JSON-serializable. - **args** (array) _(optional)_: An optional list of arguments to pass to the function. - **function** (string) **(required)**: A JavaScript function declaration to be executed by the tool in the currently selected page. - Example without arguments: `() => { +Example without arguments: `() => { return document.title }` or `async () => { return await fetch("example.com") }`. - Example with arguments: `(el) => { +Example with arguments: `(el) => { return el.innerText; }` + --- ### `get_console_message` From 7da665af5d7c15cae3762e4209eccd10dfbb6d3b Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 3 Nov 2025 11:38:55 -0800 Subject: [PATCH 3/3] update --- docs/tool-reference.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/tool-reference.md b/docs/tool-reference.md index aa9c15987..0e126b8c3 100644 --- a/docs/tool-reference.md +++ b/docs/tool-reference.md @@ -279,16 +279,15 @@ so returned values have to JSON-serializable. - **args** (array) _(optional)_: An optional list of arguments to pass to the function. - **function** (string) **(required)**: A JavaScript function declaration to be executed by the tool in the currently selected page. -Example without arguments: `() => { + Example without arguments: `() => { return document.title }` or `async () => { return await fetch("example.com") }`. -Example with arguments: `(el) => { + Example with arguments: `(el) => { return el.innerText; }` - --- ### `get_console_message`