chrome-devtools-frontend 1.0.1376716 → 1.0.1380117

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.
Files changed (434) hide show
  1. package/config/gni/devtools_grd_files.gni +15 -7
  2. package/config/gni/devtools_image_files.gni +2 -0
  3. package/front_end/Images/src/animation.svg +3 -0
  4. package/front_end/Images/src/brush-2.svg +3 -0
  5. package/front_end/core/common/SettingRegistration.ts +1 -1
  6. package/front_end/core/host/AidaClient.ts +1 -0
  7. package/front_end/core/host/InspectorFrontendHost.ts +4 -0
  8. package/front_end/core/i18n/ByteUtilities.test.ts +34 -0
  9. package/front_end/core/i18n/ByteUtilities.ts +65 -0
  10. package/front_end/core/i18n/NumberFormatter.ts +75 -0
  11. package/front_end/core/i18n/i18n.ts +4 -0
  12. package/front_end/core/i18n/time-utilities.test.ts +20 -2
  13. package/front_end/core/i18n/time-utilities.ts +125 -86
  14. package/front_end/core/platform/NumberUtilities.test.ts +3 -26
  15. package/front_end/core/platform/NumberUtilities.ts +0 -20
  16. package/front_end/core/root/Runtime.ts +6 -3
  17. package/front_end/core/sdk/CPUThrottlingManager.ts +4 -0
  18. package/front_end/core/sdk/CSSContainerQuery.test.ts +10 -16
  19. package/front_end/core/sdk/CSSContainerQuery.ts +3 -15
  20. package/front_end/core/sdk/CSSMatchedStyles.test.ts +4 -0
  21. package/front_end/core/sdk/CSSMatchedStyles.ts +5 -5
  22. package/front_end/core/sdk/CSSModel.ts +18 -0
  23. package/front_end/core/sdk/CSSPropertyParser.test.ts +16 -1
  24. package/front_end/core/sdk/CSSPropertyParser.ts +2 -2
  25. package/front_end/core/sdk/sdk-meta.ts +8 -0
  26. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +3 -3
  27. package/front_end/generated/ARIAProperties.js +4 -0
  28. package/front_end/generated/InspectorBackendCommands.js +8 -6
  29. package/front_end/generated/SupportedCSSProperties.js +17 -4
  30. package/front_end/generated/protocol-mapping.d.ts +15 -1
  31. package/front_end/generated/protocol-proxy-api.d.ts +14 -1
  32. package/front_end/generated/protocol.ts +26 -2
  33. package/front_end/models/extensions/ExtensionAPI.ts +9 -1
  34. package/front_end/models/heap_snapshot_model/HeapSnapshotModel.ts +2 -0
  35. package/front_end/models/javascript_metadata/NativeFunctions.js +8 -21
  36. package/front_end/models/live-metrics/web-vitals-injected/{rollup.config.js → rollup.config.mjs} +1 -1
  37. package/front_end/models/persistence/EditFileSystemView.ts +19 -9
  38. package/front_end/models/persistence/WorkspaceSettingsTab.ts +50 -54
  39. package/front_end/models/persistence/editFileSystemView.css +35 -15
  40. package/front_end/models/persistence/workspaceSettingsTab.css +21 -87
  41. package/front_end/models/timeline_model/timeline_model.ts +0 -6
  42. package/front_end/models/trace/Processor.test.ts +18 -17
  43. package/front_end/models/trace/Processor.ts +10 -14
  44. package/front_end/models/trace/README.md +0 -1
  45. package/front_end/models/{timeline_model → trace/extras}/TimelineJSProfile.ts +19 -29
  46. package/front_end/models/{timeline_model/TimelineModelFilter.test.ts → trace/extras/TraceFilter.test.ts} +15 -17
  47. package/front_end/models/trace/extras/TraceFilter.ts +62 -0
  48. package/front_end/models/{timeline_model/TimelineProfileTree.test.ts → trace/extras/TraceTree.test.ts} +44 -43
  49. package/front_end/models/{timeline_model/TimelineProfileTree.ts → trace/extras/TraceTree.ts} +65 -59
  50. package/front_end/models/trace/extras/extras.ts +3 -0
  51. package/front_end/models/trace/handlers/AnimationHandler.ts +0 -8
  52. package/front_end/models/trace/handlers/ExtensionTraceDataHandler.ts +1 -11
  53. package/front_end/models/trace/handlers/FramesHandler.test.ts +1 -6
  54. package/front_end/models/trace/handlers/FramesHandler.ts +1 -14
  55. package/front_end/models/trace/handlers/GPUHandler.test.ts +0 -2
  56. package/front_end/models/trace/handlers/GPUHandler.ts +1 -25
  57. package/front_end/models/trace/handlers/ImagePaintingHandler.ts +3 -0
  58. package/front_end/models/trace/handlers/InitiatorsHandler.test.ts +0 -1
  59. package/front_end/models/trace/handlers/InitiatorsHandler.ts +0 -20
  60. package/front_end/models/trace/handlers/InvalidationsHandler.test.ts +0 -1
  61. package/front_end/models/trace/handlers/InvalidationsHandler.ts +0 -18
  62. package/front_end/models/trace/handlers/LargestImagePaintHandler.test.ts +2 -2
  63. package/front_end/models/trace/handlers/LargestImagePaintHandler.ts +63 -3
  64. package/front_end/models/trace/handlers/LargestTextPaintHandler.ts +3 -0
  65. package/front_end/models/trace/handlers/LayerTreeHandler.test.ts +0 -2
  66. package/front_end/models/trace/handlers/LayerTreeHandler.ts +1 -18
  67. package/front_end/models/trace/handlers/LayoutShiftsHandler.test.ts +0 -3
  68. package/front_end/models/trace/handlers/LayoutShiftsHandler.ts +1 -20
  69. package/front_end/models/trace/handlers/MemoryHandler.test.ts +0 -1
  70. package/front_end/models/trace/handlers/MemoryHandler.ts +3 -0
  71. package/front_end/models/trace/handlers/MetaHandler.test.ts +1 -32
  72. package/front_end/models/trace/handlers/MetaHandler.ts +2 -30
  73. package/front_end/models/trace/handlers/NetworkRequestsHandler.test.ts +0 -26
  74. package/front_end/models/trace/handlers/NetworkRequestsHandler.ts +4 -23
  75. package/front_end/models/trace/handlers/PageFramesHandler.ts +3 -0
  76. package/front_end/models/trace/handlers/RendererHandler.test.ts +0 -4
  77. package/front_end/models/trace/handlers/RendererHandler.ts +1 -24
  78. package/front_end/models/trace/handlers/SamplesHandler.test.ts +0 -5
  79. package/front_end/models/trace/handlers/SamplesHandler.ts +0 -26
  80. package/front_end/models/trace/handlers/ScreenshotsHandler.test.ts +0 -1
  81. package/front_end/models/trace/handlers/SelectorStatsHandler.ts +3 -0
  82. package/front_end/models/trace/handlers/ServerTimingsHandler.ts +1 -16
  83. package/front_end/models/trace/handlers/Threads.test.ts +1 -2
  84. package/front_end/models/trace/handlers/UserInteractionsHandler.test.ts +4 -27
  85. package/front_end/models/trace/handlers/UserInteractionsHandler.ts +16 -25
  86. package/front_end/models/trace/handlers/UserTimingsHandler.ts +0 -17
  87. package/front_end/models/trace/handlers/WorkersHandler.test.ts +0 -1
  88. package/front_end/models/trace/handlers/WorkersHandler.ts +0 -23
  89. package/front_end/models/trace/handlers/types.ts +1 -8
  90. package/front_end/models/trace/insights/{CumulativeLayoutShift.test.ts → CLSCulprits.test.ts} +21 -21
  91. package/front_end/models/trace/insights/{CumulativeLayoutShift.ts → CLSCulprits.ts} +24 -5
  92. package/front_end/models/trace/insights/Common.ts +5 -55
  93. package/front_end/models/trace/insights/DocumentLatency.test.ts +2 -2
  94. package/front_end/models/trace/insights/DocumentLatency.ts +26 -6
  95. package/front_end/models/trace/insights/FontDisplay.ts +24 -5
  96. package/front_end/models/trace/insights/InteractionToNextPaint.test.ts +1 -1
  97. package/front_end/models/trace/insights/InteractionToNextPaint.ts +26 -6
  98. package/front_end/models/trace/insights/LCPDiscovery.test.ts +58 -0
  99. package/front_end/models/trace/insights/LCPDiscovery.ts +101 -0
  100. package/front_end/models/trace/insights/{LargestContentfulPaint.test.ts → LCPPhases.test.ts} +6 -28
  101. package/front_end/models/trace/insights/{LargestContentfulPaint.ts → LCPPhases.ts} +37 -38
  102. package/front_end/models/trace/insights/{InsightRunners.ts → Models.ts} +4 -3
  103. package/front_end/models/trace/insights/RenderBlocking.test.ts +1 -1
  104. package/front_end/models/trace/insights/RenderBlocking.ts +33 -28
  105. package/front_end/models/trace/insights/SlowCSSSelector.ts +26 -5
  106. package/front_end/models/trace/insights/{ThirdPartyWeb.test.ts → ThirdParties.test.ts} +3 -3
  107. package/front_end/models/trace/insights/{ThirdPartyWeb.ts → ThirdParties.ts} +24 -5
  108. package/front_end/models/trace/insights/Viewport.test.ts +1 -1
  109. package/front_end/models/trace/insights/Viewport.ts +27 -9
  110. package/front_end/models/trace/insights/insights.ts +1 -1
  111. package/front_end/models/trace/insights/types.ts +11 -9
  112. package/front_end/models/trace/types/TraceEvents.ts +51 -22
  113. package/front_end/panels/application/SharedStorageItemsView.test.ts +3 -3
  114. package/front_end/panels/application/SharedStorageItemsView.ts +5 -3
  115. package/front_end/panels/application/StorageView.ts +3 -3
  116. package/front_end/panels/application/components/StorageMetadataView.ts +1 -2
  117. package/front_end/panels/browser_debugger/XHRBreakpointsSidebarPane.ts +34 -31
  118. package/front_end/panels/coverage/CoverageView.ts +3 -3
  119. package/front_end/panels/elements/ComputedStyleModel.ts +9 -2
  120. package/front_end/panels/elements/ComputedStyleWidget.test.ts +72 -0
  121. package/front_end/panels/elements/ComputedStyleWidget.ts +12 -0
  122. package/front_end/panels/elements/ElementStatePaneWidget.test.ts +84 -30
  123. package/front_end/panels/elements/ElementStatePaneWidget.ts +42 -24
  124. package/front_end/panels/elements/ElementsTreeElement.ts +24 -11
  125. package/front_end/panels/elements/MetricsSidebarPane.ts +12 -7
  126. package/front_end/panels/elements/PropertyMatchers.ts +3 -0
  127. package/front_end/panels/elements/StylePropertiesSection.ts +15 -6
  128. package/front_end/panels/elements/StylePropertyTreeElement.test.ts +3 -1
  129. package/front_end/panels/elements/StylePropertyTreeElement.ts +8 -3
  130. package/front_end/panels/elements/stylePropertiesTreeOutline.css +2 -2
  131. package/front_end/panels/explain/components/ConsoleInsight.ts +8 -18
  132. package/front_end/panels/freestyler/AiAgent.test.ts +58 -1
  133. package/front_end/panels/freestyler/AiAgent.ts +58 -3
  134. package/front_end/panels/freestyler/DrJonesFileAgent.test.ts +99 -23
  135. package/front_end/panels/freestyler/DrJonesFileAgent.ts +53 -20
  136. package/front_end/panels/freestyler/DrJonesNetworkAgent.test.ts +15 -7
  137. package/front_end/panels/freestyler/DrJonesNetworkAgent.ts +36 -15
  138. package/front_end/panels/freestyler/DrJonesPerformanceAgent.test.ts +6 -6
  139. package/front_end/panels/freestyler/DrJonesPerformanceAgent.ts +48 -8
  140. package/front_end/panels/freestyler/FreestylerAgent.test.ts +15 -14
  141. package/front_end/panels/freestyler/FreestylerAgent.ts +52 -8
  142. package/front_end/panels/freestyler/FreestylerPanel.test.ts +539 -39
  143. package/front_end/panels/freestyler/FreestylerPanel.ts +349 -215
  144. package/front_end/panels/freestyler/components/FreestylerChatUi.test.ts +126 -34
  145. package/front_end/panels/freestyler/components/FreestylerChatUi.ts +320 -268
  146. package/front_end/panels/freestyler/components/UserActionRow.ts +156 -47
  147. package/front_end/panels/freestyler/components/freestylerChatUi.css +69 -34
  148. package/front_end/panels/freestyler/components/userActionRow.css +40 -67
  149. package/front_end/panels/freestyler/freestyler-meta.ts +3 -11
  150. package/front_end/panels/issues/components/HideIssuesMenu.ts +2 -11
  151. package/front_end/panels/layer_viewer/LayerDetailsView.ts +1 -2
  152. package/front_end/panels/layer_viewer/PaintProfilerView.ts +5 -5
  153. package/front_end/panels/lighthouse/LighthouseReportRenderer.ts +46 -0
  154. package/front_end/panels/mobile_throttling/ThrottlingSettingsTab.ts +26 -17
  155. package/front_end/panels/mobile_throttling/throttlingSettingsTab.css +25 -19
  156. package/front_end/panels/network/BinaryResourceView.ts +6 -7
  157. package/front_end/panels/network/EventSourceMessagesView.ts +1 -1
  158. package/front_end/panels/network/NetworkDataGridNode.ts +3 -3
  159. package/front_end/panels/network/NetworkLogView.ts +7 -8
  160. package/front_end/panels/network/RequestTimingView.test.ts +35 -1
  161. package/front_end/panels/network/RequestTimingView.ts +96 -0
  162. package/front_end/panels/network/ResourceWebSocketFrameView.ts +2 -2
  163. package/front_end/panels/network/networkTimingTable.css +2 -1
  164. package/front_end/panels/performance_monitor/PerformanceMonitor.ts +1 -1
  165. package/front_end/panels/profiler/HeapProfileView.ts +3 -3
  166. package/front_end/panels/profiler/HeapSnapshotView.ts +2 -2
  167. package/front_end/panels/profiler/HeapTimelineOverview.ts +12 -12
  168. package/front_end/panels/profiler/IsolateSelector.ts +3 -4
  169. package/front_end/panels/profiler/ProfileFlameChartDataProvider.ts +1 -1
  170. package/front_end/panels/profiler/ProfileSidebarTreeElement.ts +7 -6
  171. package/front_end/panels/profiler/ProfileView.ts +1 -1
  172. package/front_end/panels/recorder/components/RecordingView.ts +2 -2
  173. package/front_end/panels/recorder/injected/{rollup.config.js → rollup.config.mjs} +1 -1
  174. package/front_end/panels/recorder/recorderController.css +0 -4
  175. package/front_end/panels/security/CookieReportTreeElement.ts +1 -9
  176. package/front_end/panels/security/CookieReportView.ts +120 -0
  177. package/front_end/panels/security/SecurityPanel.ts +8 -2
  178. package/front_end/panels/security/cookieReportView.css +46 -0
  179. package/front_end/panels/security/sidebar.css +1 -2
  180. package/front_end/panels/sensors/LocationsSettingsTab.ts +26 -11
  181. package/front_end/panels/sensors/locationsSettingsTab.css +18 -18
  182. package/front_end/panels/settings/AISettingsTab.ts +6 -15
  183. package/front_end/panels/settings/KeybindsSettingsTab.ts +1 -1
  184. package/front_end/panels/settings/SettingsScreen.ts +61 -56
  185. package/front_end/panels/settings/aiSettingsTab.css +3 -14
  186. package/front_end/panels/settings/components/SyncSection.ts +1 -2
  187. package/front_end/panels/settings/components/syncSection.css +0 -10
  188. package/front_end/panels/settings/frameworkIgnoreListSettingsTab.css +3 -1
  189. package/front_end/panels/settings/keybindsSettingsTab.css +7 -10
  190. package/front_end/panels/settings/settingsScreen.css +27 -125
  191. package/front_end/panels/sources/DebuggerPlugin.ts +9 -4
  192. package/front_end/panels/sources/NavigatorView.ts +11 -13
  193. package/front_end/panels/timeline/ActiveFilters.ts +3 -4
  194. package/front_end/panels/timeline/AnimationsTrackAppender.ts +1 -2
  195. package/front_end/panels/timeline/CountersGraph.ts +2 -4
  196. package/front_end/panels/timeline/EventsTimelineTreeView.ts +7 -8
  197. package/front_end/panels/timeline/README.md +2 -1
  198. package/front_end/panels/timeline/TimelineController.ts +14 -4
  199. package/front_end/panels/timeline/TimelineEventOverview.ts +3 -4
  200. package/front_end/panels/timeline/TimelineFilters.ts +3 -4
  201. package/front_end/panels/timeline/TimelineFlameChartDataProvider.test.ts +1 -1
  202. package/front_end/panels/timeline/TimelineFlameChartDataProvider.ts +3 -10
  203. package/front_end/panels/timeline/TimelineFlameChartNetworkDataProvider.ts +1 -2
  204. package/front_end/panels/timeline/TimelineFlameChartView.ts +21 -12
  205. package/front_end/panels/timeline/TimelineLoader.test.ts +1 -2
  206. package/front_end/panels/timeline/TimelineLoader.ts +3 -4
  207. package/front_end/panels/timeline/TimelineMiniMap.ts +10 -0
  208. package/front_end/panels/timeline/TimelinePanel.ts +20 -8
  209. package/front_end/panels/timeline/TimelineTreeView.test.ts +12 -13
  210. package/front_end/panels/timeline/TimelineTreeView.ts +35 -40
  211. package/front_end/panels/timeline/TimelineUIUtils.test.ts +2 -2
  212. package/front_end/panels/timeline/TimelineUIUtils.ts +12 -14
  213. package/front_end/panels/timeline/components/LayoutShiftDetails.ts +6 -7
  214. package/front_end/panels/timeline/components/LiveMetricsView.test.ts +3 -3
  215. package/front_end/panels/timeline/components/LiveMetricsView.ts +14 -26
  216. package/front_end/panels/timeline/components/MetricCard.test.ts +1 -1
  217. package/front_end/panels/timeline/components/MetricCard.ts +46 -0
  218. package/front_end/panels/timeline/components/NetworkRequestDetails.ts +3 -4
  219. package/front_end/panels/timeline/components/SidebarSingleInsightSet.test.ts +2 -0
  220. package/front_end/panels/timeline/components/SidebarSingleInsightSet.ts +41 -36
  221. package/front_end/panels/timeline/components/insights/CLSCulprits.ts +19 -33
  222. package/front_end/panels/timeline/components/insights/DocumentLatency.ts +29 -40
  223. package/front_end/panels/timeline/components/insights/FontDisplay.ts +17 -23
  224. package/front_end/panels/timeline/components/insights/Helpers.ts +12 -16
  225. package/front_end/panels/timeline/components/insights/InteractionToNextPaint.ts +14 -26
  226. package/front_end/panels/timeline/components/insights/LCPDiscovery.ts +25 -37
  227. package/front_end/panels/timeline/components/insights/LCPPhases.ts +20 -47
  228. package/front_end/panels/timeline/components/insights/RenderBlocking.ts +19 -28
  229. package/front_end/panels/timeline/components/insights/SidebarInsight.ts +1 -2
  230. package/front_end/panels/timeline/components/insights/SlowCSSSelector.ts +18 -31
  231. package/front_end/panels/timeline/components/insights/Table.ts +5 -3
  232. package/front_end/panels/timeline/components/insights/ThirdParties.ts +18 -25
  233. package/front_end/panels/timeline/components/insights/Viewport.ts +14 -25
  234. package/front_end/panels/timeline/components/liveMetricsView.css +5 -13
  235. package/front_end/panels/timeline/components/metricCard.css +11 -0
  236. package/front_end/panels/timeline/components/sidebarInsightsTab.css +1 -1
  237. package/front_end/panels/timeline/overlays/OverlaysImpl.test.ts +5 -5
  238. package/front_end/panels/timeline/overlays/OverlaysImpl.ts +13 -12
  239. package/front_end/panels/timeline/timelineFlameChartView.css +1 -1
  240. package/front_end/panels/timeline/utils/AICallTree.test.ts +105 -0
  241. package/front_end/panels/timeline/utils/AICallTree.ts +25 -24
  242. package/front_end/testing/EnvironmentHelpers.ts +5 -18
  243. package/front_end/testing/InsightHelpers.ts +4 -4
  244. package/front_end/testing/TraceHelpers.ts +1 -1
  245. package/front_end/third_party/puppeteer/README.chromium +2 -2
  246. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Browser.d.ts +2 -3
  247. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Browser.d.ts.map +1 -1
  248. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Browser.js.map +1 -1
  249. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/ElementHandle.d.ts +14 -3
  250. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/ElementHandle.d.ts.map +1 -1
  251. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/ElementHandle.js +16 -2
  252. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/ElementHandle.js.map +1 -1
  253. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Input.d.ts +34 -5
  254. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Input.d.ts.map +1 -1
  255. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Input.js +51 -2
  256. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/api/Input.js.map +1 -1
  257. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/ElementHandle.d.ts.map +1 -1
  258. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/ElementHandle.js +10 -8
  259. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/ElementHandle.js.map +1 -1
  260. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Frame.d.ts.map +1 -1
  261. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Frame.js +1 -1
  262. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Frame.js.map +1 -1
  263. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Input.d.ts +14 -4
  264. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Input.d.ts.map +1 -1
  265. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Input.js +57 -23
  266. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/bidi/Input.js.map +1 -1
  267. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/ElementHandle.d.ts +1 -1
  268. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/ElementHandle.d.ts.map +1 -1
  269. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/ElementHandle.js +13 -10
  270. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/ElementHandle.js.map +1 -1
  271. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/Input.d.ts +15 -4
  272. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/Input.d.ts.map +1 -1
  273. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/Input.js +55 -26
  274. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/cdp/Input.js.map +1 -1
  275. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/CallbackRegistry.d.ts +0 -8
  276. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/CallbackRegistry.d.ts.map +1 -1
  277. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/CallbackRegistry.js +2 -11
  278. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/CallbackRegistry.js.map +1 -1
  279. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/ConsoleMessage.d.ts +2 -1
  280. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/ConsoleMessage.d.ts.map +1 -1
  281. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/ConsoleMessage.js +5 -2
  282. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/ConsoleMessage.js.map +1 -1
  283. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Errors.d.ts +7 -0
  284. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Errors.d.ts.map +1 -1
  285. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Errors.js +9 -1
  286. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/Errors.js.map +1 -1
  287. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/WaitTask.d.ts.map +1 -1
  288. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/WaitTask.js +5 -3
  289. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/common/WaitTask.js.map +1 -1
  290. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/environment.d.ts +1 -1
  291. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/environment.d.ts.map +1 -1
  292. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/environment.js +0 -3
  293. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/environment.js.map +1 -1
  294. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/generated/injected.d.ts +1 -1
  295. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/generated/injected.js +1 -1
  296. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/generated/version.d.ts +1 -1
  297. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/generated/version.js +1 -1
  298. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/injected/injected.d.ts +1 -1
  299. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/revisions.d.ts +3 -3
  300. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/revisions.js +3 -3
  301. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/revisions.js.map +1 -1
  302. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/util/Mutex.d.ts +2 -2
  303. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/util/incremental-id-generator.d.ts +14 -0
  304. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/util/incremental-id-generator.d.ts.map +1 -0
  305. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/util/incremental-id-generator.js +18 -0
  306. package/front_end/third_party/puppeteer/package/lib/cjs/puppeteer/util/incremental-id-generator.js.map +1 -0
  307. package/front_end/third_party/puppeteer/package/lib/es5-iife/puppeteer-core-browser.d.ts +51 -10
  308. package/front_end/third_party/puppeteer/package/lib/es5-iife/puppeteer-core-browser.js +215 -97
  309. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Browser.d.ts +2 -3
  310. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Browser.d.ts.map +1 -1
  311. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Browser.js.map +1 -1
  312. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/ElementHandle.d.ts +14 -3
  313. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/ElementHandle.d.ts.map +1 -1
  314. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/ElementHandle.js +16 -2
  315. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/ElementHandle.js.map +1 -1
  316. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Input.d.ts +34 -5
  317. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Input.d.ts.map +1 -1
  318. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Input.js +51 -2
  319. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/api/Input.js.map +1 -1
  320. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/ElementHandle.d.ts.map +1 -1
  321. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/ElementHandle.js +10 -8
  322. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/ElementHandle.js.map +1 -1
  323. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Frame.d.ts.map +1 -1
  324. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Frame.js +1 -1
  325. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Frame.js.map +1 -1
  326. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Input.d.ts +14 -4
  327. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Input.d.ts.map +1 -1
  328. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Input.js +57 -23
  329. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/bidi/Input.js.map +1 -1
  330. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/ElementHandle.d.ts +1 -1
  331. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/ElementHandle.d.ts.map +1 -1
  332. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/ElementHandle.js +13 -10
  333. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/ElementHandle.js.map +1 -1
  334. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/Input.d.ts +15 -4
  335. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/Input.d.ts.map +1 -1
  336. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/Input.js +55 -26
  337. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/cdp/Input.js.map +1 -1
  338. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/CallbackRegistry.d.ts +0 -8
  339. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/CallbackRegistry.d.ts.map +1 -1
  340. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/CallbackRegistry.js +1 -9
  341. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/CallbackRegistry.js.map +1 -1
  342. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/ConsoleMessage.d.ts +2 -1
  343. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/ConsoleMessage.d.ts.map +1 -1
  344. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/ConsoleMessage.js +5 -2
  345. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/ConsoleMessage.js.map +1 -1
  346. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Errors.d.ts +7 -0
  347. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Errors.d.ts.map +1 -1
  348. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Errors.js +7 -0
  349. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/Errors.js.map +1 -1
  350. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/WaitTask.d.ts.map +1 -1
  351. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/WaitTask.js +5 -3
  352. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/common/WaitTask.js.map +1 -1
  353. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/environment.d.ts +1 -1
  354. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/environment.d.ts.map +1 -1
  355. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/environment.js +0 -3
  356. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/environment.js.map +1 -1
  357. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/generated/injected.d.ts +1 -1
  358. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/generated/injected.js +1 -1
  359. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/generated/version.d.ts +1 -1
  360. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/generated/version.js +1 -1
  361. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/revisions.d.ts +3 -3
  362. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/revisions.js +3 -3
  363. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/revisions.js.map +1 -1
  364. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/util/incremental-id-generator.d.ts +14 -0
  365. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/util/incremental-id-generator.d.ts.map +1 -0
  366. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/util/incremental-id-generator.js +15 -0
  367. package/front_end/third_party/puppeteer/package/lib/esm/puppeteer/util/incremental-id-generator.js.map +1 -0
  368. package/front_end/third_party/puppeteer/package/lib/types.d.ts +51 -10
  369. package/front_end/third_party/puppeteer/package/package.json +4 -4
  370. package/front_end/third_party/puppeteer/package/src/api/Browser.ts +2 -3
  371. package/front_end/third_party/puppeteer/package/src/api/ElementHandle.ts +21 -3
  372. package/front_end/third_party/puppeteer/package/src/api/Input.ts +57 -8
  373. package/front_end/third_party/puppeteer/package/src/bidi/ElementHandle.ts +9 -7
  374. package/front_end/third_party/puppeteer/package/src/bidi/Frame.ts +1 -0
  375. package/front_end/third_party/puppeteer/package/src/bidi/Input.ts +72 -31
  376. package/front_end/third_party/puppeteer/package/src/cdp/ElementHandle.ts +14 -9
  377. package/front_end/third_party/puppeteer/package/src/cdp/Input.ts +71 -26
  378. package/front_end/third_party/puppeteer/package/src/common/CallbackRegistry.ts +1 -15
  379. package/front_end/third_party/puppeteer/package/src/common/ConsoleMessage.ts +8 -1
  380. package/front_end/third_party/puppeteer/package/src/common/Errors.ts +7 -0
  381. package/front_end/third_party/puppeteer/package/src/common/WaitTask.ts +9 -9
  382. package/front_end/third_party/puppeteer/package/src/environment.ts +1 -4
  383. package/front_end/third_party/puppeteer/package/src/generated/injected.ts +1 -1
  384. package/front_end/third_party/puppeteer/package/src/generated/version.ts +1 -1
  385. package/front_end/third_party/puppeteer/package/src/revisions.ts +3 -3
  386. package/front_end/third_party/puppeteer/package/src/util/incremental-id-generator.ts +20 -0
  387. package/front_end/third_party/puppeteer/puppeteer-tsconfig.json +1 -0
  388. package/front_end/ui/components/buttons/Button.test.ts +14 -0
  389. package/front_end/ui/components/buttons/Button.ts +27 -4
  390. package/front_end/ui/components/cards/card.css +7 -4
  391. package/front_end/ui/components/dialogs/Dialog.ts +2 -4
  392. package/front_end/ui/components/dialogs/ShortcutDialog.ts +15 -13
  393. package/front_end/ui/components/dialogs/dialog.css +2 -6
  394. package/front_end/ui/components/dialogs/shortcutDialog.css +33 -41
  395. package/front_end/ui/components/docs/freestyler/basic.ts +6 -8
  396. package/front_end/ui/components/docs/freestyler/empty_state.ts +6 -8
  397. package/front_end/ui/components/docs/performance_panel/track_example.html +1 -1
  398. package/front_end/ui/components/markdown_view/MarkdownView.test.ts +39 -17
  399. package/front_end/ui/components/markdown_view/MarkdownView.ts +77 -14
  400. package/front_end/ui/components/markdown_view/markdownView.css +15 -0
  401. package/front_end/ui/components/settings/SettingCheckbox.ts +3 -2
  402. package/front_end/ui/legacy/ContextMenu.ts +2 -2
  403. package/front_end/ui/legacy/InplaceEditor.ts +18 -14
  404. package/front_end/ui/legacy/TabbedPane.ts +0 -14
  405. package/front_end/ui/legacy/UIUtils.ts +0 -7
  406. package/front_end/ui/legacy/components/cookie_table/CookiesTable.ts +7 -2
  407. package/front_end/ui/legacy/components/data_grid/DataGrid.ts +8 -4
  408. package/front_end/ui/legacy/components/data_grid/ViewportDataGrid.ts +20 -11
  409. package/front_end/ui/legacy/components/inline_editor/LinkSwatch.test.ts +19 -0
  410. package/front_end/ui/legacy/components/inline_editor/LinkSwatch.ts +1 -1
  411. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +1 -1
  412. package/front_end/ui/legacy/components/perf_ui/FlameChart.ts +5 -22
  413. package/front_end/ui/legacy/components/perf_ui/OverviewGrid.ts +129 -100
  414. package/front_end/ui/legacy/components/perf_ui/TimelineGrid.ts +4 -2
  415. package/front_end/ui/legacy/components/perf_ui/TimelineOverviewCalculator.test.ts +9 -4
  416. package/front_end/ui/legacy/components/perf_ui/TimelineOverviewCalculator.ts +6 -6
  417. package/front_end/ui/legacy/components/perf_ui/TimelineOverviewPane.ts +22 -4
  418. package/front_end/ui/legacy/components/perf_ui/flameChart.css +0 -2
  419. package/front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.test.ts +49 -0
  420. package/front_end/ui/legacy/components/source_frame/BinaryResourceViewFactory.ts +23 -46
  421. package/front_end/ui/legacy/components/source_frame/ImageView.ts +1 -1
  422. package/front_end/ui/legacy/components/utils/ImagePreview.ts +1 -1
  423. package/front_end/ui/legacy/textPrompt.css +1 -1
  424. package/front_end/ui/legacy/toolbar.css +4 -5
  425. package/front_end/ui/visual_logging/KnownContextValues.ts +174 -0
  426. package/front_end/ui/visual_logging/LoggingConfig.ts +6 -2
  427. package/package.json +7 -6
  428. package/scripts/build/ninja/bundle.gni +3 -3
  429. package/scripts/build/{rollup.config.js → rollup.config.mjs} +4 -4
  430. package/scripts/devtools_paths.py +8 -4
  431. package/scripts/eslint_rules/tests/check_test_definitions_test.js +8 -3
  432. package/scripts/tools/update_goldens_v2.py +1 -1
  433. package/front_end/models/timeline_model/TimelineModelFilter.ts +0 -61
  434. /package/front_end/Images/{rollup.config.js → rollup.config.mjs} +0 -0
@@ -7,7 +7,11 @@ import * as i18n from '../../core/i18n/i18n.js';
7
7
  import type * as Platform from '../../core/platform/platform.js';
8
8
  import * as SDK from '../../core/sdk/sdk.js';
9
9
  import * as Workspace from '../../models/workspace/workspace.js';
10
+ import * as ElementsPanel from '../../panels/elements/elements.js';
10
11
  import * as NetworkForward from '../../panels/network/forward/forward.js';
12
+ import * as NetworkPanel from '../../panels/network/network.js';
13
+ import * as SourcesPanel from '../../panels/sources/sources.js';
14
+ import * as TimelinePanel from '../../panels/timeline/timeline.js';
11
15
  import * as TimelineUtils from '../../panels/timeline/utils/utils.js';
12
16
  import * as UI from '../../ui/legacy/legacy.js';
13
17
  import * as LitHtml from '../../ui/lit-html/lit-html.js';
@@ -15,6 +19,7 @@ import * as LitHtml from '../../ui/lit-html/lit-html.js';
15
19
  import {
16
20
  AgentType,
17
21
  type AiAgent,
22
+ type ConversationContext,
18
23
  ErrorType,
19
24
  type ResponseData,
20
25
  ResponseType,
@@ -30,12 +35,14 @@ import {
30
35
  } from './components/FreestylerChatUi.js';
31
36
  import {
32
37
  DrJonesFileAgent,
38
+ FileContext,
33
39
  } from './DrJonesFileAgent.js';
34
40
  import {
35
41
  DrJonesNetworkAgent,
42
+ RequestContext,
36
43
  } from './DrJonesNetworkAgent.js';
37
- import {DrJonesPerformanceAgent} from './DrJonesPerformanceAgent.js';
38
- import {FreestylerAgent} from './FreestylerAgent.js';
44
+ import {CallTreeContext, DrJonesPerformanceAgent} from './DrJonesPerformanceAgent.js';
45
+ import {FreestylerAgent, NodeContext} from './FreestylerAgent.js';
39
46
  import freestylerPanelStyles from './freestylerPanel.css.js';
40
47
 
41
48
  const {html} = LitHtml;
@@ -61,17 +68,29 @@ const UIStrings = {
61
68
  */
62
69
  sendFeedback: 'Send feedback',
63
70
  /**
64
- *@description Announcement text for screen readers when the chat is cleared.
71
+ *@description Announcement text for screen readers when a new chat is created.
65
72
  */
66
- chatCleared: 'Chat cleared',
73
+ newChatCreated: 'New chat created',
74
+ /**
75
+ *@description Announcement text for screen readers when the chat is deleted.
76
+ */
77
+ chatDeleted: 'Chat deleted',
67
78
  /**
68
79
  *@description AI assistance UI text creating selecting a history entry.
69
80
  */
70
81
  history: 'History',
71
82
  /**
72
- *@description AI assistance UI text clearing the current chat session.
83
+ *@description AI assistance UI text deleting the current chat session.
84
+ */
85
+ deleteChat: 'Delete chat',
86
+ /**
87
+ *@description AI assistance UI text that deletes all history entries.
88
+ */
89
+ clearChatHistory: 'Clear chat history',
90
+ /**
91
+ *@description AI assistance UI text explains that he user had no pas conversations.
73
92
  */
74
- clearChat: 'Clear chat',
93
+ noPastConversations: 'No past conversations',
75
94
  };
76
95
 
77
96
  /*
@@ -106,55 +125,6 @@ function selectedElementFilter(maybeNode: SDK.DOMModel.DOMNode|null): SDK.DOMMod
106
125
  return null;
107
126
  }
108
127
 
109
- // TODO(ergunsh): Use the WidgetElement instead of separately creating the toolbar.
110
- function createToolbar(
111
- target: HTMLElement,
112
- {onHistoryClick, onNewAgentClick, onDeleteClick}:
113
- {onHistoryClick: (event: Event) => void, onNewAgentClick: () => void, onDeleteClick: () => void}): void {
114
- const toolbarContainer = target.createChild('div', 'freestyler-toolbar-container');
115
- const leftToolbar = new UI.Toolbar.Toolbar('freestyler-left-toolbar', toolbarContainer);
116
- const rightToolbar = new UI.Toolbar.Toolbar('freestyler-right-toolbar', toolbarContainer);
117
-
118
- const clearButton =
119
- new UI.Toolbar.ToolbarButton(i18nString(UIStrings.newChat), 'plus', undefined, 'freestyler.new-chat');
120
- clearButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, onNewAgentClick);
121
- leftToolbar.appendToolbarItem(clearButton);
122
- leftToolbar.appendSeparator();
123
- const historyButton =
124
- new UI.Toolbar.ToolbarButton(i18nString(UIStrings.history), 'history', undefined, 'freestyler.history');
125
- historyButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, event => {
126
- onHistoryClick(event.data);
127
- });
128
- leftToolbar.appendToolbarItem(historyButton);
129
- const deleteButton =
130
- new UI.Toolbar.ToolbarButton(i18nString(UIStrings.clearChat), 'bin', undefined, 'freestyler.delete');
131
- deleteButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, onDeleteClick);
132
- leftToolbar.appendToolbarItem(deleteButton);
133
-
134
- const link = UI.XLink.XLink.create(
135
- AI_ASSISTANCE_SEND_FEEDBACK, i18nString(UIStrings.sendFeedback), undefined, undefined,
136
- 'freestyler.send-feedback');
137
- link.style.setProperty('display', null);
138
- link.style.setProperty('text-decoration', 'none');
139
- link.style.setProperty('padding', '0 var(--sys-size-3)');
140
- const linkItem = new UI.Toolbar.ToolbarItem(link);
141
- rightToolbar.appendToolbarItem(linkItem);
142
-
143
- rightToolbar.appendSeparator();
144
- const helpButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.help), 'help', undefined, 'freestyler.help');
145
- helpButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
146
- Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(AI_ASSISTANCE_HELP);
147
- });
148
- rightToolbar.appendToolbarItem(helpButton);
149
-
150
- const settingsButton =
151
- new UI.Toolbar.ToolbarButton(i18nString(UIStrings.settings), 'gear', undefined, 'freestyler.settings');
152
- settingsButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
153
- void UI.ViewManager.ViewManager.instance().showView('chrome-ai');
154
- });
155
- rightToolbar.appendToolbarItem(settingsButton);
156
- }
157
-
158
128
  function defaultView(input: FreestylerChatUiProps, output: ViewOutput, target: HTMLElement): void {
159
129
  // clang-format off
160
130
  LitHtml.render(html`
@@ -169,6 +139,34 @@ function defaultView(input: FreestylerChatUiProps, output: ViewOutput, target: H
169
139
  // clang-format on
170
140
  }
171
141
 
142
+ function createNodeContext(node: SDK.DOMModel.DOMNode|null): NodeContext|null {
143
+ if (!node) {
144
+ return null;
145
+ }
146
+ return new NodeContext(node);
147
+ }
148
+
149
+ function createFileContext(file: Workspace.UISourceCode.UISourceCode|null): FileContext|null {
150
+ if (!file) {
151
+ return null;
152
+ }
153
+ return new FileContext(file);
154
+ }
155
+
156
+ function createRequestContext(request: SDK.NetworkRequest.NetworkRequest|null): RequestContext|null {
157
+ if (!request) {
158
+ return null;
159
+ }
160
+ return new RequestContext(request);
161
+ }
162
+
163
+ function createCallTreeContext(callTree: TimelineUtils.AICallTree.AICallTree|null): CallTreeContext|null {
164
+ if (!callTree) {
165
+ return null;
166
+ }
167
+ return new CallTreeContext(callTree);
168
+ }
169
+
172
170
  let freestylerPanelInstance: FreestylerPanel;
173
171
  export class FreestylerPanel extends UI.Panel.Panel {
174
172
  static panelName = 'freestyler';
@@ -176,17 +174,26 @@ export class FreestylerPanel extends UI.Panel.Panel {
176
174
  #toggleSearchElementAction: UI.ActionRegistration.Action;
177
175
  #contentContainer: HTMLElement;
178
176
  #aidaClient: Host.AidaClient.AidaClient;
179
- #freestylerAgent: FreestylerAgent;
180
- #drJonesFileAgent: DrJonesFileAgent;
181
- #drJonesNetworkAgent: DrJonesNetworkAgent;
182
- #drJonesPerformanceAgent: DrJonesPerformanceAgent;
183
177
  #viewProps: FreestylerChatUiProps;
184
178
  #viewOutput: ViewOutput = {};
185
179
  #serverSideLoggingEnabled = isFreestylerServerSideLoggingEnabled();
186
180
  #freestylerEnabledSetting: Common.Settings.Setting<boolean>|undefined;
187
181
  #changeManager = new ChangeManager();
188
182
 
183
+ #newChatButton =
184
+ new UI.Toolbar.ToolbarButton(i18nString(UIStrings.newChat), 'plus', undefined, 'freestyler.new-chat');
185
+ #historyEntriesButton =
186
+ new UI.Toolbar.ToolbarButton(i18nString(UIStrings.history), 'history', undefined, 'freestyler.history');
187
+ #deleteHistoryEntryButton =
188
+ new UI.Toolbar.ToolbarButton(i18nString(UIStrings.deleteChat), 'bin', undefined, 'freestyler.delete');
189
+
189
190
  #agents = new Set<AiAgent<unknown>>();
191
+ #currentAgent?: AiAgent<unknown>;
192
+
193
+ #selectedFile: FileContext|null = null;
194
+ #selectedElement: NodeContext|null = null;
195
+ #selectedCallTree: CallTreeContext|null = null;
196
+ #selectedRequest: RequestContext|null = null;
190
197
 
191
198
  constructor(private view: View = defaultView, {aidaClient, aidaAvailability, syncInfo}: {
192
199
  aidaClient: Host.AidaClient.AidaClient,
@@ -196,11 +203,7 @@ export class FreestylerPanel extends UI.Panel.Panel {
196
203
  super(FreestylerPanel.panelName);
197
204
  this.#freestylerEnabledSetting = this.#getAiAssistanceEnabledSetting();
198
205
 
199
- createToolbar(this.contentElement, {
200
- onNewAgentClick: this.#clearMessages.bind(this),
201
- onHistoryClick: this.#onHistoryClicked.bind(this),
202
- onDeleteClick: this.#onDeleteClicked.bind(this),
203
- });
206
+ this.#createToolbar();
204
207
  this.#toggleSearchElementAction =
205
208
  UI.ActionRegistry.ActionRegistry.instance().getAction('elements.toggle-element-search');
206
209
  this.#aidaClient = aidaClient;
@@ -219,23 +222,59 @@ export class FreestylerPanel extends UI.Panel.Panel {
219
222
  onInspectElementClick: this.#handleSelectElementClick.bind(this),
220
223
  onFeedbackSubmit: this.#handleFeedbackSubmit.bind(this),
221
224
  onCancelClick: this.#cancel.bind(this),
222
- onSelectedNetworkRequestClick: this.#handleSelectedNetworkRequestClick.bind(this),
223
- onSelectedFileRequestClick: this.#handleSelectedFileClick.bind(this),
225
+ onContextClick: this.#handleContextClick.bind(this),
226
+ onNewConversation: this.#newChat.bind(this),
224
227
  canShowFeedbackForm: this.#serverSideLoggingEnabled,
225
228
  userInfo: {
226
229
  accountImage: syncInfo.accountImage,
227
230
  accountFullName: syncInfo.accountFullName,
228
231
  },
229
- selectedElement: null,
230
- selectedFile: null,
231
- selectedNetworkRequest: null,
232
- selectedAiCallTree: null,
232
+ selectedContext: null,
233
+ blockedByCrossOrigin: false,
234
+ stripLinks: false,
235
+ isReadOnly: false,
233
236
  };
237
+ }
234
238
 
235
- this.#freestylerAgent = this.#createFreestylerAgent();
236
- this.#drJonesFileAgent = this.#createDrJonesFileAgent();
237
- this.#drJonesNetworkAgent = this.#createDrJonesNetworkAgent();
238
- this.#drJonesPerformanceAgent = this.#createDrJonesPerformanceAgent();
239
+ #createToolbar(): void {
240
+ const toolbarContainer = this.contentElement.createChild('div', 'freestyler-toolbar-container');
241
+ const leftToolbar = new UI.Toolbar.Toolbar('freestyler-left-toolbar', toolbarContainer);
242
+ const rightToolbar = new UI.Toolbar.Toolbar('freestyler-right-toolbar', toolbarContainer);
243
+
244
+ this.#newChatButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, this.#newChat.bind(this));
245
+ leftToolbar.appendToolbarItem(this.#newChatButton);
246
+ leftToolbar.appendSeparator();
247
+
248
+ this.#historyEntriesButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, event => {
249
+ this.#onHistoryClicked(event.data);
250
+ });
251
+ leftToolbar.appendToolbarItem(this.#historyEntriesButton);
252
+ this.#deleteHistoryEntryButton.addEventListener(
253
+ UI.Toolbar.ToolbarButton.Events.CLICK, this.#onDeleteClicked.bind(this));
254
+ leftToolbar.appendToolbarItem(this.#deleteHistoryEntryButton);
255
+
256
+ const link = UI.XLink.XLink.create(
257
+ AI_ASSISTANCE_SEND_FEEDBACK, i18nString(UIStrings.sendFeedback), undefined, undefined,
258
+ 'freestyler.send-feedback');
259
+ link.style.setProperty('display', null);
260
+ link.style.setProperty('text-decoration', 'none');
261
+ link.style.setProperty('padding', '0 var(--sys-size-3)');
262
+ const linkItem = new UI.Toolbar.ToolbarItem(link);
263
+ rightToolbar.appendToolbarItem(linkItem);
264
+
265
+ rightToolbar.appendSeparator();
266
+ const helpButton = new UI.Toolbar.ToolbarButton(i18nString(UIStrings.help), 'help', undefined, 'freestyler.help');
267
+ helpButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
268
+ Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(AI_ASSISTANCE_HELP);
269
+ });
270
+ rightToolbar.appendToolbarItem(helpButton);
271
+
272
+ const settingsButton =
273
+ new UI.Toolbar.ToolbarButton(i18nString(UIStrings.settings), 'gear', undefined, 'freestyler.settings');
274
+ settingsButton.addEventListener(UI.Toolbar.ToolbarButton.Events.CLICK, () => {
275
+ void UI.ViewManager.ViewManager.instance().showView('chrome-ai');
276
+ });
277
+ rightToolbar.appendToolbarItem(settingsButton);
239
278
  }
240
279
 
241
280
  #getChatUiState(): FreestylerChatUiState {
@@ -253,6 +292,23 @@ export class FreestylerPanel extends UI.Panel.Panel {
253
292
  }
254
293
  }
255
294
 
295
+ #createAgent(agentType: AgentType): AiAgent<unknown> {
296
+ switch (agentType) {
297
+ case AgentType.FREESTYLER:
298
+ return this.#createFreestylerAgent();
299
+ case AgentType.DRJONES_FILE:
300
+ return this.#createDrJonesFileAgent();
301
+ case AgentType.DRJONES_NETWORK_REQUEST:
302
+ return this.#createDrJonesNetworkAgent();
303
+ case AgentType.DRJONES_PERFORMANCE:
304
+ return this.#createDrJonesPerformanceAgent();
305
+ }
306
+ }
307
+
308
+ #updateToolbarState(): void {
309
+ this.#deleteHistoryEntryButton.setVisible(Boolean(this.#currentAgent && !this.#currentAgent.isEmpty));
310
+ }
311
+
256
312
  #createFreestylerAgent(): FreestylerAgent {
257
313
  const agent = new FreestylerAgent({
258
314
  aidaClient: this.#aidaClient,
@@ -306,20 +362,60 @@ export class FreestylerPanel extends UI.Panel.Panel {
306
362
  return freestylerPanelInstance;
307
363
  }
308
364
 
365
+ // We select the default agent based on the open panels if
366
+ // there isn't any active conversation.
367
+ #selectDefaultAgentIfNeeded(): void {
368
+ // If there already is an agent and not it is not empty,
369
+ // we don't automatically change the agent.
370
+ if (this.#currentAgent && !this.#currentAgent.isEmpty) {
371
+ return;
372
+ }
373
+
374
+ const config = Common.Settings.Settings.instance().getHostConfig();
375
+ const isElementsPanelVisible =
376
+ Boolean(UI.Context.Context.instance().flavor(ElementsPanel.ElementsPanel.ElementsPanel));
377
+ const isNetworkPanelVisible = Boolean(UI.Context.Context.instance().flavor(NetworkPanel.NetworkPanel.NetworkPanel));
378
+ const isSourcesPanelVisible = Boolean(UI.Context.Context.instance().flavor(SourcesPanel.SourcesPanel.SourcesPanel));
379
+ const isPerformancePanelVisible =
380
+ Boolean(UI.Context.Context.instance().flavor(TimelinePanel.TimelinePanel.TimelinePanel));
381
+
382
+ let targetAgentType: AgentType|undefined = undefined;
383
+ if (isElementsPanelVisible && config.devToolsFreestyler?.enabled) {
384
+ targetAgentType = AgentType.FREESTYLER;
385
+ } else if (isNetworkPanelVisible && config.devToolsAiAssistanceNetworkAgent?.enabled) {
386
+ targetAgentType = AgentType.DRJONES_NETWORK_REQUEST;
387
+ } else if (isSourcesPanelVisible && config.devToolsAiAssistanceFileAgent?.enabled) {
388
+ targetAgentType = AgentType.DRJONES_FILE;
389
+ } else if (isPerformancePanelVisible && config.devToolsAiAssistancePerformanceAgent?.enabled) {
390
+ targetAgentType = AgentType.DRJONES_PERFORMANCE;
391
+ }
392
+
393
+ this.#currentAgent = targetAgentType ? this.#createAgent(targetAgentType) : undefined;
394
+ this.#viewProps.agentType = targetAgentType;
395
+ this.#onContextSelectionChanged();
396
+ this.doUpdate();
397
+ }
398
+
309
399
  override wasShown(): void {
310
400
  this.registerCSSFiles([freestylerPanelStyles]);
311
401
  this.#viewOutput.freestylerChatUi?.restoreScrollPosition();
312
402
  this.#viewOutput.freestylerChatUi?.focusTextInput();
403
+ this.#selectDefaultAgentIfNeeded();
313
404
  void this.#handleAidaAvailabilityChange();
314
405
  void this
315
406
  .#handleFreestylerEnabledSettingChanged(); // If the setting was switched on/off while the FreestylerPanel was not shown.
407
+ this.#selectedElement =
408
+ createNodeContext(selectedElementFilter(UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode))),
409
+ this.#selectedRequest =
410
+ createRequestContext(UI.Context.Context.instance().flavor(SDK.NetworkRequest.NetworkRequest)),
411
+ this.#selectedCallTree =
412
+ createCallTreeContext(UI.Context.Context.instance().flavor(TimelineUtils.AICallTree.AICallTree)),
413
+ this.#selectedFile = createFileContext(UI.Context.Context.instance().flavor(Workspace.UISourceCode.UISourceCode)),
316
414
  this.#viewProps = {
317
415
  ...this.#viewProps,
416
+ agentType: this.#currentAgent?.type,
318
417
  inspectElementToggled: this.#toggleSearchElementAction.toggled(),
319
- selectedElement: selectedElementFilter(UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode)),
320
- selectedNetworkRequest: UI.Context.Context.instance().flavor(SDK.NetworkRequest.NetworkRequest),
321
- selectedAiCallTree: UI.Context.Context.instance().flavor(TimelineUtils.AICallTree.AICallTree),
322
- selectedFile: UI.Context.Context.instance().flavor(Workspace.UISourceCode.UISourceCode),
418
+ selectedContext: this.#getConversationContext(),
323
419
  };
324
420
  this.doUpdate();
325
421
 
@@ -335,7 +431,14 @@ export class FreestylerPanel extends UI.Panel.Panel {
335
431
  TimelineUtils.AICallTree.AICallTree, this.#handleTraceEntryNodeFlavorChange);
336
432
  UI.Context.Context.instance().addFlavorChangeListener(
337
433
  Workspace.UISourceCode.UISourceCode, this.#handleUISourceCodeFlavorChange);
338
-
434
+ UI.Context.Context.instance().addFlavorChangeListener(
435
+ ElementsPanel.ElementsPanel.ElementsPanel, this.#selectDefaultAgentIfNeeded, this);
436
+ UI.Context.Context.instance().addFlavorChangeListener(
437
+ NetworkPanel.NetworkPanel.NetworkPanel, this.#selectDefaultAgentIfNeeded, this);
438
+ UI.Context.Context.instance().addFlavorChangeListener(
439
+ SourcesPanel.SourcesPanel.SourcesPanel, this.#selectDefaultAgentIfNeeded, this);
440
+ UI.Context.Context.instance().addFlavorChangeListener(
441
+ TimelinePanel.TimelinePanel.TimelinePanel, this.#selectDefaultAgentIfNeeded, this);
339
442
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.AiAssistancePanelOpened);
340
443
  }
341
444
 
@@ -352,6 +455,14 @@ export class FreestylerPanel extends UI.Panel.Panel {
352
455
  TimelineUtils.AICallTree.AICallTree, this.#handleTraceEntryNodeFlavorChange);
353
456
  UI.Context.Context.instance().removeFlavorChangeListener(
354
457
  Workspace.UISourceCode.UISourceCode, this.#handleUISourceCodeFlavorChange);
458
+ UI.Context.Context.instance().removeFlavorChangeListener(
459
+ ElementsPanel.ElementsPanel.ElementsPanel, this.#selectDefaultAgentIfNeeded, this);
460
+ UI.Context.Context.instance().removeFlavorChangeListener(
461
+ NetworkPanel.NetworkPanel.NetworkPanel, this.#selectDefaultAgentIfNeeded, this);
462
+ UI.Context.Context.instance().removeFlavorChangeListener(
463
+ SourcesPanel.SourcesPanel.SourcesPanel, this.#selectDefaultAgentIfNeeded, this);
464
+ UI.Context.Context.instance().removeFlavorChangeListener(
465
+ TimelinePanel.TimelinePanel.TimelinePanel, this.#selectDefaultAgentIfNeeded, this);
355
466
  }
356
467
 
357
468
  #handleAidaAvailabilityChange = async(): Promise<void> => {
@@ -379,42 +490,45 @@ export class FreestylerPanel extends UI.Panel.Panel {
379
490
  };
380
491
 
381
492
  #handleDOMNodeFlavorChange = (ev: Common.EventTarget.EventTargetEvent<SDK.DOMModel.DOMNode>): void => {
382
- if (this.#viewProps.selectedElement === ev.data) {
493
+ if (this.#selectedElement?.getItem() === ev.data) {
383
494
  return;
384
495
  }
385
496
 
386
- this.#viewProps.selectedElement = selectedElementFilter(ev.data);
387
- this.doUpdate();
497
+ this.#selectedElement = createNodeContext(selectedElementFilter(ev.data));
498
+ this.#onContextSelectionChanged();
388
499
  };
389
500
 
390
501
  #handleNetworkRequestFlavorChange =
391
502
  (ev: Common.EventTarget.EventTargetEvent<SDK.NetworkRequest.NetworkRequest>): void => {
392
- if (this.#viewProps.selectedNetworkRequest === ev.data) {
503
+ if (this.#selectedRequest?.getItem() === ev.data) {
393
504
  return;
394
505
  }
395
506
 
396
- this.#viewProps.selectedNetworkRequest = Boolean(ev.data) ? ev.data : null;
397
- this.doUpdate();
507
+ this.#selectedRequest = Boolean(ev.data) ? new RequestContext(ev.data) : null;
508
+ this.#onContextSelectionChanged();
398
509
  };
399
510
 
400
511
  #handleTraceEntryNodeFlavorChange =
401
512
  (ev: Common.EventTarget.EventTargetEvent<TimelineUtils.AICallTree.AICallTree>): void => {
402
- if (this.#viewProps.selectedAiCallTree === ev.data) {
513
+ if (this.#selectedCallTree?.getItem() === ev.data) {
403
514
  return;
404
515
  }
405
516
 
406
- this.#viewProps.selectedAiCallTree = Boolean(ev.data) ? ev.data : null;
407
- this.doUpdate();
517
+ this.#selectedCallTree = Boolean(ev.data) ? new CallTreeContext(ev.data) : null;
518
+ this.#onContextSelectionChanged();
408
519
  };
409
520
 
410
521
  #handleUISourceCodeFlavorChange =
411
522
  (ev: Common.EventTarget.EventTargetEvent<Workspace.UISourceCode.UISourceCode>): void => {
412
- if (this.#viewProps.selectedFile === ev.data) {
523
+ const newFile = ev.data;
524
+ if (!newFile) {
413
525
  return;
414
526
  }
415
-
416
- this.#viewProps.selectedFile = Boolean(ev.data) ? ev.data : null;
417
- this.doUpdate();
527
+ if (this.#selectedFile?.getItem() === newFile) {
528
+ return;
529
+ }
530
+ this.#selectedFile = new FileContext(ev.data);
531
+ this.#onContextSelectionChanged();
418
532
  };
419
533
 
420
534
  #handleFreestylerEnabledSettingChanged = (): void => {
@@ -428,6 +542,7 @@ export class FreestylerPanel extends UI.Panel.Panel {
428
542
  };
429
543
 
430
544
  doUpdate(): void {
545
+ this.#updateToolbarState();
431
546
  this.view(this.#viewProps, this.#viewOutput, this.#contentContainer);
432
547
  }
433
548
 
@@ -450,90 +565,94 @@ export class FreestylerPanel extends UI.Panel.Panel {
450
565
  });
451
566
  }
452
567
 
453
- #handleSelectedNetworkRequestClick(): void|Promise<void> {
454
- if (this.#viewProps.selectedNetworkRequest) {
568
+ #handleContextClick(): void|Promise<void> {
569
+ const context = this.#viewProps.selectedContext;
570
+ if (context instanceof RequestContext) {
455
571
  const requestLocation = NetworkForward.UIRequestLocation.UIRequestLocation.tab(
456
- this.#viewProps.selectedNetworkRequest, NetworkForward.UIRequestLocation.UIRequestTabs.HEADERS_COMPONENT);
572
+ context.getItem(), NetworkForward.UIRequestLocation.UIRequestTabs.HEADERS_COMPONENT);
457
573
  return Common.Revealer.reveal(requestLocation);
458
574
  }
459
- }
460
-
461
- #handleSelectedFileClick(): void|Promise<void> {
462
- if (this.#viewProps.selectedFile) {
463
- return Common.Revealer.reveal(this.#viewProps.selectedFile.uiLocation(0, 0));
575
+ if (context instanceof FileContext) {
576
+ return Common.Revealer.reveal(context.getItem().uiLocation(0, 0));
577
+ }
578
+ if (context instanceof CallTreeContext) {
579
+ const trace = new SDK.TraceObject.RevealableEvent(context.getItem().selectedNode.event);
580
+ return Common.Revealer.reveal(trace);
464
581
  }
582
+ // Node picker is using linkifier.
465
583
  }
466
584
 
467
585
  handleAction(actionId: string): void {
586
+ if (this.#viewProps.isLoading) {
587
+ // If running some queries already, focus the input with the abort
588
+ // button and do nothing.
589
+ this.#viewOutput.freestylerChatUi?.focusTextInput();
590
+ return;
591
+ }
592
+
593
+ let targetAgentType: AgentType|undefined;
468
594
  switch (actionId) {
469
595
  case 'freestyler.elements-floating-button': {
470
- this.#viewOutput.freestylerChatUi?.focusTextInput();
471
596
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.FreestylerOpenedFromElementsPanelFloatingButton);
472
- this.#viewProps.agentType = AgentType.FREESTYLER;
473
- this.#viewProps.messages = [];
474
- this.doUpdate();
475
- void this.#doConversation(this.#freestylerAgent.runFromHistory());
597
+ targetAgentType = AgentType.FREESTYLER;
476
598
  break;
477
599
  }
478
600
  case 'freestyler.element-panel-context': {
479
- this.#viewOutput.freestylerChatUi?.focusTextInput();
480
601
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.FreestylerOpenedFromElementsPanel);
481
- this.#viewProps.agentType = AgentType.FREESTYLER;
482
- this.#viewProps.messages = [];
483
- this.doUpdate();
484
- void this.#doConversation(this.#freestylerAgent.runFromHistory());
602
+ targetAgentType = AgentType.FREESTYLER;
485
603
  break;
486
604
  }
487
605
  case 'drjones.network-floating-button': {
488
- this.#viewOutput.freestylerChatUi?.focusTextInput();
489
606
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromNetworkPanelFloatingButton);
490
- this.#viewProps.agentType = AgentType.DRJONES_NETWORK_REQUEST;
491
- this.#viewProps.messages = [];
492
- this.doUpdate();
493
- void this.#doConversation(this.#drJonesNetworkAgent.runFromHistory());
607
+ targetAgentType = AgentType.DRJONES_NETWORK_REQUEST;
494
608
  break;
495
609
  }
496
610
  case 'drjones.network-panel-context': {
497
- this.#viewOutput.freestylerChatUi?.focusTextInput();
498
611
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromNetworkPanel);
499
- this.#viewProps.agentType = AgentType.DRJONES_NETWORK_REQUEST;
500
- this.#viewProps.messages = [];
501
- this.doUpdate();
502
- void this.#doConversation(this.#drJonesNetworkAgent.runFromHistory());
612
+ targetAgentType = AgentType.DRJONES_NETWORK_REQUEST;
503
613
  break;
504
614
  }
505
615
  case 'drjones.performance-panel-context': {
506
- this.#viewOutput.freestylerChatUi?.focusTextInput();
507
616
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromPerformancePanel);
508
- this.#viewProps.agentType = AgentType.DRJONES_PERFORMANCE;
509
- this.#viewProps.messages = [];
510
- this.doUpdate();
511
- void this.#doConversation(this.#drJonesPerformanceAgent.runFromHistory());
617
+ targetAgentType = AgentType.DRJONES_PERFORMANCE;
512
618
  break;
513
619
  }
514
620
  case 'drjones.sources-floating-button': {
515
- this.#viewOutput.freestylerChatUi?.focusTextInput();
516
621
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromSourcesPanelFloatingButton);
517
- this.#viewProps.agentType = AgentType.DRJONES_FILE;
518
- this.#viewProps.messages = [];
519
- this.doUpdate();
520
- void this.#doConversation(this.#drJonesFileAgent.runFromHistory());
622
+ targetAgentType = AgentType.DRJONES_FILE;
521
623
  break;
522
624
  }
523
625
  case 'drjones.sources-panel-context': {
524
- this.#viewOutput.freestylerChatUi?.focusTextInput();
525
626
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.DrJonesOpenedFromSourcesPanel);
526
- this.#viewProps.agentType = AgentType.DRJONES_FILE;
527
- this.#viewProps.messages = [];
528
- this.doUpdate();
529
- void this.#doConversation(this.#drJonesFileAgent.runFromHistory());
627
+ targetAgentType = AgentType.DRJONES_FILE;
530
628
  break;
531
629
  }
532
630
  }
631
+
632
+ if (!targetAgentType) {
633
+ return;
634
+ }
635
+
636
+ if (!this.#currentAgent || this.#currentAgent.type !== targetAgentType || this.#currentAgent.isHistoryEntry ||
637
+ targetAgentType === AgentType.DRJONES_PERFORMANCE) {
638
+ this.#currentAgent = this.#createAgent(targetAgentType);
639
+ }
640
+ this.#viewProps.agentType = this.#currentAgent.type;
641
+ this.#viewOutput.freestylerChatUi?.focusTextInput();
642
+ Host.userMetrics.actionTaken(Host.UserMetrics.Action.FreestylerOpenedFromElementsPanelFloatingButton);
643
+ this.#viewProps.messages = [];
644
+ this.#onContextSelectionChanged();
645
+ this.doUpdate();
646
+ this.#viewProps.isReadOnly = false;
647
+ void this.#doConversation(this.#currentAgent.runFromHistory());
533
648
  }
534
649
 
535
650
  #onHistoryClicked(event: Event): void {
536
- const contextMenu = new UI.ContextMenu.ContextMenu(event);
651
+ const boundingRect = this.#historyEntriesButton.element.getBoundingClientRect();
652
+ const contextMenu = new UI.ContextMenu.ContextMenu(event, {
653
+ x: boundingRect.left,
654
+ y: boundingRect.bottom,
655
+ });
537
656
 
538
657
  for (const agent of [...this.#agents].reverse()) {
539
658
  if (agent.isEmpty) {
@@ -544,98 +663,75 @@ export class FreestylerPanel extends UI.Panel.Panel {
544
663
  continue;
545
664
  }
546
665
 
547
- contextMenu.defaultSection().appendItem(
548
- title,
549
- () => {
550
- void this.#switchAgent(agent);
551
- },
552
- );
666
+ contextMenu.defaultSection().appendItem(title, () => {
667
+ void this.#switchAgent(agent);
668
+ });
669
+ }
670
+
671
+ const historyEmpty = contextMenu.defaultSection().items.length === 0;
672
+ if (historyEmpty) {
673
+ contextMenu.defaultSection().appendItem(i18nString(UIStrings.noPastConversations), () => {}, {
674
+ disabled: true,
675
+ });
553
676
  }
554
677
 
678
+ contextMenu.footerSection().appendItem(
679
+ i18nString(UIStrings.clearChatHistory),
680
+ () => {
681
+ this.#clearHistory();
682
+ },
683
+ {
684
+ disabled: historyEmpty,
685
+ },
686
+ );
687
+
555
688
  void contextMenu.show();
556
689
  }
557
690
 
691
+ #clearHistory(): void {
692
+ this.#agents = new Set();
693
+ this.#currentAgent = undefined;
694
+ this.#viewProps.messages = [];
695
+ this.#viewProps.agentType = undefined;
696
+ this.doUpdate();
697
+ }
698
+
558
699
  #onDeleteClicked(): void {
559
- if (!this.#viewProps.agentType) {
560
- return;
700
+ if (this.#currentAgent) {
701
+ this.#agents.delete(this.#currentAgent);
702
+ this.#currentAgent = undefined;
561
703
  }
562
704
 
563
- switch (this.#viewProps.agentType) {
564
- case AgentType.FREESTYLER:
565
- this.#agents.delete(this.#freestylerAgent);
566
- this.#freestylerAgent = this.#createFreestylerAgent();
567
- break;
568
- case AgentType.DRJONES_FILE:
569
- this.#agents.delete(this.#drJonesFileAgent);
570
- this.#drJonesFileAgent = this.#createDrJonesFileAgent();
571
- break;
572
- case AgentType.DRJONES_NETWORK_REQUEST:
573
- this.#agents.delete(this.#drJonesNetworkAgent);
574
- this.#drJonesNetworkAgent = this.#createDrJonesNetworkAgent();
575
- break;
576
- case AgentType.DRJONES_PERFORMANCE:
577
- this.#agents.delete(this.#drJonesPerformanceAgent);
578
- this.#drJonesPerformanceAgent = this.#createDrJonesPerformanceAgent();
579
- break;
580
- }
581
705
  this.#viewProps.messages = [];
582
- this.#viewProps.agentType = undefined;
706
+
707
+ this.#selectDefaultAgentIfNeeded();
708
+ this.#onContextSelectionChanged();
583
709
  this.doUpdate();
710
+ UI.ARIAUtils.alert(i18nString(UIStrings.chatDeleted));
584
711
  }
585
712
 
586
713
  async #switchAgent(agent: AiAgent<unknown>): Promise<void> {
587
- switch (agent.type) {
588
- case AgentType.FREESTYLER:
589
- if (this.#freestylerAgent === agent && agent.type === this.#viewProps.agentType) {
590
- return;
591
- }
592
- this.#freestylerAgent = agent as FreestylerAgent;
593
- break;
594
- case AgentType.DRJONES_FILE:
595
- if (this.#drJonesFileAgent === agent && agent.type === this.#viewProps.agentType) {
596
- return;
597
- }
598
- this.#drJonesFileAgent = agent as DrJonesFileAgent;
599
- break;
600
- case AgentType.DRJONES_NETWORK_REQUEST:
601
- if (this.#drJonesNetworkAgent === agent && agent.type === this.#viewProps.agentType) {
602
- return;
603
- }
604
- this.#drJonesNetworkAgent = agent as DrJonesNetworkAgent;
605
- break;
606
- case AgentType.DRJONES_PERFORMANCE:
607
- if (this.#drJonesPerformanceAgent === agent && agent.type === this.#viewProps.agentType) {
608
- return;
609
- }
610
- this.#drJonesPerformanceAgent = agent as DrJonesPerformanceAgent;
611
- break;
714
+ if (this.#currentAgent === agent) {
715
+ return;
612
716
  }
717
+
718
+ this.#currentAgent = agent;
613
719
  this.#viewProps.messages = [];
614
720
  this.#viewProps.agentType = agent.type;
721
+ this.#onContextSelectionChanged();
722
+ this.#viewProps.isReadOnly = true;
615
723
  await this.#doConversation(agent.runFromHistory());
616
724
  }
617
725
 
618
- #clearMessages(): void {
726
+ #newChat(): void {
619
727
  this.#viewProps.messages = [];
620
728
  this.#viewProps.isLoading = false;
621
- switch (this.#viewProps.agentType) {
622
- case AgentType.FREESTYLER:
623
- this.#freestylerAgent = this.#createFreestylerAgent();
624
- break;
625
- case AgentType.DRJONES_FILE:
626
- this.#drJonesFileAgent = this.#createDrJonesFileAgent();
627
- break;
628
- case AgentType.DRJONES_NETWORK_REQUEST:
629
- this.#drJonesNetworkAgent = this.#createDrJonesNetworkAgent();
630
- break;
631
- case AgentType.DRJONES_PERFORMANCE:
632
- this.#drJonesPerformanceAgent = this.#createDrJonesPerformanceAgent();
633
- break;
634
- }
635
-
729
+ this.#currentAgent = undefined;
636
730
  this.#cancel();
731
+
732
+ this.#selectDefaultAgentIfNeeded();
637
733
  this.doUpdate();
638
- UI.ARIAUtils.alert(i18nString(UIStrings.chatCleared));
734
+ UI.ARIAUtils.alert(i18nString(UIStrings.newChatCreated));
639
735
  }
640
736
 
641
737
  #runAbortController = new AbortController();
@@ -645,29 +741,67 @@ export class FreestylerPanel extends UI.Panel.Panel {
645
741
  this.doUpdate();
646
742
  }
647
743
 
648
- async #startConversation(text: string): Promise<void> {
649
- if (!this.#viewProps.agentType) {
744
+ #onContextSelectionChanged(): void {
745
+ if (!this.#currentAgent) {
746
+ this.#viewProps.blockedByCrossOrigin = false;
747
+ this.doUpdate();
650
748
  return;
651
749
  }
652
- this.#runAbortController = new AbortController();
653
- const signal = this.#runAbortController.signal;
750
+ const currentContext = this.#getConversationContext();
751
+ this.#viewProps.selectedContext = currentContext;
752
+ if (!currentContext) {
753
+ this.#viewProps.blockedByCrossOrigin = false;
754
+ this.#viewProps.requiresNewConversation = false;
755
+ this.doUpdate();
756
+ return;
757
+ }
758
+ this.#viewProps.blockedByCrossOrigin = !currentContext.isOriginAllowed(this.#currentAgent.origin);
759
+ this.#viewProps.isReadOnly = this.#currentAgent.isHistoryEntry;
760
+ this.#viewProps.requiresNewConversation = this.#currentAgent.type === AgentType.DRJONES_PERFORMANCE &&
761
+ Boolean(this.#currentAgent.context) && this.#currentAgent.context !== currentContext;
762
+ this.#viewProps.stripLinks = this.#viewProps.agentType === AgentType.DRJONES_PERFORMANCE;
763
+ this.doUpdate();
764
+ }
654
765
 
655
- let runner: AsyncGenerator<ResponseData, void, void>|undefined;
656
- switch (this.#viewProps.agentType) {
766
+ #getConversationContext(): ConversationContext<unknown>|null {
767
+ if (!this.#currentAgent) {
768
+ return null;
769
+ }
770
+ let context: ConversationContext<unknown>|null;
771
+ switch (this.#currentAgent.type) {
657
772
  case AgentType.FREESTYLER:
658
- runner = this.#freestylerAgent.run(text, {signal, selected: this.#viewProps.selectedElement});
773
+ context = this.#selectedElement;
659
774
  break;
660
775
  case AgentType.DRJONES_FILE:
661
- runner = this.#drJonesFileAgent.run(text, {signal, selected: this.#viewProps.selectedFile});
776
+ context = this.#selectedFile;
662
777
  break;
663
778
  case AgentType.DRJONES_NETWORK_REQUEST:
664
- runner = this.#drJonesNetworkAgent.run(text, {signal, selected: this.#viewProps.selectedNetworkRequest});
779
+ context = this.#selectedRequest;
665
780
  break;
666
781
  case AgentType.DRJONES_PERFORMANCE:
667
- runner = this.#drJonesPerformanceAgent.run(text, {signal, selected: this.#viewProps.selectedAiCallTree});
782
+ context = this.#selectedCallTree;
668
783
  break;
669
784
  }
785
+ return context;
786
+ }
670
787
 
788
+ async #startConversation(text: string): Promise<void> {
789
+ if (!this.#currentAgent) {
790
+ return;
791
+ }
792
+ this.#runAbortController = new AbortController();
793
+ const signal = this.#runAbortController.signal;
794
+ const context = this.#getConversationContext();
795
+ // If a different context is provided, it must be from the same origin.
796
+ if (context && !context.isOriginAllowed(this.#currentAgent.origin)) {
797
+ // This error should not be reached. If it happens, some
798
+ // invariants do not hold anymore.
799
+ throw new Error('cross-origin context data should not be included');
800
+ }
801
+ const runner = this.#currentAgent.run(text, {
802
+ signal,
803
+ selected: context,
804
+ });
671
805
  UI.ARIAUtils.alert(lockedString(UIStringsNotTranslate.answerLoading));
672
806
  await this.#doConversation(runner);
673
807
  UI.ARIAUtils.alert(lockedString(UIStringsNotTranslate.answerReady));