lazy-gravity 0.5.2 → 0.5.3
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/dist/services/cdpService.js +100 -0
- package/package.json +1 -1
|
@@ -123,6 +123,18 @@ class CdpService extends events_1.EventEmitter {
|
|
|
123
123
|
(t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade')) &&
|
|
124
124
|
!t.title?.includes('Launchpad'));
|
|
125
125
|
}
|
|
126
|
+
// No workbench page found — try to open the chat panel automatically
|
|
127
|
+
// before falling back to Launchpad
|
|
128
|
+
if (!target) {
|
|
129
|
+
const anyPage = allPages.find(t => t.webSocketDebuggerUrl);
|
|
130
|
+
if (anyPage) {
|
|
131
|
+
logger_1.logger.debug('[CdpService] No workbench page found. Attempting to open chat panel via Cmd+L / Ctrl+L...');
|
|
132
|
+
await this.openChatPanelViaKeyboard(anyPage.webSocketDebuggerUrl);
|
|
133
|
+
// Re-scan after opening chat panel
|
|
134
|
+
target = await this.findWorkbenchTarget();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Last resort: accept Launchpad as target
|
|
126
138
|
if (!target) {
|
|
127
139
|
target = allPages.find(t => t.webSocketDebuggerUrl &&
|
|
128
140
|
(t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade') || t.title?.includes('Launchpad')));
|
|
@@ -578,6 +590,94 @@ class CdpService extends events_1.EventEmitter {
|
|
|
578
590
|
}
|
|
579
591
|
throw new Error(`Workbench page for workspace "${projectName}" not found within ${maxWaitMs / 1000} seconds`);
|
|
580
592
|
}
|
|
593
|
+
/**
|
|
594
|
+
* Scan all CDP ports and return the first workbench-like target page.
|
|
595
|
+
*/
|
|
596
|
+
async findWorkbenchTarget() {
|
|
597
|
+
let allPages = [];
|
|
598
|
+
for (const port of this.ports) {
|
|
599
|
+
try {
|
|
600
|
+
const list = await this.getJson(`http://127.0.0.1:${port}/json/list`);
|
|
601
|
+
allPages.push(...list);
|
|
602
|
+
}
|
|
603
|
+
catch {
|
|
604
|
+
// port not responding
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return (allPages.find(t => t.type === 'page' &&
|
|
608
|
+
t.webSocketDebuggerUrl &&
|
|
609
|
+
!t.title?.includes('Launchpad') &&
|
|
610
|
+
!t.url?.includes('workbench-jetski-agent') &&
|
|
611
|
+
(t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade'))) ??
|
|
612
|
+
allPages.find(t => t.webSocketDebuggerUrl &&
|
|
613
|
+
(t.url?.includes('workbench') || t.title?.includes('Antigravity') || t.title?.includes('Cascade')) &&
|
|
614
|
+
!t.title?.includes('Launchpad')) ??
|
|
615
|
+
null);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Temporarily connect to a page and send Cmd+L / Ctrl+L to open the chat panel.
|
|
619
|
+
*/
|
|
620
|
+
async openChatPanelViaKeyboard(wsUrl) {
|
|
621
|
+
const tempWs = new ws_1.default(wsUrl);
|
|
622
|
+
let idCounter = 1;
|
|
623
|
+
try {
|
|
624
|
+
await new Promise((resolve, reject) => {
|
|
625
|
+
tempWs.on('open', resolve);
|
|
626
|
+
tempWs.on('error', reject);
|
|
627
|
+
setTimeout(() => reject(new Error('Timeout')), 5000);
|
|
628
|
+
});
|
|
629
|
+
const send = (method, params = {}) => new Promise((resolve, reject) => {
|
|
630
|
+
const id = idCounter++;
|
|
631
|
+
tempWs.send(JSON.stringify({ id, method, params }));
|
|
632
|
+
const timeout = setTimeout(() => reject(new Error('Timeout')), 3000);
|
|
633
|
+
const onMsg = (raw) => {
|
|
634
|
+
try {
|
|
635
|
+
const data = JSON.parse(raw.toString());
|
|
636
|
+
if (data.id === id) {
|
|
637
|
+
clearTimeout(timeout);
|
|
638
|
+
tempWs.off('message', onMsg);
|
|
639
|
+
resolve();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
catch { /* ignore */ }
|
|
643
|
+
};
|
|
644
|
+
tempWs.on('message', onMsg);
|
|
645
|
+
});
|
|
646
|
+
const modifiers = process.platform === 'darwin' ? 4 : 2; // Meta : Ctrl
|
|
647
|
+
await send('Input.dispatchKeyEvent', {
|
|
648
|
+
type: 'keyDown',
|
|
649
|
+
key: 'l',
|
|
650
|
+
code: 'KeyL',
|
|
651
|
+
modifiers,
|
|
652
|
+
windowsVirtualKeyCode: 76,
|
|
653
|
+
nativeVirtualKeyCode: 76,
|
|
654
|
+
});
|
|
655
|
+
await send('Input.dispatchKeyEvent', {
|
|
656
|
+
type: 'keyUp',
|
|
657
|
+
key: 'l',
|
|
658
|
+
code: 'KeyL',
|
|
659
|
+
modifiers,
|
|
660
|
+
windowsVirtualKeyCode: 76,
|
|
661
|
+
nativeVirtualKeyCode: 76,
|
|
662
|
+
});
|
|
663
|
+
// Wait until a workbench target appears, up to a bounded timeout
|
|
664
|
+
const deadline = Date.now() + 10000;
|
|
665
|
+
while (Date.now() < deadline) {
|
|
666
|
+
await new Promise(r => setTimeout(r, 500));
|
|
667
|
+
if (await this.findWorkbenchTarget()) {
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
catch (e) {
|
|
673
|
+
logger_1.logger.debug(`[CdpService] Failed to open chat panel automatically: ${e}`);
|
|
674
|
+
}
|
|
675
|
+
finally {
|
|
676
|
+
if (tempWs.readyState === ws_1.default.OPEN) {
|
|
677
|
+
tempWs.close();
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
581
681
|
async runCommand(command, args) {
|
|
582
682
|
await new Promise((resolve, reject) => {
|
|
583
683
|
const child = (0, child_process_1.spawn)(command, args, { stdio: 'ignore' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lazy-gravity",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Control Antigravity from anywhere — a local, secure bot (Discord + Telegram) that lets you remotely operate Antigravity on your home PC from your smartphone.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|