1- // Copyright (c) Meta Platforms, Inc. and affiliates.
2- // Copyright 2024 The Chromium Authors. All rights reserved.
1+ // Copyright 2025 The Chromium Authors. All rights reserved.
32// Use of this source code is governed by a BSD-style license that can be
43// found in the LICENSE file.
54
6- import * as UI from '../../ui/legacy/legacy.js' ;
7- import livematePanelStyles from './livematePanel.css.js' ;
8- import * as SDK from '../../core/sdk/sdk.js' ;
9- import { ReactDevToolsViewBase } from '../react_devtools/ReactDevToolsViewBase.js' ;
5+ import * as Host from '../../core/host/host.js' ;
106import * as i18n from '../../core/i18n/i18n.js' ;
7+ import { ReactDevToolsViewBase } from '../react_devtools/ReactDevToolsViewBase.js' ;
8+
9+ import livematePanelStyles from './livematePanel.css.js' ;
1110
1211let livematePanelInstance : LivematePanel ;
1312
@@ -17,7 +16,10 @@ const UIStrings = {
1716 */
1817 title : '⚛️ Livemate' ,
1918} as const ;
20- const str_ = i18n . i18n . registerUIStrings ( 'panels/livemate/LivematePanel.ts' , UIStrings ) ;
19+ const str_ = i18n . i18n . registerUIStrings (
20+ 'panels/livemate/LivematePanel.ts' ,
21+ UIStrings
22+ ) ;
2123const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
2224
2325export class LivematePanel extends ReactDevToolsViewBase {
@@ -28,48 +30,56 @@ export class LivematePanel extends ReactDevToolsViewBase {
2830 return livematePanelInstance ;
2931 }
3032
31- constructor ( ) {
33+ constructor ( ) {
3234 super ( 'components' , i18nString ( UIStrings . title ) ) ;
35+ this . registerRequiredCSS ( livematePanelStyles ) ;
3336 }
3437
3538 override renderDevToolsView ( ) : void {
3639 this . clearView ( ) ;
3740
38- const model = this . model ;
39- if ( model === null ) {
40- throw new Error ( 'Attempted to render React DevTools panel, but the model was null' ) ;
41- }
41+ this . contentElement . classList . add ( 'livemate-panel' ) ;
4242
43- const bridge = model . getBridgeOrThrow ( ) ;
43+ const promptSection = this . contentElement . createChild (
44+ 'div' ,
45+ 'livemate-prompt-section'
46+ ) ;
4447
45- const button = document . createElement ( 'button' ) ;
46- button . textContent = 'Start Inspecting Host' ;
48+ const promptTextarea = document . createElement ( 'textarea' ) ;
49+ promptTextarea . className = 'livemate-prompt-input' ;
50+ promptTextarea . placeholder = 'Ask Devmate anything about this app...' ;
51+ promptSection . appendChild ( promptTextarea ) ;
4752
48- bridge . addListener ( 'selectElement' , ( element : any ) => { console . log ( element ) } ) ;
53+ const sendButton = promptSection . createChild (
54+ 'button' ,
55+ 'livemate-send-button'
56+ ) ;
57+ sendButton . textContent = 'Send to Devmate' ;
4958
50- let inspecting = false ;
59+ const statusArea = promptSection . createChild ( 'div' , 'livemate-status' ) ;
5160
52- button . onclick = ( ) => {
53- if ( inspecting ) {
54- ( bridge as any ) . send ( 'stopInspectingHost' ) ;
55- button . textContent = 'Start Inspecting Host' ;
56- inspecting = false ;
57- } else {
58- ( bridge as any ) . send ( 'startInspectingHost' , false ) ;
59- button . textContent = 'Stop Inspecting Host' ;
60- inspecting = true ;
61+ const handleSend = ( ) : void => {
62+ const prompt = promptTextarea . value . trim ( ) ;
63+ if ( ! prompt ) {
64+ statusArea . textContent = 'Please enter a prompt' ;
65+ statusArea . className = 'livemate-status error' ;
66+ return ;
6167 }
62- }
63-
64- this . contentElement . appendChild ( button ) ;
65-
66-
67-
68- // bridge.send('stopInspectingHost');
68+ statusArea . textContent = 'Sending to Devmate...' ;
69+ statusArea . className = 'livemate-status pending' ;
70+
71+ (
72+ Host . InspectorFrontendHost . InspectorFrontendHostInstance as unknown as {
73+ sendToDevmate : ( prompt : string ) => void ,
74+ }
75+ ) . sendToDevmate ( prompt ) ;
76+ } ;
77+
78+ sendButton . addEventListener ( 'click' , handleSend ) ;
79+ promptTextarea . addEventListener ( 'keydown' , e => {
80+ if ( e . key === 'Enter' && ( e . metaKey || e . ctrlKey ) ) {
81+ handleSend ( ) ;
82+ }
83+ } ) ;
6984 }
70-
71- // this.contentElement.removeChildren();
72-
73- // const header = this.contentElement.createChild('div', 'livemate-header');
74- // header.textContent = 'Livemate Panel';
7585}
0 commit comments