superbased 1.4.0 → 1.6.1
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/SUPERBASED_SKILL.md +129 -34
- package/dist/electron/core/platform.d.ts +2 -0
- package/dist/electron/core/platform.d.ts.map +1 -1
- package/dist/electron/main.js +95 -13
- package/dist/electron/modules/active-window.d.ts.map +1 -1
- package/dist/electron/modules/active-window.js +8 -0
- package/dist/electron/modules/active-window.js.map +1 -1
- package/dist/electron/modules/api-server.d.ts.map +1 -1
- package/dist/electron/modules/api-server.js +232 -4
- package/dist/electron/modules/api-server.js.map +1 -1
- package/dist/electron/modules/azure-speech-realtime.d.ts +13 -3
- package/dist/electron/modules/azure-speech-realtime.d.ts.map +1 -1
- package/dist/electron/modules/azure-speech-realtime.js +187 -54
- package/dist/electron/modules/azure-speech-realtime.js.map +1 -1
- package/dist/electron/modules/capture.d.ts.map +1 -1
- package/dist/electron/modules/capture.js +27 -8
- package/dist/electron/modules/capture.js.map +1 -1
- package/dist/electron/modules/dictation.d.ts +2 -0
- package/dist/electron/modules/dictation.d.ts.map +1 -1
- package/dist/electron/modules/dictation.js +145 -20
- package/dist/electron/modules/dictation.js.map +1 -1
- package/dist/electron/modules/ocr.d.ts.map +1 -1
- package/dist/electron/modules/ocr.js +15 -3
- package/dist/electron/modules/ocr.js.map +1 -1
- package/dist/electron/modules/recording/capture-queue.d.ts.map +1 -1
- package/dist/electron/modules/recording/capture-queue.js +43 -10
- package/dist/electron/modules/recording/capture-queue.js.map +1 -1
- package/dist/electron/modules/recording/index.d.ts.map +1 -1
- package/dist/electron/modules/recording/index.js +12 -6
- package/dist/electron/modules/recording/index.js.map +1 -1
- package/dist/electron/modules/recording/monitor-analyzer.d.ts +40 -0
- package/dist/electron/modules/recording/monitor-analyzer.d.ts.map +1 -0
- package/dist/electron/modules/recording/monitor-analyzer.js +220 -0
- package/dist/electron/modules/recording/monitor-analyzer.js.map +1 -0
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts +28 -0
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts.map +1 -0
- package/dist/electron/modules/recording/providers/change-detect-provider.js +181 -0
- package/dist/electron/modules/recording/providers/change-detect-provider.js.map +1 -0
- package/dist/electron/modules/recording/providers/provider-factory.d.ts +8 -2
- package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +1 -1
- package/dist/electron/modules/recording/providers/provider-factory.js +33 -12
- package/dist/electron/modules/recording/providers/provider-factory.js.map +1 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts.map +1 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.js +9 -5
- package/dist/electron/modules/recording/providers/uiohook-provider.js.map +1 -1
- package/dist/electron/modules/recording/recording-session.d.ts +5 -1
- package/dist/electron/modules/recording/recording-session.d.ts.map +1 -1
- package/dist/electron/modules/recording/recording-session.js +78 -6
- package/dist/electron/modules/recording/recording-session.js.map +1 -1
- package/dist/electron/modules/recording/trigger-engine.d.ts.map +1 -1
- package/dist/electron/modules/recording/trigger-engine.js +10 -3
- package/dist/electron/modules/recording/trigger-engine.js.map +1 -1
- package/dist/electron/modules/store.js +2 -2
- package/dist/electron/modules/store.js.map +1 -1
- package/dist/electron/modules/uiohook-manager.d.ts +19 -0
- package/dist/electron/modules/uiohook-manager.d.ts.map +1 -0
- package/dist/electron/modules/uiohook-manager.js +101 -0
- package/dist/electron/modules/uiohook-manager.js.map +1 -0
- package/dist/headless/electron/modules/active-window.js +8 -0
- package/dist/headless/electron/modules/api-server.js +137 -3
- package/dist/headless/electron/modules/azure-speech-realtime.js +187 -54
- package/dist/headless/electron/modules/dictation.js +122 -0
- package/dist/headless/headless/dictation-hotkey.js +212 -47
- package/dist/headless/headless/dictation-overlay.js +218 -0
- package/dist/headless/headless/mic-capture.js +95 -1
- package/dist/headless/headless/platform-headless.js +103 -3
- package/dist/headless/headless/win32-text-injector.js +359 -0
- package/dist/headless/mic-capture.d.ts +21 -1
- package/dist/headless/mic-capture.d.ts.map +1 -1
- package/dist/headless/mic-capture.js +95 -1
- package/dist/headless/mic-capture.js.map +1 -1
- package/dist/shared/constants.d.ts +1 -1
- package/dist/shared/constants.js +1 -1
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/recording-types.d.ts +12 -0
- package/dist/shared/recording-types.d.ts.map +1 -1
- package/mcp-server/dist/api-client.js +9 -0
- package/mcp-server/dist/index.js +91 -6
- package/package.json +2 -2
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared uiohook lifecycle manager — reference-counted start/stop.
|
|
3
|
+
//
|
|
4
|
+
// Both dictation and recording use the same uiohook-napi singleton.
|
|
5
|
+
// Without coordination, recording's stop() kills dictation's listeners.
|
|
6
|
+
// This manager tracks how many consumers need the hook running and only
|
|
7
|
+
// calls the real uIOhook.stop() when the last one releases.
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.acquire = acquire;
|
|
46
|
+
exports.release = release;
|
|
47
|
+
exports.isRunning = isRunning;
|
|
48
|
+
exports.getModule = getModule;
|
|
49
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
50
|
+
let uiohookModule = null;
|
|
51
|
+
const consumers = new Set();
|
|
52
|
+
async function ensureLoaded() {
|
|
53
|
+
if (!uiohookModule) {
|
|
54
|
+
uiohookModule = await Promise.resolve().then(() => __importStar(require('uiohook-napi')));
|
|
55
|
+
}
|
|
56
|
+
return uiohookModule;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Acquire the hook for a named consumer. Starts the native hook if not
|
|
60
|
+
* already running. Returns the uiohook module for event registration.
|
|
61
|
+
*/
|
|
62
|
+
async function acquire(consumer) {
|
|
63
|
+
const mod = await ensureLoaded();
|
|
64
|
+
const wasEmpty = consumers.size === 0;
|
|
65
|
+
consumers.add(consumer);
|
|
66
|
+
if (wasEmpty) {
|
|
67
|
+
mod.uIOhook.start();
|
|
68
|
+
logger_1.default.info(`[uiohook-manager] Hook started (consumer: ${consumer})`);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
logger_1.default.info(`[uiohook-manager] Hook already running, added consumer: ${consumer} (active: ${[...consumers].join(', ')})`);
|
|
72
|
+
}
|
|
73
|
+
return mod;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Release the hook for a named consumer. Only stops the native hook
|
|
77
|
+
* when the last consumer releases.
|
|
78
|
+
*/
|
|
79
|
+
function release(consumer) {
|
|
80
|
+
consumers.delete(consumer);
|
|
81
|
+
if (consumers.size === 0 && uiohookModule) {
|
|
82
|
+
uiohookModule.uIOhook.stop();
|
|
83
|
+
logger_1.default.info(`[uiohook-manager] Hook stopped (last consumer: ${consumer})`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
logger_1.default.info(`[uiohook-manager] Consumer released: ${consumer} (remaining: ${[...consumers].join(', ') || 'none'})`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Check if the hook is currently running (any consumer active).
|
|
91
|
+
*/
|
|
92
|
+
function isRunning() {
|
|
93
|
+
return consumers.size > 0;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the uiohook module without acquiring. Returns null if not loaded.
|
|
97
|
+
*/
|
|
98
|
+
function getModule() {
|
|
99
|
+
return uiohookModule;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=uiohook-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uiohook-manager.js","sourceRoot":"","sources":["../../../electron/modules/uiohook-manager.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,wEAAwE;AACxE,4DAA4D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkB5D,0BAaC;AAMD,0BASC;AAKD,8BAEC;AAKD,8BAEC;AA1DD,uDAA4B;AAE5B,IAAI,aAAa,GAAyC,IAAI,CAAC;AAC/D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;AAEpC,KAAK,UAAU,YAAY;IACzB,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,wDAAa,cAAc,GAAC,CAAC;IAC/C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,OAAO,CAAC,QAAgB;IAC5C,MAAM,GAAG,GAAG,MAAM,YAAY,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,KAAK,CAAC,CAAC;IACtC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAExB,IAAI,QAAQ,EAAE,CAAC;QACb,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpB,gBAAG,CAAC,IAAI,CAAC,6CAA6C,QAAQ,GAAG,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,gBAAG,CAAC,IAAI,CAAC,2DAA2D,QAAQ,aAAa,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,QAAgB;IACtC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE3B,IAAI,SAAS,CAAC,IAAI,KAAK,CAAC,IAAI,aAAa,EAAE,CAAC;QAC1C,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC7B,gBAAG,CAAC,IAAI,CAAC,kDAAkD,QAAQ,GAAG,CAAC,CAAC;IAC1E,CAAC;SAAM,CAAC;QACN,gBAAG,CAAC,IAAI,CAAC,wCAAwC,QAAQ,gBAAgB,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;IACnH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,OAAO,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -39,8 +39,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.getActiveWindowInfo = getActiveWindowInfo;
|
|
40
40
|
// Detects the currently active window for capture metadata
|
|
41
41
|
const logger_1 = __importDefault(require("../logger"));
|
|
42
|
+
const platform_1 = require("../core/platform");
|
|
42
43
|
let activeWinErrorLogged = false;
|
|
43
44
|
async function getActiveWindowInfo() {
|
|
45
|
+
// active-win is a native module compiled for Electron's Node.js.
|
|
46
|
+
// In headless mode (system Node.js), loading the native binding crashes
|
|
47
|
+
// at the C++ level (NODE_MODULE_VERSION mismatch) which can't be caught
|
|
48
|
+
// by try/catch. Skip it entirely outside Electron.
|
|
49
|
+
if (!(0, platform_1.getPlatform)().isElectron()) {
|
|
50
|
+
return { appName: null, windowTitle: null };
|
|
51
|
+
}
|
|
44
52
|
try {
|
|
45
53
|
// active-win is ESM-only, use dynamic import
|
|
46
54
|
const activeWin = await Promise.resolve().then(() => __importStar(require('active-win')));
|
|
@@ -837,8 +837,9 @@ function registerExpandedRoutes(server) {
|
|
|
837
837
|
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
838
838
|
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
839
839
|
}
|
|
840
|
-
// Window targeting: find matching window
|
|
840
|
+
// Window targeting: find matching window, bring to foreground, then capture
|
|
841
841
|
let windowInfo = null;
|
|
842
|
+
let buffer = null;
|
|
842
843
|
if (body.window) {
|
|
843
844
|
const sources = await (0, platform_1.getPlatform)().listWindows();
|
|
844
845
|
const match = sources.find((s) => s.name.toLowerCase().includes(body.window.toLowerCase()));
|
|
@@ -846,8 +847,139 @@ function registerExpandedRoutes(server) {
|
|
|
846
847
|
return reply.code(404).send({ error: `No window matching "${body.window}"`, availableWindows: sources.map((s) => s.name) });
|
|
847
848
|
}
|
|
848
849
|
windowInfo = { appName: match.name, windowTitle: match.name };
|
|
850
|
+
// Bring target window to foreground, capture, then restore original window.
|
|
851
|
+
// Uses a temp .ps1 script with Win32 P/Invoke to handle minimized windows
|
|
852
|
+
// and bypass SetForegroundWindow restrictions (AttachThreadInput trick).
|
|
853
|
+
const { execSync: execSyncCapture } = require('child_process');
|
|
854
|
+
const osMod = require('os');
|
|
855
|
+
const pathMod = require('path');
|
|
856
|
+
const fsMod = require('fs');
|
|
857
|
+
try {
|
|
858
|
+
if (process.platform === 'win32') {
|
|
859
|
+
const hwnd = match.hwnd;
|
|
860
|
+
let previousHwnd = null;
|
|
861
|
+
if (hwnd) {
|
|
862
|
+
const activateScript = pathMod.join(osMod.tmpdir(), 'superbased-activate.ps1');
|
|
863
|
+
fsMod.writeFileSync(activateScript, `
|
|
864
|
+
param([long]$TargetHwnd)
|
|
865
|
+
Add-Type -TypeDefinition @'
|
|
866
|
+
using System; using System.Runtime.InteropServices;
|
|
867
|
+
public class WinActivate {
|
|
868
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
869
|
+
[DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int c);
|
|
870
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
|
871
|
+
[DllImport("user32.dll")] public static extern bool BringWindowToTop(IntPtr h);
|
|
872
|
+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
|
873
|
+
[DllImport("kernel32.dll")] public static extern uint GetCurrentThreadId();
|
|
874
|
+
[DllImport("user32.dll")] public static extern bool AttachThreadInput(uint a, uint b, bool attach);
|
|
875
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
|
|
876
|
+
public static IntPtr Activate(IntPtr target) {
|
|
877
|
+
IntPtr prev = GetForegroundWindow();
|
|
878
|
+
uint dummy;
|
|
879
|
+
uint fgThread = GetWindowThreadProcessId(prev, out dummy);
|
|
880
|
+
uint curThread = GetCurrentThreadId();
|
|
881
|
+
AttachThreadInput(curThread, fgThread, true);
|
|
882
|
+
ShowWindow(target, 9);
|
|
883
|
+
keybd_event(0x12, 0, 1, UIntPtr.Zero);
|
|
884
|
+
keybd_event(0x12, 0, 3, UIntPtr.Zero);
|
|
885
|
+
SetForegroundWindow(target);
|
|
886
|
+
BringWindowToTop(target);
|
|
887
|
+
AttachThreadInput(curThread, fgThread, false);
|
|
888
|
+
return prev;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
'@
|
|
892
|
+
$h = [IntPtr]::new($TargetHwnd)
|
|
893
|
+
$prev = [WinActivate]::Activate($h)
|
|
894
|
+
$prev.ToInt64()
|
|
895
|
+
`);
|
|
896
|
+
try {
|
|
897
|
+
previousHwnd = execSyncCapture(`powershell -ExecutionPolicy Bypass -File "${activateScript}" -TargetHwnd ${hwnd}`, { encoding: 'utf-8', timeout: 5000, stdio: 'pipe' }).trim();
|
|
898
|
+
}
|
|
899
|
+
catch { /* ignore */ }
|
|
900
|
+
try {
|
|
901
|
+
fsMod.unlinkSync(activateScript);
|
|
902
|
+
}
|
|
903
|
+
catch { /* cleanup */ }
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
// Fallback: use AppActivate by title
|
|
907
|
+
const escapedTitle = match.name.replace(/'/g, "''");
|
|
908
|
+
execSyncCapture(`powershell -command "(New-Object -ComObject WScript.Shell).AppActivate('${escapedTitle}')"`, { timeout: 3000, stdio: 'pipe' });
|
|
909
|
+
}
|
|
910
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
911
|
+
// Capture while target is in foreground
|
|
912
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
913
|
+
// Restore the original window
|
|
914
|
+
if (previousHwnd && previousHwnd !== '0' && hwnd) {
|
|
915
|
+
const restoreScript = pathMod.join(osMod.tmpdir(), 'superbased-restore.ps1');
|
|
916
|
+
fsMod.writeFileSync(restoreScript, `
|
|
917
|
+
param([long]$Hwnd)
|
|
918
|
+
Add-Type -TypeDefinition @'
|
|
919
|
+
using System; using System.Runtime.InteropServices;
|
|
920
|
+
public class WinRestore {
|
|
921
|
+
[DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
|
|
922
|
+
[DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
|
|
923
|
+
public static void Restore(IntPtr target) {
|
|
924
|
+
keybd_event(0x12, 0, 1, UIntPtr.Zero);
|
|
925
|
+
keybd_event(0x12, 0, 3, UIntPtr.Zero);
|
|
926
|
+
SetForegroundWindow(target);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
'@
|
|
930
|
+
[WinRestore]::Restore([IntPtr]::new($Hwnd))
|
|
931
|
+
`);
|
|
932
|
+
try {
|
|
933
|
+
execSyncCapture(`powershell -ExecutionPolicy Bypass -File "${restoreScript}" -Hwnd ${previousHwnd}`, { timeout: 3000, stdio: 'pipe' });
|
|
934
|
+
}
|
|
935
|
+
catch { /* ignore */ }
|
|
936
|
+
try {
|
|
937
|
+
fsMod.unlinkSync(restoreScript);
|
|
938
|
+
}
|
|
939
|
+
catch { /* cleanup */ }
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else if (process.platform === 'darwin') {
|
|
943
|
+
// macOS: use AppleScript to get frontmost app, activate target, capture, restore
|
|
944
|
+
let previousApp = null;
|
|
945
|
+
try {
|
|
946
|
+
previousApp = execSyncCapture('osascript -e \'tell application "System Events" to get name of first process whose frontmost is true\'', { encoding: 'utf-8', timeout: 3000, stdio: 'pipe' }).trim();
|
|
947
|
+
}
|
|
948
|
+
catch { /* ignore */ }
|
|
949
|
+
// Extract app name from window title (format: "AppName - WindowTitle")
|
|
950
|
+
const dashIdx = match.name.indexOf(' - ');
|
|
951
|
+
const appName = dashIdx !== -1 ? match.name.substring(0, dashIdx) : match.name;
|
|
952
|
+
const windowTitle = dashIdx !== -1 ? match.name.substring(dashIdx + 3) : '';
|
|
953
|
+
// Activate the target window
|
|
954
|
+
const escapedApp = appName.replace(/"/g, '\\"');
|
|
955
|
+
try {
|
|
956
|
+
if (windowTitle) {
|
|
957
|
+
execSyncCapture(`osascript -e 'tell application "${escapedApp}" to activate' -e 'delay 0.2' -e 'tell application "System Events" to tell process "${escapedApp}" to set frontmost to true'`, { timeout: 3000, stdio: 'pipe' });
|
|
958
|
+
}
|
|
959
|
+
else {
|
|
960
|
+
execSyncCapture(`osascript -e 'tell application "${escapedApp}" to activate'`, { timeout: 3000, stdio: 'pipe' });
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
catch { /* ignore */ }
|
|
964
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
965
|
+
// Capture while target is in foreground
|
|
966
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
967
|
+
// Restore the previous app
|
|
968
|
+
if (previousApp) {
|
|
969
|
+
try {
|
|
970
|
+
const escapedPrev = previousApp.replace(/"/g, '\\"');
|
|
971
|
+
execSyncCapture(`osascript -e 'tell application "${escapedPrev}" to activate'`, { timeout: 3000, stdio: 'pipe' });
|
|
972
|
+
}
|
|
973
|
+
catch { /* ignore */ }
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
catch {
|
|
978
|
+
// Window activation failed — capture will get whatever is on screen
|
|
979
|
+
}
|
|
849
980
|
}
|
|
850
|
-
|
|
981
|
+
if (!buffer)
|
|
982
|
+
buffer = await (0, capture_1.captureScreen)();
|
|
851
983
|
// Auto-redact if enabled
|
|
852
984
|
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
853
985
|
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
@@ -950,7 +1082,9 @@ function registerExpandedRoutes(server) {
|
|
|
950
1082
|
windows: sources.map((s) => ({
|
|
951
1083
|
id: s.id,
|
|
952
1084
|
name: s.name,
|
|
953
|
-
|
|
1085
|
+
hwnd: s.hwnd,
|
|
1086
|
+
minimized: s.minimized,
|
|
1087
|
+
isActive: active.windowTitle ? s.name === active.windowTitle : false,
|
|
954
1088
|
})),
|
|
955
1089
|
activeWindow: active,
|
|
956
1090
|
});
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// Azure Speech Services real-time transcription via WebSocket.
|
|
3
3
|
// Uses the microsoft-cognitiveservices-speech-sdk with PushAudioInputStream
|
|
4
4
|
// for streaming audio from the renderer process.
|
|
5
|
+
//
|
|
6
|
+
// Performance: the recognizer and WebSocket are kept alive between dictation
|
|
7
|
+
// sessions (persistent mode). Only the push stream is closed/reopened per
|
|
8
|
+
// session. This eliminates the ~700ms reconnect + phrase re-attach cost.
|
|
5
9
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -44,6 +48,7 @@ exports.startRealtimeRecognition = startRealtimeRecognition;
|
|
|
44
48
|
exports.pushAudioData = pushAudioData;
|
|
45
49
|
exports.startPreBuffering = startPreBuffering;
|
|
46
50
|
exports.stopRealtimeRecognition = stopRealtimeRecognition;
|
|
51
|
+
exports.shutdownRecognizer = shutdownRecognizer;
|
|
47
52
|
exports.isRealtimeRunning = isRealtimeRunning;
|
|
48
53
|
exports.extractRegionFromEndpoint = extractRegionFromEndpoint;
|
|
49
54
|
const fs = __importStar(require("fs"));
|
|
@@ -56,6 +61,14 @@ let recognizer = null;
|
|
|
56
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
62
|
let pushStream = null;
|
|
58
63
|
let isRunning = false;
|
|
64
|
+
// Pre-warmed recognizer: created in background after each session ends,
|
|
65
|
+
// ready for instant use on the next dictation.
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
let standbyRecognizer = null;
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
let standbyPushStream = null;
|
|
70
|
+
let standbyReady = false;
|
|
71
|
+
let lastConfig = null;
|
|
59
72
|
// Accumulate final results across multiple recognized events
|
|
60
73
|
let finalText = '';
|
|
61
74
|
// Last accepted recognized text — used to skip exact duplicates that Azure
|
|
@@ -115,50 +128,7 @@ function loadBundledPhraseList() {
|
|
|
115
128
|
cachedPhraseList = [];
|
|
116
129
|
return cachedPhraseList;
|
|
117
130
|
}
|
|
118
|
-
|
|
119
|
-
const speechSdk = await loadSdk();
|
|
120
|
-
if (isRunning) {
|
|
121
|
-
logger_1.default.warn('[AzureSpeechRT] Already running, stopping previous session');
|
|
122
|
-
await stopRealtimeRecognition();
|
|
123
|
-
}
|
|
124
|
-
finalText = '';
|
|
125
|
-
lastRecognized = '';
|
|
126
|
-
// Create speech config
|
|
127
|
-
const speechConfig = speechSdk.SpeechConfig.fromSubscription(subscriptionKey, region);
|
|
128
|
-
speechConfig.speechRecognitionLanguage = language || 'en-US';
|
|
129
|
-
speechConfig.enableDictation(); // Optimizes for dictation: better punctuation, handles longer pauses
|
|
130
|
-
// Silence timeouts — configurable via Settings > Dictation > Advanced
|
|
131
|
-
const endSilence = timing?.endSilenceMs ?? 5000;
|
|
132
|
-
const initialSilence = timing?.initialSilenceMs ?? 15000;
|
|
133
|
-
const segSilence = timing?.segmentationSilenceMs ?? 3000;
|
|
134
|
-
speechConfig.setProperty('speechServiceConnection_endSilenceTimeoutMs', String(endSilence));
|
|
135
|
-
speechConfig.setProperty('speechServiceConnection_initialSilenceTimeoutMs', String(initialSilence));
|
|
136
|
-
speechConfig.setProperty('Speech_SegmentationSilenceTimeoutMs', String(segSilence));
|
|
137
|
-
// Create push stream — expects 16kHz, 16-bit, mono PCM
|
|
138
|
-
const format = speechSdk.AudioStreamFormat.getWaveFormatPCM(16000, 16, 1);
|
|
139
|
-
pushStream = speechSdk.AudioInputStream.createPushStream(format);
|
|
140
|
-
// Create audio config from push stream
|
|
141
|
-
const audioConfig = speechSdk.AudioConfig.fromStreamInput(pushStream);
|
|
142
|
-
// Create recognizer
|
|
143
|
-
recognizer = new speechSdk.SpeechRecognizer(speechConfig, audioConfig);
|
|
144
|
-
// Attach a phrase list grammar to boost recognition of technical terms.
|
|
145
|
-
// Combines the bundled curated list (~600 dev/cloud/AI terms) with any
|
|
146
|
-
// caller-supplied extras (typically the user's personal dictionary).
|
|
147
|
-
// Azure caps a single grammar at 1024 phrases per session.
|
|
148
|
-
try {
|
|
149
|
-
const bundled = loadBundledPhraseList();
|
|
150
|
-
const merged = mergePhrases(bundled, extraPhrases || []);
|
|
151
|
-
if (merged.length > 0) {
|
|
152
|
-
const phraseList = speechSdk.PhraseListGrammar.fromRecognizer(recognizer);
|
|
153
|
-
for (const phrase of merged) {
|
|
154
|
-
phraseList.addPhrase(phrase);
|
|
155
|
-
}
|
|
156
|
-
logger_1.default.info(`[AzureSpeechRT] Attached ${merged.length} phrases (bundled=${bundled.length}, extra=${extraPhrases?.length || 0})`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
logger_1.default.warn('[AzureSpeechRT] Failed to attach phrase list:', err);
|
|
161
|
-
}
|
|
131
|
+
function attachRecognizerEvents(speechSdk, callbacks) {
|
|
162
132
|
// Intermediate results — updates as user speaks
|
|
163
133
|
recognizer.recognizing = (_sender, e) => {
|
|
164
134
|
if (e.result.text) {
|
|
@@ -222,6 +192,70 @@ async function startRealtimeRecognition(subscriptionKey, region, language, callb
|
|
|
222
192
|
callbacks.onError(`Recognition error: ${e.errorDetails}`);
|
|
223
193
|
}
|
|
224
194
|
};
|
|
195
|
+
}
|
|
196
|
+
async function startRealtimeRecognition(subscriptionKey, region, language, callbacks, timing, extraPhrases) {
|
|
197
|
+
const speechSdk = await loadSdk();
|
|
198
|
+
// If a pre-warmed standby recognizer is ready, use it instantly.
|
|
199
|
+
// It was created in the background after the previous session ended.
|
|
200
|
+
if (standbyReady && standbyRecognizer && standbyPushStream) {
|
|
201
|
+
logger_1.default.info('[AzureSpeechRT] Using pre-warmed standby recognizer (instant)');
|
|
202
|
+
recognizer = standbyRecognizer;
|
|
203
|
+
pushStream = standbyPushStream;
|
|
204
|
+
standbyRecognizer = null;
|
|
205
|
+
standbyPushStream = null;
|
|
206
|
+
standbyReady = false;
|
|
207
|
+
finalText = '';
|
|
208
|
+
lastRecognized = '';
|
|
209
|
+
attachRecognizerEvents(speechSdk, callbacks);
|
|
210
|
+
isRunning = true;
|
|
211
|
+
flushPreBuffer();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (isRunning) {
|
|
215
|
+
logger_1.default.warn('[AzureSpeechRT] Already running, stopping previous session');
|
|
216
|
+
await stopRealtimeRecognition();
|
|
217
|
+
}
|
|
218
|
+
finalText = '';
|
|
219
|
+
lastRecognized = '';
|
|
220
|
+
// Create speech config
|
|
221
|
+
const speechConfig = speechSdk.SpeechConfig.fromSubscription(subscriptionKey, region);
|
|
222
|
+
speechConfig.speechRecognitionLanguage = language || 'en-US';
|
|
223
|
+
speechConfig.enableDictation(); // Optimizes for dictation: better punctuation, handles longer pauses
|
|
224
|
+
// Silence timeouts — configurable via Settings > Dictation > Advanced
|
|
225
|
+
const endSilence = timing?.endSilenceMs ?? 5000;
|
|
226
|
+
const initialSilence = timing?.initialSilenceMs ?? 15000;
|
|
227
|
+
const segSilence = timing?.segmentationSilenceMs ?? 3000;
|
|
228
|
+
speechConfig.setProperty('speechServiceConnection_endSilenceTimeoutMs', String(endSilence));
|
|
229
|
+
speechConfig.setProperty('speechServiceConnection_initialSilenceTimeoutMs', String(initialSilence));
|
|
230
|
+
speechConfig.setProperty('Speech_SegmentationSilenceTimeoutMs', String(segSilence));
|
|
231
|
+
// Save config for pre-warming the next standby recognizer
|
|
232
|
+
lastConfig = { key: subscriptionKey, region, language, timing, phrases: extraPhrases };
|
|
233
|
+
// Create push stream — expects 16kHz, 16-bit, mono PCM
|
|
234
|
+
const format = speechSdk.AudioStreamFormat.getWaveFormatPCM(16000, 16, 1);
|
|
235
|
+
pushStream = speechSdk.AudioInputStream.createPushStream(format);
|
|
236
|
+
// Create audio config from push stream
|
|
237
|
+
const audioConfig = speechSdk.AudioConfig.fromStreamInput(pushStream);
|
|
238
|
+
// Create recognizer
|
|
239
|
+
recognizer = new speechSdk.SpeechRecognizer(speechConfig, audioConfig);
|
|
240
|
+
// Attach a phrase list grammar to boost recognition of technical terms.
|
|
241
|
+
// Combines the bundled curated list (~600 dev/cloud/AI terms) with any
|
|
242
|
+
// caller-supplied extras (typically the user's personal dictionary).
|
|
243
|
+
// Azure caps a single grammar at 1024 phrases per session.
|
|
244
|
+
try {
|
|
245
|
+
const bundled = loadBundledPhraseList();
|
|
246
|
+
const merged = mergePhrases(bundled, extraPhrases || []);
|
|
247
|
+
if (merged.length > 0) {
|
|
248
|
+
const phraseList = speechSdk.PhraseListGrammar.fromRecognizer(recognizer);
|
|
249
|
+
for (const phrase of merged) {
|
|
250
|
+
phraseList.addPhrase(phrase);
|
|
251
|
+
}
|
|
252
|
+
logger_1.default.info(`[AzureSpeechRT] Attached ${merged.length} phrases (bundled=${bundled.length}, extra=${extraPhrases?.length || 0})`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
logger_1.default.warn('[AzureSpeechRT] Failed to attach phrase list:', err);
|
|
257
|
+
}
|
|
258
|
+
attachRecognizerEvents(speechSdk, callbacks);
|
|
225
259
|
// Start continuous recognition
|
|
226
260
|
return new Promise((resolve, reject) => {
|
|
227
261
|
recognizer.startContinuousRecognitionAsync(() => {
|
|
@@ -269,24 +303,30 @@ function flushPreBuffer() {
|
|
|
269
303
|
preBuffering = false;
|
|
270
304
|
}
|
|
271
305
|
/**
|
|
272
|
-
* Stop
|
|
273
|
-
*
|
|
274
|
-
*
|
|
306
|
+
* Stop the current dictation session and return the accumulated transcript.
|
|
307
|
+
*
|
|
308
|
+
* In persistent mode: closes the push stream (signals end-of-audio) and
|
|
309
|
+
* stops recognition, but keeps the recognizer alive for the next session.
|
|
310
|
+
* The recognizer will be restarted with a new push stream on the next call
|
|
311
|
+
* to startRealtimeRecognition().
|
|
312
|
+
*
|
|
313
|
+
* The stopContinuousRecognitionAsync call ensures all recognized events
|
|
314
|
+
* have fired before we grab finalText.
|
|
275
315
|
*/
|
|
276
316
|
async function stopRealtimeRecognition() {
|
|
277
317
|
if (!isRunning)
|
|
278
318
|
return finalText;
|
|
279
|
-
// Close push stream
|
|
319
|
+
// Close push stream — signals end of audio to SDK
|
|
280
320
|
if (pushStream) {
|
|
281
321
|
pushStream.close();
|
|
282
322
|
pushStream = null;
|
|
283
323
|
}
|
|
284
|
-
//
|
|
285
|
-
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
286
|
-
// Stop the recognizer
|
|
324
|
+
// Stop recognition — ensures all recognized events have fired
|
|
287
325
|
if (recognizer) {
|
|
326
|
+
const oldRecognizer = recognizer;
|
|
327
|
+
recognizer = null;
|
|
288
328
|
await new Promise((resolve) => {
|
|
289
|
-
|
|
329
|
+
oldRecognizer.stopContinuousRecognitionAsync(() => {
|
|
290
330
|
logger_1.default.info('[AzureSpeechRT] Stopped');
|
|
291
331
|
resolve();
|
|
292
332
|
}, (err) => {
|
|
@@ -294,15 +334,108 @@ async function stopRealtimeRecognition() {
|
|
|
294
334
|
resolve();
|
|
295
335
|
});
|
|
296
336
|
});
|
|
297
|
-
recognizer
|
|
298
|
-
|
|
337
|
+
// Close the old recognizer in background
|
|
338
|
+
setTimeout(() => { try {
|
|
339
|
+
oldRecognizer.close();
|
|
340
|
+
}
|
|
341
|
+
catch { /* ignore */ } }, 0);
|
|
299
342
|
}
|
|
300
343
|
isRunning = false;
|
|
301
344
|
const result = finalText;
|
|
302
345
|
finalText = '';
|
|
303
346
|
lastRecognized = '';
|
|
347
|
+
// Pre-warm the next recognizer in the background so it's ready
|
|
348
|
+
// by the time the user starts the next dictation session.
|
|
349
|
+
prewarmStandby();
|
|
304
350
|
return result;
|
|
305
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Create a standby recognizer in the background using the last config.
|
|
354
|
+
* Called after each session ends. The standby is fully connected with
|
|
355
|
+
* phrases attached — ready for instant use on the next dictation.
|
|
356
|
+
*/
|
|
357
|
+
function prewarmStandby() {
|
|
358
|
+
if (!lastConfig || !sdk)
|
|
359
|
+
return;
|
|
360
|
+
// Clean up any existing standby
|
|
361
|
+
if (standbyRecognizer) {
|
|
362
|
+
try {
|
|
363
|
+
standbyRecognizer.close();
|
|
364
|
+
}
|
|
365
|
+
catch { /* ignore */ }
|
|
366
|
+
standbyRecognizer = null;
|
|
367
|
+
standbyPushStream = null;
|
|
368
|
+
standbyReady = false;
|
|
369
|
+
}
|
|
370
|
+
const { key, region, language, timing, phrases } = lastConfig;
|
|
371
|
+
const speechSdk = sdk;
|
|
372
|
+
// Create everything fresh
|
|
373
|
+
const speechConfig = speechSdk.SpeechConfig.fromSubscription(key, region);
|
|
374
|
+
speechConfig.speechRecognitionLanguage = language || 'en-US';
|
|
375
|
+
speechConfig.enableDictation();
|
|
376
|
+
const endSilence = timing?.endSilenceMs ?? 5000;
|
|
377
|
+
const initialSilence = timing?.initialSilenceMs ?? 15000;
|
|
378
|
+
const segSilence = timing?.segmentationSilenceMs ?? 3000;
|
|
379
|
+
speechConfig.setProperty('speechServiceConnection_endSilenceTimeoutMs', String(endSilence));
|
|
380
|
+
speechConfig.setProperty('speechServiceConnection_initialSilenceTimeoutMs', String(initialSilence));
|
|
381
|
+
speechConfig.setProperty('Speech_SegmentationSilenceTimeoutMs', String(segSilence));
|
|
382
|
+
const format = speechSdk.AudioStreamFormat.getWaveFormatPCM(16000, 16, 1);
|
|
383
|
+
const newPushStream = speechSdk.AudioInputStream.createPushStream(format);
|
|
384
|
+
const audioConfig = speechSdk.AudioConfig.fromStreamInput(newPushStream);
|
|
385
|
+
const newRecognizer = new speechSdk.SpeechRecognizer(speechConfig, audioConfig);
|
|
386
|
+
// Attach phrases
|
|
387
|
+
try {
|
|
388
|
+
const bundled = loadBundledPhraseList();
|
|
389
|
+
const merged = mergePhrases(bundled, phrases || []);
|
|
390
|
+
if (merged.length > 0) {
|
|
391
|
+
const phraseList = speechSdk.PhraseListGrammar.fromRecognizer(newRecognizer);
|
|
392
|
+
for (const phrase of merged) {
|
|
393
|
+
phraseList.addPhrase(phrase);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
catch { /* ignore */ }
|
|
398
|
+
// Start recognition so the WebSocket connects
|
|
399
|
+
newRecognizer.startContinuousRecognitionAsync(() => {
|
|
400
|
+
standbyRecognizer = newRecognizer;
|
|
401
|
+
standbyPushStream = newPushStream;
|
|
402
|
+
standbyReady = true;
|
|
403
|
+
logger_1.default.info('[AzureSpeechRT] Standby recognizer pre-warmed and ready');
|
|
404
|
+
}, (err) => {
|
|
405
|
+
logger_1.default.warn('[AzureSpeechRT] Failed to pre-warm standby:', err);
|
|
406
|
+
try {
|
|
407
|
+
newRecognizer.close();
|
|
408
|
+
}
|
|
409
|
+
catch { /* ignore */ }
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Fully shut down the recognizer (called on app exit).
|
|
414
|
+
*/
|
|
415
|
+
async function shutdownRecognizer() {
|
|
416
|
+
lastConfig = null; // Prevent prewarmStandby from running during stop
|
|
417
|
+
// Clean up standby
|
|
418
|
+
if (standbyRecognizer) {
|
|
419
|
+
try {
|
|
420
|
+
standbyRecognizer.close();
|
|
421
|
+
}
|
|
422
|
+
catch { /* ignore */ }
|
|
423
|
+
standbyRecognizer = null;
|
|
424
|
+
standbyPushStream = null;
|
|
425
|
+
standbyReady = false;
|
|
426
|
+
}
|
|
427
|
+
if (isRunning) {
|
|
428
|
+
await stopRealtimeRecognition();
|
|
429
|
+
}
|
|
430
|
+
if (recognizer) {
|
|
431
|
+
try {
|
|
432
|
+
recognizer.close();
|
|
433
|
+
}
|
|
434
|
+
catch { /* ignore */ }
|
|
435
|
+
recognizer = null;
|
|
436
|
+
}
|
|
437
|
+
lastConfig = null;
|
|
438
|
+
}
|
|
306
439
|
/**
|
|
307
440
|
* Deduplicate + cap a phrase list. Azure's PhraseListGrammar accepts up to
|
|
308
441
|
* 1024 phrases per session — we prioritise caller-supplied extras (personal
|