chrome-devtools-frontend 1.0.1675430 → 1.0.1676824
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WATCHLISTS +0 -4
- package/front_end/core/common/Settings.ts +0 -66
- package/front_end/core/root/Runtime.ts +0 -5
- package/front_end/core/sdk/CSSMetadata.ts +5 -9
- package/front_end/core/sdk/CSSPropertyParserMatchers.ts +8 -28
- package/front_end/core/sdk/DebuggerModel.ts +50 -30
- package/front_end/core/sdk/ResourceTreeModel.ts +20 -1
- package/front_end/core/sdk/Script.ts +9 -53
- package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +213 -23
- package/front_end/entrypoints/main/MainImpl.ts +31 -0
- package/front_end/generated/InspectorBackendCommands.ts +3 -1
- package/front_end/generated/SupportedCSSProperties.ts +21 -4
- package/front_end/generated/protocol-mapping.d.ts +14 -0
- package/front_end/generated/protocol-proxy-api.d.ts +10 -0
- package/front_end/generated/protocol.ts +35 -0
- package/front_end/models/ai_assistance/AiAgent2.ts +11 -0
- package/front_end/models/ai_assistance/AiConversation.ts +22 -5
- package/front_end/models/ai_assistance/README.md +52 -26
- package/front_end/models/ai_assistance/agents/AiAgent.ts +54 -8
- package/front_end/models/ai_assistance/agents/ContextSelectionAgent.ts +1 -1
- package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +7 -194
- package/front_end/models/ai_assistance/agents/StorageAgent.ts +8 -87
- package/front_end/models/ai_assistance/agents/StylingAgent.snapshot.txt +2 -1
- package/front_end/models/ai_assistance/ai_assistance.ts +16 -0
- package/front_end/models/ai_assistance/contexts/PerformanceTraceContext.ts +124 -0
- package/front_end/models/ai_assistance/contexts/StorageContext.ts +111 -0
- package/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.ts +69 -1
- package/front_end/models/ai_assistance/skills/README.md +63 -1
- package/front_end/models/ai_assistance/skills/Skill.ts +1 -1
- package/front_end/models/ai_assistance/skills/SkillRegistry.ts +4 -0
- package/front_end/models/ai_assistance/skills/performance.md +8 -0
- package/front_end/models/ai_assistance/skills/sources.md +16 -0
- package/front_end/models/ai_assistance/skills/storage.md +31 -0
- package/front_end/models/ai_assistance/tools/GetSourceContent.ts +101 -0
- package/front_end/models/ai_assistance/tools/GetTraceEventByKey.ts +83 -0
- package/front_end/models/ai_assistance/tools/GetTraceMainThreadSummary.ts +106 -0
- package/front_end/models/ai_assistance/tools/GetTraceNetworkSummary.ts +104 -0
- package/front_end/models/ai_assistance/tools/ListPageOrigins.ts +81 -0
- package/front_end/models/ai_assistance/tools/ListSources.ts +116 -0
- package/front_end/models/ai_assistance/tools/SelectTraceEventByKey.ts +90 -0
- package/front_end/models/ai_assistance/tools/Tool.ts +22 -1
- package/front_end/models/ai_assistance/tools/ToolRegistry.ts +14 -0
- package/front_end/models/bindings/CSSWorkspaceBinding.ts +4 -0
- package/front_end/models/bindings/CompilerScriptMapping.ts +4 -0
- package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +8 -0
- package/front_end/models/bindings/ResourceScriptMapping.ts +3 -201
- package/front_end/models/bindings/SASSSourceMapping.ts +6 -0
- package/front_end/models/breakpoints/BreakpointManager.ts +2 -49
- package/front_end/models/heap_snapshot/HeapSnapshotModel.ts +27 -0
- package/front_end/models/heap_snapshot/HeapSnapshotProxy.ts +10 -2
- package/front_end/models/issues_manager/descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
- package/front_end/models/issues_manager/descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
- package/front_end/models/issues_manager/descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
- package/front_end/models/javascript_metadata/NativeFunctions.js +1 -1
- package/front_end/models/persistence/IsolatedFileSystem.ts +7 -8
- package/front_end/models/persistence/IsolatedFileSystemManager.ts +2 -2
- package/front_end/models/persistence/PlatformFileSystem.ts +1 -1
- package/front_end/models/persistence/persistence-meta.ts +9 -9
- package/front_end/models/trace/types/TraceEvents.ts +36 -0
- package/front_end/panels/accessibility/ARIAAttributesView.ts +3 -3
- package/front_end/panels/accessibility/AccessibilityNodeView.ts +36 -36
- package/front_end/panels/accessibility/AccessibilityStrings.ts +168 -168
- package/front_end/panels/accessibility/SourceOrderView.ts +7 -7
- package/front_end/panels/accessibility/accessibility-meta.ts +2 -2
- package/front_end/panels/ai_assistance/AiAssistancePanel.ts +5 -5
- package/front_end/panels/ai_assistance/components/AIv2MarkdownRenderer.ts +2 -3
- package/front_end/panels/ai_assistance/components/ChatInput.ts +2 -2
- package/front_end/panels/ai_assistance/components/ChatMessage.ts +27 -2
- package/front_end/panels/application/IndexedDBViews.ts +65 -63
- package/front_end/panels/application/WebMCPView.ts +16 -7
- package/front_end/panels/common/AiCodeCompletionSummaryToolbar.ts +5 -5
- package/front_end/panels/common/BadgeNotification.ts +8 -8
- package/front_end/panels/common/ExtensionServer.ts +21 -1
- package/front_end/panels/common/GdpSignUpDialog.ts +16 -16
- package/front_end/panels/common/GeminiRebrandPromoDialog.ts +5 -6
- package/front_end/panels/common/PersistenceUtils.ts +2 -2
- package/front_end/panels/common/common.ts +0 -97
- package/front_end/panels/console/ConsoleInsightTeaser.ts +2 -2
- package/front_end/panels/console/ConsolePinPane.ts +2 -2
- package/front_end/panels/console/ConsoleView.ts +20 -19
- package/front_end/panels/elements/LayoutPane.ts +2 -8
- package/front_end/panels/event_listeners/EventListenersView.ts +8 -4
- package/front_end/panels/issues/AffectedTrackingSitesView.ts +25 -14
- package/front_end/panels/media/PlayerMessagesView.ts +149 -68
- package/front_end/panels/network/NetworkPanel.ts +1 -1
- package/front_end/panels/network/RequestPayloadView.ts +1 -0
- package/front_end/panels/profiler/HeapSnapshotView.ts +0 -2
- package/front_end/panels/profiler/heapProfiler.css +0 -9
- package/front_end/panels/recorder/RecorderPanel.ts +2 -3
- package/front_end/panels/screencast/ScreencastView.ts +148 -138
- package/front_end/panels/sources/AiCodeCompletionPlugin.ts +2 -2
- package/front_end/panels/sources/DebuggerPlugin.ts +9 -58
- package/front_end/panels/sources/ScopeChainSidebarPane.ts +1 -1
- package/front_end/panels/sources/UISourceCodeFrame.ts +3 -8
- package/front_end/panels/sources/WatchExpressionsSidebarPane.ts +4 -2
- package/front_end/panels/timeline/TimelineController.ts +36 -64
- package/front_end/panels/timeline/TimelinePanel.ts +11 -8
- package/front_end/panels/timeline/TimelineUIUtils.ts +5 -2
- package/front_end/panels/timeline/overlays/components/EntryLabelOverlay.ts +2 -2
- package/front_end/panels/timeline/timelinePanel.css +0 -10
- package/front_end/panels/utils/utils.ts +7 -7
- package/front_end/services/tracing/PerformanceTracing.ts +5 -17
- package/front_end/third_party/chromium/README.chromium +1 -1
- package/front_end/third_party/codemirror.next/chunk/codemirror.js +1 -1
- package/front_end/third_party/codemirror.next/chunk/codemirror.js.map +1 -1
- package/front_end/third_party/codemirror.next/package.json +2 -2
- package/front_end/third_party/codemirror.next/rebuild.sh +4 -1
- package/front_end/ui/comments/CommentAnchorResolver.ts +436 -10
- package/front_end/ui/comments/CommentManager.ts +640 -0
- package/front_end/ui/comments/CommentsOverlayWidget.ts +121 -0
- package/front_end/ui/comments/comments.ts +4 -0
- package/front_end/ui/comments/commentsOverlay.css +49 -0
- package/front_end/{panels/common → ui/components/dialogs}/FreDialog.ts +6 -6
- package/front_end/ui/components/dialogs/TypeToAllowDialog.ts +96 -0
- package/front_end/ui/components/dialogs/dialogs.ts +4 -0
- package/front_end/ui/components/settings/SettingCheckbox.ts +3 -3
- package/front_end/{panels/common → ui/components/text_editor}/AiCodeCompletionDisclaimer.ts +13 -13
- package/front_end/ui/components/text_editor/AiCodeCompletionProvider.ts +7 -6
- package/front_end/{panels/common → ui/components/text_editor}/AiCodeCompletionTeaser.ts +43 -46
- package/front_end/ui/components/text_editor/AiCodeGenerationProvider.ts +22 -26
- package/front_end/{panels/common → ui/components/text_editor}/AiCodeGenerationTeaser.ts +10 -10
- package/front_end/{panels/common → ui/components/text_editor}/AiCodeGenerationUpgradeDialog.ts +5 -5
- package/front_end/ui/components/text_editor/text_editor.ts +4 -0
- package/front_end/ui/legacy/Toolbar.ts +1 -1
- package/front_end/ui/legacy/components/object_ui/CustomPreviewComponent.ts +11 -3
- package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +270 -162
- package/front_end/ui/legacy/components/object_ui/objectPropertiesSection.css +5 -0
- package/front_end/ui/legacy/components/quick_open/CommandMenu.ts +11 -16
- package/front_end/ui/legacy/components/settings_ui/SettingsUI.ts +5 -12
- package/front_end/ui/legacy/components/source_frame/JSONView.ts +8 -1
- package/front_end/ui/legacy/components/source_frame/SourceFrame.ts +2 -2
- package/front_end/ui/settings/SettingUIRegistration.ts +55 -6
- package/front_end/ui/visual_logging/KnownContextValues.ts +1 -0
- package/mcp/mcp.ts +6 -1
- package/package.json +1 -1
- package/front_end/Images/toolbarResizerVertical.png +0 -0
- package/front_end/emulated_devices/MotoG4-landscape.svg +0 -155
- package/front_end/emulated_devices/MotoG4-portrait.svg +0 -155
- package/front_end/emulated_devices/Nexus5X-landscape.svg +0 -19
- package/front_end/emulated_devices/Nexus5X-portrait.svg +0 -19
- package/front_end/emulated_devices/Nexus6P-landscape.svg +0 -50
- package/front_end/emulated_devices/Nexus6P-portrait.svg +0 -54
- package/front_end/emulated_devices/google-nest-hub-horizontal.png +0 -0
- package/front_end/emulated_devices/google-nest-hub-max-horizontal.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-default-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-default-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-keyboard-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-keyboard-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-navigation-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-horizontal-navigation-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-default-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-default-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-keyboard-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-keyboard-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-navigation-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5-vertical-navigation-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-default-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-default-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-keyboard-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-keyboard-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-navigation-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-horizontal-navigation-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-default-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-default-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-keyboard-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-keyboard-2x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-navigation-1x.png +0 -0
- package/front_end/emulated_devices/google-nexus-5x-vertical-navigation-2x.png +0 -0
- package/front_end/emulated_devices/iPad-landscape.svg +0 -73
- package/front_end/emulated_devices/iPad-portrait.svg +0 -76
- package/front_end/emulated_devices/iPhone5-landscape.svg +0 -99
- package/front_end/emulated_devices/iPhone5-portrait.svg +0 -83
- package/front_end/emulated_devices/iPhone6-landscape.svg +0 -111
- package/front_end/emulated_devices/iPhone6-portrait.svg +0 -116
- package/front_end/emulated_devices/iPhone6Plus-landscape.svg +0 -118
- package/front_end/emulated_devices/iPhone6Plus-portrait.svg +0 -116
- package/front_end/emulated_devices/optimized/MotoG4-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/MotoG4-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/Nexus5X-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/Nexus5X-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/Nexus6P-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/Nexus6P-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/README.md +0 -9
- package/front_end/emulated_devices/optimized/google-nest-hub-horizontal.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nest-hub-max-horizontal.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-default-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-default-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-keyboard-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-keyboard-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-navigation-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-horizontal-navigation-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-default-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-default-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-keyboard-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-keyboard-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-navigation-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5-vertical-navigation-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-default-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-default-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-keyboard-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-keyboard-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-navigation-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-horizontal-navigation-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-default-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-default-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-keyboard-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-keyboard-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-navigation-1x.avif +0 -0
- package/front_end/emulated_devices/optimized/google-nexus-5x-vertical-navigation-2x.avif +0 -0
- package/front_end/emulated_devices/optimized/iPad-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/iPad-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone5-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone5-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone6-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone6-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone6Plus-landscape.avif +0 -0
- package/front_end/emulated_devices/optimized/iPhone6Plus-portrait.avif +0 -0
- package/front_end/emulated_devices/optimized/optimized_images.gni +0 -53
- package/front_end/models/ai_assistance/agents/README.md +0 -136
- /package/front_end/{panels/common → ui/components/dialogs}/freDialog.css +0 -0
- /package/front_end/{panels/common/common.css → ui/components/dialogs/typeToAllowDialog.css} +0 -0
- /package/front_end/{panels/common → ui/components/text_editor}/aiCodeCompletionDisclaimer.css +0 -0
- /package/front_end/{panels/common → ui/components/text_editor}/aiCodeCompletionTeaser.css +0 -0
- /package/front_end/{panels/common → ui/components/text_editor}/aiCodeGenerationTeaser.css +0 -0
- /package/front_end/{panels/common → ui/components/text_editor}/aiCodeGenerationUpgradeDialog.css +0 -0
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
# AI in DevTools
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Architecture Overview
|
|
4
4
|
|
|
5
|
-
When the user interacts with AI via the AI Assistance Panel, they are having a _conversation_ with an agent.
|
|
5
|
+
When the user interacts with AI via the AI Assistance Panel, they are having a _conversation_ with an agent. DevTools currently contains two architectural generations for AI assistance:
|
|
6
|
+
|
|
7
|
+
- **Legacy V1 (Multi-Agent Architecture)**: Implemented in `agents/`. Each domain is handled by a specialized agent subclass extending `AiAgent` (for example, `PerformanceAgent`, `StylingAgent`, `NetworkAgent`).
|
|
8
|
+
- **AIAgentV2 (Unified Single-Agent Architecture)**: Implemented in `AiAgent2.ts`. We are migrating from the siloed multi-agent architecture to a unified, skill-based single-agent architecture. In V2, a single agent (`AiAgent2`) handles multiple domains by dynamically loading **Skills** (`skills/`) and calling type-safe **Tools** (`tools/`).
|
|
9
|
+
|
|
10
|
+
Both architectures share the core **Contexts**, **Formatters**, and **Security & Origin Isolation** mechanisms described below.
|
|
11
|
+
|
|
12
|
+
## Core Concepts & Lifecycle
|
|
6
13
|
|
|
7
14
|
### Contexts
|
|
8
15
|
|
|
@@ -24,21 +31,47 @@ Encapsulating prompt formatting and UI generation within the context classes sim
|
|
|
24
31
|
|
|
25
32
|
To deal with the work to take an object that is the AI agent's context and turn it into a text representation that can be sent to the AI, we use _formatters_. These are typically classes with `static` methods that can take in objects and return their text representation that we want to pass to the AI.
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
### Lifecycle & Cache Clearing
|
|
35
|
+
|
|
36
|
+
AI Agents can maintain internal stateful variables to optimize performance or store context (such as stashed tool results, formatters, or instruction flags). However, this state must be carefully managed to prevent security leaks (such as cross-origin data leaks after page navigation) or stale results.
|
|
37
|
+
|
|
38
|
+
The `AiAgent` base class defines a `clearCache()` method. This method is automatically invoked by the system when:
|
|
39
|
+
- An execution error occurs.
|
|
40
|
+
- The user aborts the execution.
|
|
41
|
+
- A cross-origin navigation is detected (via the top-level origin blocking mechanism).
|
|
42
|
+
|
|
43
|
+
If you introduce new stateful member variables in an `AiAgent` subclass, you **must** override `clearCache()` to reset them:
|
|
44
|
+
1. Always call `super.clearCache()` to ensure base class cleanup is executed.
|
|
45
|
+
2. Reset any subclass-specific state (such as setting formatters to `null`, clearing lists, or resetting boolean flags).
|
|
46
|
+
|
|
47
|
+
Example from `PerformanceAgent`:
|
|
48
|
+
```typescript
|
|
49
|
+
override clearCache(): void {
|
|
50
|
+
super.clearCache();
|
|
51
|
+
this.#functionCallCacheForFocus.clear();
|
|
52
|
+
this.#formatter = null;
|
|
53
|
+
this.#traceFacts = [];
|
|
54
|
+
// ... reset other stateful fields
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Security & Origin Isolation
|
|
28
59
|
|
|
29
|
-
|
|
60
|
+
To prevent prompt injection attacks and cross-origin data leaks, the AI Assistance panel enforces strict origin-lock boundaries:
|
|
61
|
+
|
|
62
|
+
- **Origin Locking**: Once a conversation session begins, it locks to the origin of the initial data context (e.g. `https://google.com` or a specific file path).
|
|
63
|
+
- **Opaque Origins**: Any origin classified as opaque (e.g. `data:`, `about:`, `detached` nodes, unparsed `undefined://` or empty origins) is blocked from starting AI assistance (`isOpaqueOrigin()`).
|
|
64
|
+
- **File Isolation**: Local files (`file://`) do not share a single wildcard origin. Instead, the path is appended (e.g. `file:///path/to/file.js`) to treat each local file as its own unique origin. Swapping local files in the same conversation is blocked.
|
|
65
|
+
- **Trace Isolation**: Imported performance trace recordings are isolated using the virtual origin `imported-trace://${domain}`. This ensures that loaded local trace files do not share origins with live pages, preventing potential cross-origin prompt injection attacks when switching contexts.
|
|
66
|
+
- **Equivalence**: `areOriginsEquivalent()` ensures opaque origins are never equivalent to anything (including themselves), forcing a conversation reset on transitions.
|
|
30
67
|
|
|
31
|
-
|
|
32
|
-
- A single agent (`AIAgent2`) handles multiple domains.
|
|
33
|
-
- Capabilities are defined as **Skills** in Markdown files.
|
|
34
|
-
- The agent can dynamically load skills as needed via a `learnSkill` tool.
|
|
68
|
+
## AIAgentV2 (Unified Architecture)
|
|
35
69
|
|
|
36
|
-
|
|
70
|
+
We are migrating DevTools AI Assistance from a siloed multi-agent architecture to a unified, skill-based single-agent architecture (`AiAgent2`). In this new architecture, capabilities are defined as **Skills** in Markdown files, and the agent can dynamically load skills as needed via a `learnSkills` tool.
|
|
37
71
|
|
|
38
72
|
### Skills Build System
|
|
39
73
|
|
|
40
|
-
To support dynamic loading of skills, we generate JavaScript files from Markdown files containing skill definitions.
|
|
41
|
-
We use a nested `BUILD.gn` file in the `skills/` subdirectory specifically for this purpose. This ensures that GN's `target_gen_dir` points to `gen/front_end/models/ai_assistance/skills/`, placing the generated `.skill.js` files in the same relative structure as their source `.md` files. This allows TypeScript files in the `skills/` directory (like `map.ts`) to import the generated files using relative paths (e.g., `./styling.skill.js`) seamlessly. See the [Skills README](skills/README.md) for full details.
|
|
74
|
+
To support dynamic loading of skills, we generate JavaScript files from Markdown files containing skill definitions. We use a nested `BUILD.gn` file in the `skills/` subdirectory specifically for this purpose. This ensures that GN's `target_gen_dir` points to `gen/front_end/models/ai_assistance/skills/`, placing the generated `.skill.js` files in the same relative structure as their source `.md` files. This allows TypeScript files in the `skills/` directory (like `map.ts`) to import the generated files using relative paths (e.g., `./styling.skill.js`) seamlessly. See the [Skills README](skills/README.md) for full details.
|
|
42
75
|
|
|
43
76
|
### Tools and ToolRegistry
|
|
44
77
|
|
|
@@ -49,9 +82,13 @@ To support skills requiring execution of code or fetching page state (like compu
|
|
|
49
82
|
- **Capability Contexts**: Instead of passing a monolithic grab-bag context to all tools, dependencies are broken into narrow capability interfaces (e.g. `PageExecutionCapability`, `StyleMutationCapability`, `TargetCapability`, `OriginLockCapability`). Tools declare their required dependencies by intersecting these interfaces on their generic `ContextType` definition. The caller/Agent fulfills the complete capability context (`AllToolsCapabilities`), guaranteeing 100% compile-time type safety for dependencies without runtime checks.
|
|
50
83
|
- **ToolRegistry**: A static registry (`ToolRegistry`) storing instantiated tools. It uses TypeScript function overloading and generic lookups (`static get<K extends keyof typeof TOOLS>(name: K): typeof TOOLS[K]`) to return the precise class type of each tool, preventing type-erasure and escape-hatches (such as `any` or `as unknown` type assertions) at integration points like `AiAgent2.ts`. See the [Tools README](tools/README.md) for authoring instructions.
|
|
51
84
|
|
|
52
|
-
|
|
85
|
+
### Adding a new skill
|
|
86
|
+
|
|
87
|
+
See the [Skills README](skills/README.md) for detailed instructions.
|
|
53
88
|
|
|
54
|
-
|
|
89
|
+
## Extending Domain Support (Performance Insights)
|
|
90
|
+
|
|
91
|
+
### PerformanceTraceContext
|
|
55
92
|
|
|
56
93
|
The context for `PerformanceAgent` is `PerformanceTraceContext`, which wraps `AgentFocus`. `AgentFocus` supports different behavior for different entry-points of the "Ask AI" feature for a trace (such as a specific performance insight, flame chart call tree, trace event, or the whole parsed trace). `PerformanceTraceContext` implements `ConversationContext<AgentFocus>` to fetch prompt details, user-facing accordion details, and context-specific AI suggestions.
|
|
57
94
|
|
|
@@ -73,16 +110,15 @@ In general, the trace bounds are defined by the insight's overlays. If there are
|
|
|
73
110
|
|
|
74
111
|
See the `insightBounds` function in `InsightAIContext.ts`.
|
|
75
112
|
|
|
76
|
-
|
|
77
113
|
### Testing the new Insight
|
|
78
114
|
|
|
79
115
|
Once it's working, it's a good idea to manually experiment with the new Insight and ask a bunch of questions on different traces. Try to find (or create) websites that cause the insight to identify a variety of outputs and see how far you can push the AI. Look for instances where you can perhaps clarify the data you are passing into it, or tweak your wording, to try to make it clearer. You can also take the data you are sending and paste it into Gemini to get feedback on your prompt from the AI.
|
|
80
116
|
|
|
81
117
|
(We are working on a better, more automated way, of evaluating these responses).
|
|
82
118
|
|
|
83
|
-
## Debugging
|
|
119
|
+
## Debugging & Local Development
|
|
84
120
|
|
|
85
|
-
To test the AI code, you must be running DevTools in a branded Chrome (e.g. official Chrome Canary) and be signed in. You can use the `npm start` with a canary flag in this repository to run against Chromium, or by running Chrome Canary and pointing it to your local DevTools
|
|
121
|
+
To test the AI code, you must be running DevTools in a branded Chrome (e.g. official Chrome Canary) and be signed in. You can use the `npm start` with a canary flag in this repository to run against Chromium, or by running Chrome Canary and pointing it to your local DevTools:
|
|
86
122
|
|
|
87
123
|
```
|
|
88
124
|
npm start -- --browser=canary
|
|
@@ -108,13 +144,3 @@ Now, when interacting with the AI and sending requests, you will see output logg
|
|
|
108
144
|
### Testing the Accessibility Skill
|
|
109
145
|
|
|
110
146
|
The accessibility skill (`accessibility.md`) relies on an active Lighthouse report. Before interacting with the agent using this skill, ensure you have run a Lighthouse audit on the page you are inspecting so that the `getLighthouseAudits` tool can retrieve the report data.
|
|
111
|
-
|
|
112
|
-
## Security & Origin Isolation
|
|
113
|
-
|
|
114
|
-
To prevent prompt injection attacks and cross-origin data leaks, the AI Assistance panel enforces strict origin-lock boundaries:
|
|
115
|
-
|
|
116
|
-
* **Origin Locking**: Once a conversation session begins, it locks to the origin of the initial data context (e.g. `https://google.com` or a specific file path).
|
|
117
|
-
* **Opaque Origins**: Any origin classified as opaque (e.g. `data:`, `about:`, `detached` nodes, unparsed `undefined://` or empty origins) is blocked from starting AI assistance (`isOpaqueOrigin()`).
|
|
118
|
-
* **File Isolation**: Local files (`file://`) do not share a single wildcard origin. Instead, the path is appended (e.g. `file:///path/to/file.js`) to treat each local file as its own unique origin. Swapping local files in the same conversation is blocked.
|
|
119
|
-
* **Trace Isolation**: Imported performance trace recordings are isolated using the virtual origin `imported-trace://${domain}`. This ensures that loaded local trace files do not share origins with live pages, preventing potential cross-origin prompt injection attacks when switching contexts.
|
|
120
|
-
* **Equivalence**: `areOriginsEquivalent()` ensures opaque origins are never equivalent to anything (including themselves), forcing a conversation reset on transitions.
|
|
@@ -122,6 +122,10 @@ export interface ActionResponse {
|
|
|
122
122
|
output?: string;
|
|
123
123
|
canceled: boolean;
|
|
124
124
|
widgets?: AiWidget[];
|
|
125
|
+
/**
|
|
126
|
+
* The name of the executed tool. Only populated for AI v2.
|
|
127
|
+
*/
|
|
128
|
+
toolName?: string;
|
|
125
129
|
}
|
|
126
130
|
|
|
127
131
|
export interface QueryingResponse {
|
|
@@ -161,7 +165,7 @@ export type AllowedOriginResult = {
|
|
|
161
165
|
|
|
162
166
|
export interface AgentOptions {
|
|
163
167
|
aidaClient: Host.AidaClient.AidaClient;
|
|
164
|
-
|
|
168
|
+
serverSideLoggingAllowed?: boolean;
|
|
165
169
|
sessionId?: string;
|
|
166
170
|
confirmSideEffectForTest?: typeof Promise.withResolvers;
|
|
167
171
|
onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
|
|
@@ -193,6 +197,14 @@ export abstract class ConversationContext<T> {
|
|
|
193
197
|
abstract getItem(): T;
|
|
194
198
|
abstract getTitle(): string;
|
|
195
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Returns true if the server-side logging is enabled when this context is active.
|
|
202
|
+
* Currently only used for AI v2.
|
|
203
|
+
*/
|
|
204
|
+
isLoggingEnabled(): boolean {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
|
|
196
208
|
getOrigin(): string {
|
|
197
209
|
return extractContextOrigin(this.getURL());
|
|
198
210
|
}
|
|
@@ -387,10 +399,22 @@ export interface SourceCodeAiWidget {
|
|
|
387
399
|
};
|
|
388
400
|
}
|
|
389
401
|
|
|
402
|
+
export interface StorageBreakdownAiWidget {
|
|
403
|
+
name: 'STORAGE_BREAKDOWN';
|
|
404
|
+
data: {
|
|
405
|
+
totalUsageBytes: number,
|
|
406
|
+
totalQuotaBytes: number,
|
|
407
|
+
usageBreakdown: Array<{
|
|
408
|
+
storageType: string,
|
|
409
|
+
bytes: number,
|
|
410
|
+
}>,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
390
414
|
export type AiWidget = ComputedStyleAiWidget|CoreVitalsAiWidget|StylePropertiesAiWidget|DomTreeAiWidget|
|
|
391
415
|
PerformanceTraceAiWidget|PerfInsightAiWidget|TimelineRangeSummaryAiWidget|BottomUpTreeAiWidget|SourceFileAiWidget|
|
|
392
416
|
LighthouseReportAiWidget|TimelineEventSummaryAiWidget|NetworkRequestGeneralHeadersAiWidget|SourceCodeAiWidget|
|
|
393
|
-
SourceFilesListAiWidget|NetworkRequestsListAiWidget|NetworkTrackAiWidget;
|
|
417
|
+
SourceFilesListAiWidget|NetworkRequestsListAiWidget|NetworkTrackAiWidget|StorageBreakdownAiWidget;
|
|
394
418
|
|
|
395
419
|
/**
|
|
396
420
|
* @deprecated Used for v1 agents. Once v2 is shipped, this can be removed.
|
|
@@ -472,7 +496,16 @@ export abstract class AiAgent<T> {
|
|
|
472
496
|
|
|
473
497
|
readonly #sessionId: string;
|
|
474
498
|
readonly #aidaClient: Host.AidaClient.AidaClient;
|
|
475
|
-
|
|
499
|
+
/**
|
|
500
|
+
* Whether server-side logging is permitted by the system policy (based on
|
|
501
|
+
* user preferences, feature flags, or branding configurations).
|
|
502
|
+
*/
|
|
503
|
+
readonly #serverSideLoggingAllowed: boolean;
|
|
504
|
+
/**
|
|
505
|
+
* Tracks the dynamic runtime state of logging. Even if logging is allowed
|
|
506
|
+
* by policy, tools can temporarily deactivate this to avoid logging sensitive data.
|
|
507
|
+
*/
|
|
508
|
+
#serverSideLoggingActive: boolean;
|
|
476
509
|
readonly confirmSideEffect: typeof Promise.withResolvers;
|
|
477
510
|
readonly #functionDeclarations = new Map<string, FunctionDeclaration<Record<string, unknown>, unknown>>();
|
|
478
511
|
readonly #allowedOrigin?: () => AllowedOriginResult;
|
|
@@ -499,13 +532,15 @@ export abstract class AiAgent<T> {
|
|
|
499
532
|
|
|
500
533
|
constructor(opts: AgentOptions) {
|
|
501
534
|
this.#aidaClient = opts.aidaClient;
|
|
502
|
-
|
|
535
|
+
let serverSideLoggingAllowed = opts.serverSideLoggingAllowed ?? false;
|
|
503
536
|
// Disable logging for now.
|
|
504
537
|
// For context, see b/454563259#comment35.
|
|
505
538
|
// We should be able to remove this ~end of April.
|
|
506
539
|
if (Root.Runtime.hostConfig.devToolsGeminiRebranding?.enabled) {
|
|
507
|
-
|
|
540
|
+
serverSideLoggingAllowed = false;
|
|
508
541
|
}
|
|
542
|
+
this.#serverSideLoggingAllowed = serverSideLoggingAllowed;
|
|
543
|
+
this.#serverSideLoggingActive = serverSideLoggingAllowed;
|
|
509
544
|
this.#sessionId = opts.sessionId ?? crypto.randomUUID();
|
|
510
545
|
this.confirmSideEffect = opts.confirmSideEffectForTest ?? (() => Promise.withResolvers());
|
|
511
546
|
this.#history = opts.history ?? [];
|
|
@@ -558,8 +593,17 @@ export abstract class AiAgent<T> {
|
|
|
558
593
|
clearCache(): void {
|
|
559
594
|
}
|
|
560
595
|
|
|
561
|
-
|
|
562
|
-
|
|
596
|
+
/**
|
|
597
|
+
* Toggles whether server-side logging is active.
|
|
598
|
+
* Note that logging can only be activated if it was allowed by policy/configuration
|
|
599
|
+
* at startup (i.e., `#serverSideLoggingAllowed` is true).
|
|
600
|
+
*/
|
|
601
|
+
protected setServerSideLoggingActive(active: boolean): void {
|
|
602
|
+
if (active && this.#serverSideLoggingAllowed) {
|
|
603
|
+
this.#serverSideLoggingActive = true;
|
|
604
|
+
} else {
|
|
605
|
+
this.#serverSideLoggingActive = false;
|
|
606
|
+
}
|
|
563
607
|
}
|
|
564
608
|
|
|
565
609
|
popPendingMultimodalInput(): MultimodalInput|undefined {
|
|
@@ -618,7 +662,7 @@ export abstract class AiAgent<T> {
|
|
|
618
662
|
model_id: this.options.modelId || undefined,
|
|
619
663
|
},
|
|
620
664
|
metadata: {
|
|
621
|
-
disable_user_content_logging: !(this.#
|
|
665
|
+
disable_user_content_logging: !(this.#serverSideLoggingActive ?? false),
|
|
622
666
|
string_session_id: this.#sessionId,
|
|
623
667
|
user_tier: userTier,
|
|
624
668
|
client_version:
|
|
@@ -1027,6 +1071,7 @@ export abstract class AiAgent<T> {
|
|
|
1027
1071
|
output: typeof result.result === 'string' ? result.result : JSON.stringify(result.result),
|
|
1028
1072
|
widgets: result.widgets,
|
|
1029
1073
|
canceled: false,
|
|
1074
|
+
toolName: name,
|
|
1030
1075
|
};
|
|
1031
1076
|
}
|
|
1032
1077
|
|
|
@@ -1036,6 +1081,7 @@ export abstract class AiAgent<T> {
|
|
|
1036
1081
|
code,
|
|
1037
1082
|
output: result.error,
|
|
1038
1083
|
canceled: false,
|
|
1084
|
+
toolName: name,
|
|
1039
1085
|
};
|
|
1040
1086
|
}
|
|
1041
1087
|
|
|
@@ -19,6 +19,7 @@ import {DOMNodeContext} from '../contexts/DOMNodeContext.js';
|
|
|
19
19
|
import {FileContext} from '../contexts/FileContext.js';
|
|
20
20
|
import {PerformanceTraceContext} from '../contexts/PerformanceTraceContext.js';
|
|
21
21
|
import {getRequestContextOrigin, RequestContext} from '../contexts/RequestContext.js';
|
|
22
|
+
import {StorageContext} from '../contexts/StorageContext.js';
|
|
22
23
|
import {formatBytesToKb, seconds} from '../data_formatters/UnitFormatters.js';
|
|
23
24
|
import {debugLog} from '../debug.js';
|
|
24
25
|
import {StorageItem} from '../StorageItem.js';
|
|
@@ -30,7 +31,6 @@ import {
|
|
|
30
31
|
type ContextResponse,
|
|
31
32
|
type RequestOptions,
|
|
32
33
|
} from './AiAgent.js';
|
|
33
|
-
import {StorageContext} from './StorageAgent.js';
|
|
34
34
|
|
|
35
35
|
const lockedString = i18n.i18n.lockedString;
|
|
36
36
|
/**
|
|
@@ -14,12 +14,11 @@ import * as Tracing from '../../../services/tracing/tracing.js';
|
|
|
14
14
|
import * as Logs from '../../logs/logs.js';
|
|
15
15
|
import * as Trace from '../../trace/trace.js';
|
|
16
16
|
import {canResourceContentsBeReadForTrace} from '../AiOrigins.js';
|
|
17
|
-
import type {PerformanceTraceContext} from '../contexts/PerformanceTraceContext.js';
|
|
18
|
-
import {sanitizeHeaders} from '../data_formatters/NetworkRequestFormatter.js';
|
|
17
|
+
import type {MainThreadSectionLabel, PerformanceTraceContext} from '../contexts/PerformanceTraceContext.js';
|
|
19
18
|
import {
|
|
20
19
|
PerformanceInsightFormatter,
|
|
21
20
|
} from '../data_formatters/PerformanceInsightFormatter.js';
|
|
22
|
-
import {PerformanceTraceFormatter} from '../data_formatters/PerformanceTraceFormatter.js';
|
|
21
|
+
import {formatEventForAI, PerformanceTraceFormatter} from '../data_formatters/PerformanceTraceFormatter.js';
|
|
23
22
|
import {debugLog} from '../debug.js';
|
|
24
23
|
import {AICallTree} from '../performance/AICallTree.js';
|
|
25
24
|
import type {AgentFocus} from '../performance/AIContext.js';
|
|
@@ -49,13 +48,6 @@ const UIStringsNotTranslated = {
|
|
|
49
48
|
} as const;
|
|
50
49
|
const lockedString = i18n.i18n.lockedString;
|
|
51
50
|
|
|
52
|
-
/**
|
|
53
|
-
* Labels used to identify specific periods or categories in the trace for getting main thread summary.
|
|
54
|
-
* Supports hardcoded phases, dynamic navigation IDs (`NAVIGATION_X`), and insight models.
|
|
55
|
-
*/
|
|
56
|
-
export type MainThreadSectionLabel = 'nav-to-lcp'|'lcp-ttfb'|'lcp-render-delay'|'trace-bounds'|'NO_NAVIGATION'|
|
|
57
|
-
`NAVIGATION_${string}`|keyof Trace.Insights.Types.InsightModels;
|
|
58
|
-
|
|
59
51
|
/**
|
|
60
52
|
* WARNING: preamble defined in code is only used when userTier is
|
|
61
53
|
* TESTERS. Otherwise, a server-side preamble is used (see
|
|
@@ -196,14 +188,6 @@ enum ScorePriority {
|
|
|
196
188
|
// 16k Tokens * ~4 char per token.
|
|
197
189
|
const MAX_FUNCTION_RESULT_BYTE_LENGTH = 16384 * 4;
|
|
198
190
|
|
|
199
|
-
const STATIC_LABEL_NAMES: Record<string, string> = {
|
|
200
|
-
'nav-to-lcp': 'navigation to LCP',
|
|
201
|
-
'lcp-ttfb': 'LCP to TTFB',
|
|
202
|
-
'lcp-render-delay': 'LCP render delay',
|
|
203
|
-
'trace-bounds': 'the entire trace',
|
|
204
|
-
NO_NAVIGATION: 'the period before the first navigation',
|
|
205
|
-
};
|
|
206
|
-
|
|
207
191
|
function getInsightModel(
|
|
208
192
|
model: Trace.Insights.Types.InsightModels,
|
|
209
193
|
key: string,
|
|
@@ -214,33 +198,6 @@ function getInsightModel(
|
|
|
214
198
|
return undefined;
|
|
215
199
|
}
|
|
216
200
|
|
|
217
|
-
/**
|
|
218
|
-
* Converts the label name we use in the code to a human readable one that is
|
|
219
|
-
* shown to the user.
|
|
220
|
-
*/
|
|
221
|
-
export function getLabelName(label: MainThreadSectionLabel, focus: AgentFocus): string {
|
|
222
|
-
if (Object.prototype.hasOwnProperty.call(STATIC_LABEL_NAMES, label)) {
|
|
223
|
-
return STATIC_LABEL_NAMES[label];
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const {parsedTrace} = focus;
|
|
227
|
-
const insightSetById = parsedTrace.insights?.get(label as Trace.Types.Events.NavigationId);
|
|
228
|
-
if (insightSetById) {
|
|
229
|
-
return `navigation to ${insightSetById.url.href}`;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Go through all the insights we have to find the first one that matches to find the title.
|
|
233
|
-
// TODO(b/505291090): make it easier to look up Insight titles from a key.
|
|
234
|
-
for (const insightSet of parsedTrace.insights?.values() ?? []) {
|
|
235
|
-
const model = getInsightModel(insightSet.model, label);
|
|
236
|
-
if (model) {
|
|
237
|
-
return `${model.title} insight`;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return label;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
201
|
export interface PerformanceAgentOptions extends AgentOptions {
|
|
245
202
|
tracker?: Tracing.FreshRecording.Tracker;
|
|
246
203
|
networkLog?: Logs.NetworkLog.NetworkLog;
|
|
@@ -816,9 +773,8 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
816
773
|
const insightSet = parsedTrace.insights?.get(params.insightSetId);
|
|
817
774
|
if (!insightSet) {
|
|
818
775
|
const valid = ([...parsedTrace.insights?.values() ?? []])
|
|
819
|
-
.map(
|
|
820
|
-
|
|
821
|
-
this.#formatter?.serializeBounds(insightSet.bounds)}`)
|
|
776
|
+
.map(insightSet => `id: ${insightSet.id}, url: ${insightSet.url}, bounds: ${
|
|
777
|
+
this.#formatter?.serializeBounds(insightSet.bounds)}`)
|
|
822
778
|
.join('; ');
|
|
823
779
|
return {error: `Invalid insight set id. Valid insight set ids are: ${valid}`};
|
|
824
780
|
}
|
|
@@ -939,20 +895,6 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
939
895
|
},
|
|
940
896
|
});
|
|
941
897
|
|
|
942
|
-
const createBounds =
|
|
943
|
-
(min?: Trace.Types.Timing.Micro, max?: Trace.Types.Timing.Micro): Trace.Types.Timing.TraceWindowMicro|null => {
|
|
944
|
-
const {min: bMin, max: bMax} = parsedTrace.data.Meta.traceBounds;
|
|
945
|
-
const clampedMin = Math.max(min ?? bMin, bMin);
|
|
946
|
-
const clampedMax = Math.min(max ?? bMax, bMax);
|
|
947
|
-
|
|
948
|
-
if (clampedMin > clampedMax) {
|
|
949
|
-
return null;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
return Trace.Helpers.Timing.traceWindowFromMicroSeconds(
|
|
953
|
-
clampedMin as Trace.Types.Timing.Micro, clampedMax as Trace.Types.Timing.Micro);
|
|
954
|
-
};
|
|
955
|
-
|
|
956
898
|
this.declareFunction<{label: MainThreadSectionLabel}, {summary: string}>('getMainThreadTrackSummaryByLabel', {
|
|
957
899
|
description:
|
|
958
900
|
'Returns a focused, detailed summary of the main thread for a predefined labeled period. Use this to get more relevant detail than the initial trace summary before diagnosing issues.',
|
|
@@ -971,7 +913,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
971
913
|
required: ['label'],
|
|
972
914
|
},
|
|
973
915
|
displayInfoFromArgs: args => {
|
|
974
|
-
const labelName = getLabelName(args.label
|
|
916
|
+
const labelName = context.getLabelName(args.label);
|
|
975
917
|
return {
|
|
976
918
|
title: lockedString(`${UIStringsNotTranslated.mainThreadActivity}: ${labelName}`),
|
|
977
919
|
action: `getMainThreadTrackSummaryByLabel('${args.label}')`,
|
|
@@ -980,7 +922,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
980
922
|
handler: async args => {
|
|
981
923
|
debugLog('Function call: getMainThreadTrackSummaryByLabel');
|
|
982
924
|
|
|
983
|
-
const bounds =
|
|
925
|
+
const bounds = context.getBoundsForLabel(args.label);
|
|
984
926
|
if (!bounds) {
|
|
985
927
|
return {error: `Invalid label: ${args.label}`};
|
|
986
928
|
}
|
|
@@ -1028,7 +970,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
1028
970
|
throw new Error('missing formatter');
|
|
1029
971
|
}
|
|
1030
972
|
|
|
1031
|
-
const bounds = createBounds(args.min, args.max);
|
|
973
|
+
const bounds = context.createBounds(args.min, args.max);
|
|
1032
974
|
if (!bounds) {
|
|
1033
975
|
return {error: 'invalid bounds'};
|
|
1034
976
|
}
|
|
@@ -1326,67 +1268,6 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
1326
1268
|
});
|
|
1327
1269
|
}
|
|
1328
1270
|
|
|
1329
|
-
#getBoundsForLabel(label: MainThreadSectionLabel, focus: AgentFocus): Trace.Types.Timing.TraceWindowMicro|null {
|
|
1330
|
-
const {parsedTrace} = focus;
|
|
1331
|
-
const insightSet = focus.primaryInsightSet;
|
|
1332
|
-
|
|
1333
|
-
if (label === 'nav-to-lcp') {
|
|
1334
|
-
if (insightSet) {
|
|
1335
|
-
const lcp = Trace.Insights.Common.getLCP(insightSet);
|
|
1336
|
-
if (lcp) {
|
|
1337
|
-
return Trace.Helpers.Timing.traceWindowFromMicroSeconds(
|
|
1338
|
-
insightSet.bounds.min, lcp.event.ts as Trace.Types.Timing.Micro);
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
return null;
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1344
|
-
if (label === 'lcp-ttfb') {
|
|
1345
|
-
if (insightSet) {
|
|
1346
|
-
const subparts = insightSet.model.LCPBreakdown?.subparts;
|
|
1347
|
-
if (subparts?.ttfb) {
|
|
1348
|
-
return subparts.ttfb;
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
return null;
|
|
1352
|
-
}
|
|
1353
|
-
|
|
1354
|
-
if (label === 'lcp-render-delay') {
|
|
1355
|
-
if (insightSet) {
|
|
1356
|
-
const subparts = insightSet.model.LCPBreakdown?.subparts;
|
|
1357
|
-
if (subparts?.renderDelay) {
|
|
1358
|
-
return subparts.renderDelay;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
return null;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
if (label === 'trace-bounds') {
|
|
1365
|
-
return parsedTrace.data.Meta.traceBounds;
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
const insightSetById = parsedTrace.insights?.get(label as Trace.Types.Events.NavigationId);
|
|
1369
|
-
if (insightSetById) {
|
|
1370
|
-
return insightSetById.bounds;
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1373
|
-
if (insightSet) {
|
|
1374
|
-
const model = getInsightModel(insightSet.model, label);
|
|
1375
|
-
if (model) {
|
|
1376
|
-
return Trace.Insights.Common.insightBounds(model, insightSet.bounds);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
for (const is of parsedTrace.insights?.values() ?? []) {
|
|
1381
|
-
const model = getInsightModel(is.model, label);
|
|
1382
|
-
if (model) {
|
|
1383
|
-
return Trace.Insights.Common.insightBounds(model, is.bounds);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
return null;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
1271
|
async #getNetworkRequestImageData(lcpRequest: Trace.Types.Events.SyntheticNetworkRequest):
|
|
1391
1272
|
Promise<TextUtils.ContentData.ContentData|undefined> {
|
|
1392
1273
|
const target = this.targetManager.primaryPageTarget();
|
|
@@ -1408,71 +1289,3 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
|
|
|
1408
1289
|
return undefined;
|
|
1409
1290
|
}
|
|
1410
1291
|
}
|
|
1411
|
-
|
|
1412
|
-
/**
|
|
1413
|
-
* Serializes a trace event to a JSON string for AI consumption,
|
|
1414
|
-
* ensuring sensitive data (like headers and raw script source code)
|
|
1415
|
-
* is sanitized or redacted.
|
|
1416
|
-
*/
|
|
1417
|
-
function formatEventForAI(event: Trace.Types.Events.Event): string {
|
|
1418
|
-
if (Trace.Types.Events.isSyntheticNetworkRequest(event)) {
|
|
1419
|
-
return JSON.stringify({
|
|
1420
|
-
...event,
|
|
1421
|
-
args: {
|
|
1422
|
-
...event.args,
|
|
1423
|
-
data: {
|
|
1424
|
-
...event.args.data,
|
|
1425
|
-
responseHeaders: event.args.data.responseHeaders ? sanitizeHeaders(event.args.data.responseHeaders) : null,
|
|
1426
|
-
},
|
|
1427
|
-
},
|
|
1428
|
-
});
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
if (Trace.Types.Events.isResourceReceiveResponse(event)) {
|
|
1432
|
-
return JSON.stringify({
|
|
1433
|
-
...event,
|
|
1434
|
-
args: {
|
|
1435
|
-
...event.args,
|
|
1436
|
-
data: {
|
|
1437
|
-
...event.args.data,
|
|
1438
|
-
headers: event.args.data.headers ? sanitizeHeaders(event.args.data.headers) : undefined,
|
|
1439
|
-
},
|
|
1440
|
-
},
|
|
1441
|
-
});
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
if (Trace.Types.Events.isRundownScriptSource(event)) {
|
|
1445
|
-
// Redact sensitive cross-origin script source text.
|
|
1446
|
-
const safeData: Omit<Trace.Types.Events.RundownScriptSource['args']['data'], 'sourceText'> = {
|
|
1447
|
-
isolate: event.args.data.isolate,
|
|
1448
|
-
scriptId: event.args.data.scriptId,
|
|
1449
|
-
length: event.args.data.length,
|
|
1450
|
-
};
|
|
1451
|
-
return JSON.stringify({
|
|
1452
|
-
...event,
|
|
1453
|
-
args: {
|
|
1454
|
-
...event.args,
|
|
1455
|
-
data: safeData,
|
|
1456
|
-
},
|
|
1457
|
-
});
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
if (Trace.Types.Events.isRundownScriptSourceLarge(event)) {
|
|
1461
|
-
// Redact sensitive cross-origin script source text.
|
|
1462
|
-
const safeData: Omit<Trace.Types.Events.RundownScriptSourceLarge['args']['data'], 'sourceText'> = {
|
|
1463
|
-
isolate: event.args.data.isolate,
|
|
1464
|
-
scriptId: event.args.data.scriptId,
|
|
1465
|
-
splitIndex: event.args.data.splitIndex,
|
|
1466
|
-
splitCount: event.args.data.splitCount,
|
|
1467
|
-
};
|
|
1468
|
-
return JSON.stringify({
|
|
1469
|
-
...event,
|
|
1470
|
-
args: {
|
|
1471
|
-
...event.args,
|
|
1472
|
-
data: safeData,
|
|
1473
|
-
},
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
return JSON.stringify(event);
|
|
1478
|
-
}
|