superbased 2.0.2 → 2.0.9
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/electron/core/settings-schema.d.ts.map +1 -1
- package/dist/electron/core/settings-schema.js +14 -1
- package/dist/electron/core/settings-schema.js.map +1 -1
- package/dist/electron/modules/api-server.d.ts.map +1 -1
- package/dist/electron/modules/api-server.js +13 -2
- package/dist/electron/modules/api-server.js.map +1 -1
- package/dist/electron/modules/dictation.d.ts.map +1 -1
- package/dist/electron/modules/dictation.js +51 -8
- package/dist/electron/modules/dictation.js.map +1 -1
- package/dist/electron/modules/stt/macos-engine.d.ts.map +1 -1
- package/dist/electron/modules/stt/macos-engine.js +34 -6
- package/dist/electron/modules/stt/macos-engine.js.map +1 -1
- package/dist/electron/modules/stt/router.d.ts.map +1 -1
- package/dist/electron/modules/stt/router.js +36 -5
- package/dist/electron/modules/stt/router.js.map +1 -1
- package/dist/headless/electron/core/settings-schema.js +14 -1
- package/dist/headless/electron/modules/api-server.js +13 -2
- package/dist/headless/electron/modules/dictation.js +51 -8
- package/dist/headless/electron/modules/stt/macos-engine.js +34 -6
- package/dist/headless/electron/modules/stt/router.js +36 -5
- package/mcp-server/dist/index.js +42 -0
- package/package.json +5 -5
|
@@ -65,6 +65,7 @@ const keystroke_1 = require("./keystroke");
|
|
|
65
65
|
const active_window_1 = require("./active-window");
|
|
66
66
|
const database_1 = require("../db/database");
|
|
67
67
|
const constants_1 = require("../../shared/constants");
|
|
68
|
+
const router_1 = require("./stt/router");
|
|
68
69
|
let state = 'idle';
|
|
69
70
|
let indicatorWindow = null;
|
|
70
71
|
let uiohookModule = null;
|
|
@@ -74,6 +75,7 @@ let soundFeedback = true;
|
|
|
74
75
|
let maxDurationSeconds = 120;
|
|
75
76
|
let excludedApps = [];
|
|
76
77
|
let language = '';
|
|
78
|
+
let sttEngine = 'auto';
|
|
77
79
|
let pasteMethod = 'clipboard'; // 'clipboard' | 'shift-insert' | 'type-chars'
|
|
78
80
|
let endSilenceMs = 5000;
|
|
79
81
|
let initialSilenceMs = 500;
|
|
@@ -691,16 +693,25 @@ function onKeyUp(e) {
|
|
|
691
693
|
function startDictation() {
|
|
692
694
|
if (state !== 'idle')
|
|
693
695
|
return;
|
|
694
|
-
//
|
|
695
|
-
|
|
696
|
-
|
|
696
|
+
// Authentication is only required for cloud STT. Sherpa (sherpa-onnx) and
|
|
697
|
+
// native engines (macOS Speech / Windows WinRT) run entirely on-device. The
|
|
698
|
+
// 'auto' engine falls back to local engines when not signed in, so we let it
|
|
699
|
+
// through too — the router surfaces a clear error if no engine is available.
|
|
700
|
+
// Realtime mode (Azure Speech) always requires sign-in because the Azure key
|
|
701
|
+
// is fetched from the backend.
|
|
702
|
+
const cloudRequired = transcriptionMode === 'realtime' || sttEngine === 'cloud';
|
|
703
|
+
if (cloudRequired && !(0, auth_1.isAuthenticated)()) {
|
|
704
|
+
logger_1.default.info(`[Dictation] Blocked — user not signed in (engine=${sttEngine}, mode=${transcriptionMode})`);
|
|
697
705
|
if (indicatorWindow && !indicatorWindow.isDestroyed()) {
|
|
698
706
|
indicatorWindow.showInactive();
|
|
699
|
-
|
|
707
|
+
const msg = sttEngine === 'cloud'
|
|
708
|
+
? 'Cloud transcription requires sign-in. Switch to native or sherpa engine in Settings → Dictation for offline dictation.'
|
|
709
|
+
: 'Please sign in for real-time dictation, or set Settings → Dictation → STT engine to native or sherpa for offline.';
|
|
710
|
+
indicatorWindow.webContents.send('dictation:error-message', msg);
|
|
700
711
|
setTimeout(() => {
|
|
701
712
|
if (indicatorWindow && !indicatorWindow.isDestroyed())
|
|
702
713
|
indicatorWindow.hide();
|
|
703
|
-
},
|
|
714
|
+
}, 3000);
|
|
704
715
|
}
|
|
705
716
|
return;
|
|
706
717
|
}
|
|
@@ -993,10 +1004,23 @@ async function handleAudioReady(audioBase64) {
|
|
|
993
1004
|
}
|
|
994
1005
|
try {
|
|
995
1006
|
const t0 = Date.now();
|
|
996
|
-
logger_1.default.info('[Dictation] Transcribing audio...', language ? `language: ${language}` : 'auto-detect');
|
|
997
|
-
|
|
1007
|
+
logger_1.default.info('[Dictation] Transcribing audio...', language ? `language: ${language}` : 'auto-detect', `engine=${sttEngine}`);
|
|
1008
|
+
const routeResult = await (0, router_1.route)({
|
|
1009
|
+
engine: sttEngine,
|
|
1010
|
+
audioBase64,
|
|
1011
|
+
language: language || undefined,
|
|
1012
|
+
source: 'dictation',
|
|
1013
|
+
phraseList: (0, database_1.getDictionaryWordList)?.() ?? undefined,
|
|
1014
|
+
});
|
|
1015
|
+
if (!routeResult.ok) {
|
|
1016
|
+
// Surface the structured router error so the catch block below maps it
|
|
1017
|
+
// to a user-friendly indicator message. The router's `message` already
|
|
1018
|
+
// names the failed engine and provides remediation hints.
|
|
1019
|
+
throw new Error(routeResult.message ?? `Transcription failed (${routeResult.error})`);
|
|
1020
|
+
}
|
|
1021
|
+
let transcript = routeResult.text;
|
|
998
1022
|
const t1 = Date.now();
|
|
999
|
-
logger_1.default.info(`[Dictation]
|
|
1023
|
+
logger_1.default.info(`[Dictation] ${routeResult.engine} completed in ${t1 - t0}ms (router-reported ${routeResult.latencyMs}ms)`);
|
|
1000
1024
|
// Post-process: technical terms + remove fillers + normalize short phrases
|
|
1001
1025
|
transcript = normalizeTechnicalTerms(transcript);
|
|
1002
1026
|
transcript = removeFillerWords(transcript);
|
|
@@ -1055,6 +1079,23 @@ async function handleAudioReady(audioBase64) {
|
|
|
1055
1079
|
if (errMsg.includes('Daily AI limit')) {
|
|
1056
1080
|
displayMsg = 'Daily AI limit reached. Upgrade to Pro for unlimited access.';
|
|
1057
1081
|
}
|
|
1082
|
+
else if (errMsg.includes('No speech-to-text engine is available')) {
|
|
1083
|
+
// Router's structured "all engines unavailable" message — give the
|
|
1084
|
+
// shortest actionable path. Full diagnostic is in the log.
|
|
1085
|
+
displayMsg = 'No STT engine. Sign in (Settings) or run: superbased stt download zipformer-en-20M';
|
|
1086
|
+
}
|
|
1087
|
+
else if (errMsg.includes('Cloud transcription requires sign-in')) {
|
|
1088
|
+
displayMsg = 'Cloud transcription needs sign-in. Switch engine to "auto" or "sherpa" in Settings → Dictation.';
|
|
1089
|
+
}
|
|
1090
|
+
else if (errMsg.includes('model not downloaded') || errMsg.includes('model_required')) {
|
|
1091
|
+
displayMsg = 'Sherpa model not downloaded. Run: superbased stt download zipformer-en-20M';
|
|
1092
|
+
}
|
|
1093
|
+
else if (errMsg.includes('binary_not_installed') || errMsg.includes('macos-speech is not installed')) {
|
|
1094
|
+
displayMsg = 'Native STT engine not installed. Reinstall with: npm install -g superbased --include=optional';
|
|
1095
|
+
}
|
|
1096
|
+
else if (errMsg.includes('Speech Recognition permission')) {
|
|
1097
|
+
displayMsg = 'Grant Speech Recognition in System Settings → Privacy & Security.';
|
|
1098
|
+
}
|
|
1058
1099
|
else if (errMsg.includes('session has expired') || errMsg.includes('sign in')) {
|
|
1059
1100
|
displayMsg = 'Session expired. Please sign in again.';
|
|
1060
1101
|
}
|
|
@@ -1093,6 +1134,8 @@ async function initializeDictation(window) {
|
|
|
1093
1134
|
maxDurationSeconds = (storedDuration !== undefined && storedDuration !== 30) ? storedDuration : 120;
|
|
1094
1135
|
excludedApps = (0, store_1.getSetting)('dictationSettings.excludedApps') || [];
|
|
1095
1136
|
language = (0, store_1.getSetting)('dictationSettings.language') || '';
|
|
1137
|
+
const storedEngine = (0, store_1.getSetting)('dictationSettings.engine');
|
|
1138
|
+
sttEngine = (storedEngine === 'cloud' || storedEngine === 'native' || storedEngine === 'sherpa') ? storedEngine : 'auto';
|
|
1096
1139
|
pasteMethod = (0, store_1.getSetting)('dictationSettings.pasteMethod') || 'clipboard';
|
|
1097
1140
|
endSilenceMs = (0, store_1.getSetting)('dictationSettings.endSilenceMs') || 5000;
|
|
1098
1141
|
initialSilenceMs = (0, store_1.getSetting)('dictationSettings.initialSilenceMs') ?? 500;
|
|
@@ -9,11 +9,16 @@
|
|
|
9
9
|
// Permission model (Speech framework):
|
|
10
10
|
// - `authorizationStatus()` — sync, does not prompt.
|
|
11
11
|
// - `requestAuthorization()` — async, prompts on first call.
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
12
|
+
//
|
|
13
|
+
// We auto-prompt on first dictate when status is exactly `notDetermined`.
|
|
14
|
+
// The original design deferred prompting to a separate setup wizard, but
|
|
15
|
+
// in practice users hit the dictation hotkey and got "permission
|
|
16
|
+
// notDetermined" forever because nothing else was triggering the prompt —
|
|
17
|
+
// the app never even appeared in System Settings → Privacy & Security →
|
|
18
|
+
// Speech Recognition (macOS only lists apps that have asked at least
|
|
19
|
+
// once). Auto-prompting is gated to a single attempt per session via
|
|
20
|
+
// `permissionPromptAttempted` so a denied user doesn't see the prompt
|
|
21
|
+
// flicker on every keystroke.
|
|
17
22
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
23
|
if (k2 === undefined) k2 = k;
|
|
19
24
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -119,6 +124,11 @@ function recognitionFailedError(detail) {
|
|
|
119
124
|
hint: 'Retry with engine="sherpa" or engine="cloud".',
|
|
120
125
|
};
|
|
121
126
|
}
|
|
127
|
+
// Module-scoped flag: only auto-prompt once per process. After the user
|
|
128
|
+
// answers the OS dialog (allow OR deny), authorizationStatus() returns the
|
|
129
|
+
// chosen state forever — re-prompting is a no-op per Apple's API contract,
|
|
130
|
+
// but we still gate it to make the code path's intent explicit.
|
|
131
|
+
let permissionPromptAttempted = false;
|
|
122
132
|
class MacosSpeechEngine {
|
|
123
133
|
name = 'native-macos';
|
|
124
134
|
async checkAvailability() {
|
|
@@ -136,7 +146,25 @@ class MacosSpeechEngine {
|
|
|
136
146
|
return binaryNotInstalledError();
|
|
137
147
|
return binaryLoadFailedError(binding.error);
|
|
138
148
|
}
|
|
139
|
-
|
|
149
|
+
let status = binding.module.authorizationStatus();
|
|
150
|
+
// First-time-on-this-machine path: trigger the OS prompt so the app
|
|
151
|
+
// shows up in System Settings → Privacy & Security → Speech Recognition
|
|
152
|
+
// and the user can grant. Without this call, macOS never displays the
|
|
153
|
+
// prompt and the user is stuck reading "permission notDetermined" with
|
|
154
|
+
// no actionable lever.
|
|
155
|
+
if (status === 'notDetermined' && !permissionPromptAttempted) {
|
|
156
|
+
permissionPromptAttempted = true;
|
|
157
|
+
try {
|
|
158
|
+
logger_1.default.info('[stt.macos] permission notDetermined — calling requestAuthorization to trigger OS prompt');
|
|
159
|
+
status = await binding.module.requestAuthorization();
|
|
160
|
+
logger_1.default.info(`[stt.macos] requestAuthorization resolved → ${status}`);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
logger_1.default.error('[stt.macos] requestAuthorization threw:', err);
|
|
164
|
+
// Fall through; status is still 'notDetermined' which produces a
|
|
165
|
+
// permissionRequiredError below — better than crashing.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
140
168
|
if (status !== 'authorized')
|
|
141
169
|
return permissionRequiredError(status);
|
|
142
170
|
return { ok: true };
|
|
@@ -39,13 +39,44 @@ function notSignedInError() {
|
|
|
39
39
|
hint: 'Run `superbased_stt_status` to see which engines are available.',
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
function noEngineAvailableError(
|
|
42
|
+
function noEngineAvailableError(report) {
|
|
43
|
+
// Build a per-engine reason map so the user sees exactly what's missing
|
|
44
|
+
// instead of a generic "Tried: cloud, sherpa". Each line names the engine,
|
|
45
|
+
// its current state, and the specific remediation step.
|
|
46
|
+
const lines = [];
|
|
47
|
+
lines.push(` • cloud: ${report.cloud.signedIn ? 'signed in (unexpected — should have routed here)' : 'not signed in. Run `superbased auth login`.'}`);
|
|
48
|
+
const sherpaParts = [];
|
|
49
|
+
if (!report.sherpa.binaryInstalled) {
|
|
50
|
+
sherpaParts.push(`sherpa-onnx-node binary not installed${report.sherpa.binaryError ? ` (${report.sherpa.binaryError})` : ''}`);
|
|
51
|
+
}
|
|
52
|
+
if (!report.sherpa.modelDownloaded) {
|
|
53
|
+
sherpaParts.push('model not downloaded — run `superbased stt download zipformer-en-20M`');
|
|
54
|
+
}
|
|
55
|
+
if (sherpaParts.length === 0) {
|
|
56
|
+
sherpaParts.push('available (unexpected — should have routed here)');
|
|
57
|
+
}
|
|
58
|
+
lines.push(` • sherpa: ${sherpaParts.join('; ')}`);
|
|
59
|
+
const nativeName = report.native.platform === 'darwin' ? 'native-macos' : report.native.platform === 'win32' ? 'native-windows' : 'native';
|
|
60
|
+
if (report.native.available) {
|
|
61
|
+
lines.push(` • ${nativeName}: available (unexpected — should have routed here)`);
|
|
62
|
+
}
|
|
63
|
+
else if (report.native.platform === 'darwin' || report.native.platform === 'win32') {
|
|
64
|
+
const reason = report.native.bindingLoaded === false
|
|
65
|
+
? `binding not loaded${report.native.bindingError ? ` (${report.native.bindingError})` : ''}`
|
|
66
|
+
: report.native.permissionStatus && report.native.permissionStatus !== 'authorized'
|
|
67
|
+
? `permission ${report.native.permissionStatus} — grant via System Settings → Privacy & Security → Speech Recognition`
|
|
68
|
+
: (report.native.reason ?? 'unavailable');
|
|
69
|
+
lines.push(` • ${nativeName}: ${reason}`);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
lines.push(` • native: not supported on platform=${report.native.platform}`);
|
|
73
|
+
}
|
|
43
74
|
return {
|
|
44
75
|
ok: false,
|
|
45
76
|
error: 'unavailable',
|
|
46
|
-
engine:
|
|
47
|
-
message: `No speech-to-text engine is available
|
|
48
|
-
hint: 'Run `superbased_stt_status` for
|
|
77
|
+
engine: 'sherpa',
|
|
78
|
+
message: `No speech-to-text engine is available.\n${lines.join('\n')}\n\nFastest fix: run \`superbased auth login\` to use cloud transcription.`,
|
|
79
|
+
hint: 'Run `superbased_stt_status` (MCP) or `superbased doctor` (CLI) for the full capability report.',
|
|
49
80
|
};
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
@@ -196,7 +227,7 @@ async function route(opts) {
|
|
|
196
227
|
if (requested === 'auto') {
|
|
197
228
|
const chosen = resolveAutoEngine(report);
|
|
198
229
|
if (chosen === null) {
|
|
199
|
-
return noEngineAvailableError(
|
|
230
|
+
return noEngineAvailableError(report);
|
|
200
231
|
}
|
|
201
232
|
logger_1.default.info(`[stt.router] auto → ${chosen}`);
|
|
202
233
|
if (chosen === 'cloud')
|
package/mcp-server/dist/index.js
CHANGED
|
@@ -243,6 +243,48 @@ function nextStepsForDictate(cleanup, hadText) {
|
|
|
243
243
|
* Shared between stdio transport (CLI) and HTTP transport (API server).
|
|
244
244
|
*/
|
|
245
245
|
function registerMcpTools(server, client, projectDir) {
|
|
246
|
+
// Compatibility shim for MCP clients that reject `{ type: 'image' }` content
|
|
247
|
+
// blocks despite the MCP spec accepting them. Observed concrete failure:
|
|
248
|
+
// OpenCode's MCP client validates each block with a Zod schema that only
|
|
249
|
+
// permits `type: 'text'`, surfacing as `-32602 Invalid params: expected
|
|
250
|
+
// "text"` on every tool that returns a screenshot (workspace_sync, ui_dump,
|
|
251
|
+
// capture_image, scroll_capture, …).
|
|
252
|
+
// When SUPERBASED_MCP_TEXT_ONLY=1 is set on the bridge process (configurable
|
|
253
|
+
// per-client in the MCP server's `env` block), we transparently filter image
|
|
254
|
+
// content blocks out of every tool response before they reach the transport.
|
|
255
|
+
// The text block is kept — agents still see the metadata + base64 byte count;
|
|
256
|
+
// they just lose direct vision-model handoff. Non-strict clients (Claude
|
|
257
|
+
// Code, Cursor, Windsurf, Codex) leave the var unset and keep getting the
|
|
258
|
+
// image blocks they asked for.
|
|
259
|
+
const stripImageBlocks = process.env.SUPERBASED_MCP_TEXT_ONLY === '1';
|
|
260
|
+
if (stripImageBlocks) {
|
|
261
|
+
const origTool = server.tool.bind(server);
|
|
262
|
+
server.tool = (...toolArgs) => {
|
|
263
|
+
// server.tool's last positional arg is always the handler callback.
|
|
264
|
+
const handler = toolArgs[toolArgs.length - 1];
|
|
265
|
+
if (typeof handler === 'function') {
|
|
266
|
+
const wrapped = async (...handlerArgs) => {
|
|
267
|
+
const result = await handler(...handlerArgs);
|
|
268
|
+
if (result && typeof result === 'object' && 'content' in result) {
|
|
269
|
+
const r = result;
|
|
270
|
+
if (Array.isArray(r.content)) {
|
|
271
|
+
r.content = r.content.filter((b) => {
|
|
272
|
+
return !(b && typeof b === 'object' && b.type === 'image');
|
|
273
|
+
});
|
|
274
|
+
// MCP spec allows empty content, but some clients reject zero-
|
|
275
|
+
// length arrays. Guarantee at least one block.
|
|
276
|
+
if (r.content.length === 0) {
|
|
277
|
+
r.content.push({ type: 'text', text: '(image content stripped — SUPERBASED_MCP_TEXT_ONLY=1)' });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return result;
|
|
282
|
+
};
|
|
283
|
+
toolArgs[toolArgs.length - 1] = wrapped;
|
|
284
|
+
}
|
|
285
|
+
return origTool(...toolArgs);
|
|
286
|
+
};
|
|
287
|
+
}
|
|
246
288
|
// Monitor alert poller state
|
|
247
289
|
let monitorPoller = null;
|
|
248
290
|
let monitorSessionId = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superbased",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"main": "dist/electron/main.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"superbased": "./dist/headless/headless/cli.js"
|
|
@@ -142,10 +142,10 @@
|
|
|
142
142
|
},
|
|
143
143
|
"optionalDependencies": {
|
|
144
144
|
"sherpa-onnx-node": "^1.10.0",
|
|
145
|
-
"@superbased/macos-speech": "
|
|
146
|
-
"@superbased/winrt-speech": "
|
|
147
|
-
"@superbased/macos-ax": "
|
|
148
|
-
"@superbased/win-uia": "
|
|
145
|
+
"@superbased/macos-speech": "0.1.0",
|
|
146
|
+
"@superbased/winrt-speech": "0.1.0",
|
|
147
|
+
"@superbased/macos-ax": "0.1.0",
|
|
148
|
+
"@superbased/win-uia": "0.1.0"
|
|
149
149
|
},
|
|
150
150
|
"overrides": {
|
|
151
151
|
"tar": ">=7.5.11"
|