superbased 1.4.0
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/LICENSE +31 -0
- package/README.md +84 -0
- package/SUPERBASED_SKILL.md +358 -0
- package/dist/electron/ai/ai-client.d.ts +45 -0
- package/dist/electron/ai/ai-client.d.ts.map +1 -0
- package/dist/electron/ai/ai-client.js +205 -0
- package/dist/electron/ai/ai-client.js.map +1 -0
- package/dist/electron/ai/context-builder.d.ts +8 -0
- package/dist/electron/ai/context-builder.d.ts.map +1 -0
- package/dist/electron/ai/context-builder.js +28 -0
- package/dist/electron/ai/context-builder.js.map +1 -0
- package/dist/electron/ai/instruction-parser.d.ts +11 -0
- package/dist/electron/ai/instruction-parser.d.ts.map +1 -0
- package/dist/electron/ai/instruction-parser.js +47 -0
- package/dist/electron/ai/instruction-parser.js.map +1 -0
- package/dist/electron/ai/orchestrator.d.ts +17 -0
- package/dist/electron/ai/orchestrator.d.ts.map +1 -0
- package/dist/electron/ai/orchestrator.js +53 -0
- package/dist/electron/ai/orchestrator.js.map +1 -0
- package/dist/electron/ai/providers/anthropic.d.ts +6 -0
- package/dist/electron/ai/providers/anthropic.d.ts.map +1 -0
- package/dist/electron/ai/providers/anthropic.js +67 -0
- package/dist/electron/ai/providers/anthropic.js.map +1 -0
- package/dist/electron/ai/providers/azure-openai.d.ts +12 -0
- package/dist/electron/ai/providers/azure-openai.d.ts.map +1 -0
- package/dist/electron/ai/providers/azure-openai.js +87 -0
- package/dist/electron/ai/providers/azure-openai.js.map +1 -0
- package/dist/electron/ai/providers/gemini.d.ts +6 -0
- package/dist/electron/ai/providers/gemini.d.ts.map +1 -0
- package/dist/electron/ai/providers/gemini.js +49 -0
- package/dist/electron/ai/providers/gemini.js.map +1 -0
- package/dist/electron/ai/providers/openai.d.ts +6 -0
- package/dist/electron/ai/providers/openai.d.ts.map +1 -0
- package/dist/electron/ai/providers/openai.js +68 -0
- package/dist/electron/ai/providers/openai.js.map +1 -0
- package/dist/electron/core/auth-store.d.ts +15 -0
- package/dist/electron/core/auth-store.d.ts.map +1 -0
- package/dist/electron/core/auth-store.js +86 -0
- package/dist/electron/core/auth-store.js.map +1 -0
- package/dist/electron/core/config.d.ts +6 -0
- package/dist/electron/core/config.d.ts.map +1 -0
- package/dist/electron/core/config.js +81 -0
- package/dist/electron/core/config.js.map +1 -0
- package/dist/electron/core/file-logger.d.ts +17 -0
- package/dist/electron/core/file-logger.d.ts.map +1 -0
- package/dist/electron/core/file-logger.js +74 -0
- package/dist/electron/core/file-logger.js.map +1 -0
- package/dist/electron/core/json-store.d.ts +4 -0
- package/dist/electron/core/json-store.d.ts.map +1 -0
- package/dist/electron/core/json-store.js +118 -0
- package/dist/electron/core/json-store.js.map +1 -0
- package/dist/electron/core/paths.d.ts +17 -0
- package/dist/electron/core/paths.d.ts.map +1 -0
- package/dist/electron/core/paths.js +117 -0
- package/dist/electron/core/paths.js.map +1 -0
- package/dist/electron/core/platform.d.ts +21 -0
- package/dist/electron/core/platform.d.ts.map +1 -0
- package/dist/electron/core/platform.js +18 -0
- package/dist/electron/core/platform.js.map +1 -0
- package/dist/electron/core/process-coord.d.ts +19 -0
- package/dist/electron/core/process-coord.d.ts.map +1 -0
- package/dist/electron/core/process-coord.js +124 -0
- package/dist/electron/core/process-coord.js.map +1 -0
- package/dist/electron/db/database.d.ts +154 -0
- package/dist/electron/db/database.d.ts.map +1 -0
- package/dist/electron/db/database.js +637 -0
- package/dist/electron/db/database.js.map +1 -0
- package/dist/electron/db/models.d.ts +26 -0
- package/dist/electron/db/models.d.ts.map +1 -0
- package/dist/electron/db/models.js +4 -0
- package/dist/electron/db/models.js.map +1 -0
- package/dist/electron/logger.d.ts +9 -0
- package/dist/electron/logger.d.ts.map +1 -0
- package/dist/electron/logger.js +18 -0
- package/dist/electron/logger.js.map +1 -0
- package/dist/electron/main.js +3286 -0
- package/dist/electron/modules/active-window.d.ts +6 -0
- package/dist/electron/modules/active-window.d.ts.map +1 -0
- package/dist/electron/modules/active-window.js +68 -0
- package/dist/electron/modules/active-window.js.map +1 -0
- package/dist/electron/modules/api-server.d.ts +8 -0
- package/dist/electron/modules/api-server.d.ts.map +1 -0
- package/dist/electron/modules/api-server.js +1324 -0
- package/dist/electron/modules/api-server.js.map +1 -0
- package/dist/electron/modules/auth.d.ts +28 -0
- package/dist/electron/modules/auth.d.ts.map +1 -0
- package/dist/electron/modules/auth.js +150 -0
- package/dist/electron/modules/auth.js.map +1 -0
- package/dist/electron/modules/azure-speech-realtime.d.ts +38 -0
- package/dist/electron/modules/azure-speech-realtime.d.ts.map +1 -0
- package/dist/electron/modules/azure-speech-realtime.js +354 -0
- package/dist/electron/modules/azure-speech-realtime.js.map +1 -0
- package/dist/electron/modules/capture-modes.d.ts +19 -0
- package/dist/electron/modules/capture-modes.d.ts.map +1 -0
- package/dist/electron/modules/capture-modes.js +100 -0
- package/dist/electron/modules/capture-modes.js.map +1 -0
- package/dist/electron/modules/capture.d.ts +16 -0
- package/dist/electron/modules/capture.d.ts.map +1 -0
- package/dist/electron/modules/capture.js +139 -0
- package/dist/electron/modules/capture.js.map +1 -0
- package/dist/electron/modules/clipboard.d.ts +6 -0
- package/dist/electron/modules/clipboard.d.ts.map +1 -0
- package/dist/electron/modules/clipboard.js +26 -0
- package/dist/electron/modules/clipboard.js.map +1 -0
- package/dist/electron/modules/color-picker.d.ts +4 -0
- package/dist/electron/modules/color-picker.d.ts.map +1 -0
- package/dist/electron/modules/color-picker.js +233 -0
- package/dist/electron/modules/color-picker.js.map +1 -0
- package/dist/electron/modules/dictation.d.ts +25 -0
- package/dist/electron/modules/dictation.d.ts.map +1 -0
- package/dist/electron/modules/dictation.js +1058 -0
- package/dist/electron/modules/dictation.js.map +1 -0
- package/dist/electron/modules/error-reporter.d.ts +7 -0
- package/dist/electron/modules/error-reporter.d.ts.map +1 -0
- package/dist/electron/modules/error-reporter.js +65 -0
- package/dist/electron/modules/error-reporter.js.map +1 -0
- package/dist/electron/modules/hotkeys.d.ts +4 -0
- package/dist/electron/modules/hotkeys.d.ts.map +1 -0
- package/dist/electron/modules/hotkeys.js +40 -0
- package/dist/electron/modules/hotkeys.js.map +1 -0
- package/dist/electron/modules/keystroke.d.ts +7 -0
- package/dist/electron/modules/keystroke.d.ts.map +1 -0
- package/dist/electron/modules/keystroke.js +53 -0
- package/dist/electron/modules/keystroke.js.map +1 -0
- package/dist/electron/modules/license.d.ts +25 -0
- package/dist/electron/modules/license.d.ts.map +1 -0
- package/dist/electron/modules/license.js +175 -0
- package/dist/electron/modules/license.js.map +1 -0
- package/dist/electron/modules/mcp-config.d.ts +16 -0
- package/dist/electron/modules/mcp-config.d.ts.map +1 -0
- package/dist/electron/modules/mcp-config.js +146 -0
- package/dist/electron/modules/mcp-config.js.map +1 -0
- package/dist/electron/modules/ocr.d.ts +3 -0
- package/dist/electron/modules/ocr.d.ts.map +1 -0
- package/dist/electron/modules/ocr.js +176 -0
- package/dist/electron/modules/ocr.js.map +1 -0
- package/dist/electron/modules/pin-window.d.ts +3 -0
- package/dist/electron/modules/pin-window.d.ts.map +1 -0
- package/dist/electron/modules/pin-window.js +63 -0
- package/dist/electron/modules/pin-window.js.map +1 -0
- package/dist/electron/modules/recording/ai-analysis.d.ts +8 -0
- package/dist/electron/modules/recording/ai-analysis.d.ts.map +1 -0
- package/dist/electron/modules/recording/ai-analysis.js +88 -0
- package/dist/electron/modules/recording/ai-analysis.js.map +1 -0
- package/dist/electron/modules/recording/capture-queue.d.ts +48 -0
- package/dist/electron/modules/recording/capture-queue.d.ts.map +1 -0
- package/dist/electron/modules/recording/capture-queue.js +376 -0
- package/dist/electron/modules/recording/capture-queue.js.map +1 -0
- package/dist/electron/modules/recording/cli.d.ts +13 -0
- package/dist/electron/modules/recording/cli.d.ts.map +1 -0
- package/dist/electron/modules/recording/cli.js +135 -0
- package/dist/electron/modules/recording/cli.js.map +1 -0
- package/dist/electron/modules/recording/http-api.d.ts +3 -0
- package/dist/electron/modules/recording/http-api.d.ts.map +1 -0
- package/dist/electron/modules/recording/http-api.js +236 -0
- package/dist/electron/modules/recording/http-api.js.map +1 -0
- package/dist/electron/modules/recording/index.d.ts +15 -0
- package/dist/electron/modules/recording/index.d.ts.map +1 -0
- package/dist/electron/modules/recording/index.js +148 -0
- package/dist/electron/modules/recording/index.js.map +1 -0
- package/dist/electron/modules/recording/input-hook-provider.d.ts +15 -0
- package/dist/electron/modules/recording/input-hook-provider.d.ts.map +1 -0
- package/dist/electron/modules/recording/input-hook-provider.js +5 -0
- package/dist/electron/modules/recording/input-hook-provider.js.map +1 -0
- package/dist/electron/modules/recording/mcp-tool.d.ts +13 -0
- package/dist/electron/modules/recording/mcp-tool.d.ts.map +1 -0
- package/dist/electron/modules/recording/mcp-tool.js +81 -0
- package/dist/electron/modules/recording/mcp-tool.js.map +1 -0
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts +15 -0
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts.map +1 -0
- package/dist/electron/modules/recording/providers/periodic-provider.js +55 -0
- package/dist/electron/modules/recording/providers/periodic-provider.js.map +1 -0
- package/dist/electron/modules/recording/providers/provider-factory.d.ts +9 -0
- package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +1 -0
- package/dist/electron/modules/recording/providers/provider-factory.js +70 -0
- package/dist/electron/modules/recording/providers/provider-factory.js.map +1 -0
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts +19 -0
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts.map +1 -0
- package/dist/electron/modules/recording/providers/uiohook-provider.js +263 -0
- package/dist/electron/modules/recording/providers/uiohook-provider.js.map +1 -0
- package/dist/electron/modules/recording/recording-session.d.ts +25 -0
- package/dist/electron/modules/recording/recording-session.d.ts.map +1 -0
- package/dist/electron/modules/recording/recording-session.js +317 -0
- package/dist/electron/modules/recording/recording-session.js.map +1 -0
- package/dist/electron/modules/recording/session-alignment.d.ts +32 -0
- package/dist/electron/modules/recording/session-alignment.d.ts.map +1 -0
- package/dist/electron/modules/recording/session-alignment.js +103 -0
- package/dist/electron/modules/recording/session-alignment.js.map +1 -0
- package/dist/electron/modules/recording/session-export.d.ts +2 -0
- package/dist/electron/modules/recording/session-export.d.ts.map +1 -0
- package/dist/electron/modules/recording/session-export.js +287 -0
- package/dist/electron/modules/recording/session-export.js.map +1 -0
- package/dist/electron/modules/recording/trigger-engine.d.ts +62 -0
- package/dist/electron/modules/recording/trigger-engine.d.ts.map +1 -0
- package/dist/electron/modules/recording/trigger-engine.js +546 -0
- package/dist/electron/modules/recording/trigger-engine.js.map +1 -0
- package/dist/electron/modules/recording/visual-diff.d.ts +17 -0
- package/dist/electron/modules/recording/visual-diff.d.ts.map +1 -0
- package/dist/electron/modules/recording/visual-diff.js +109 -0
- package/dist/electron/modules/recording/visual-diff.js.map +1 -0
- package/dist/electron/modules/redact.d.ts +34 -0
- package/dist/electron/modules/redact.d.ts.map +1 -0
- package/dist/electron/modules/redact.js +583 -0
- package/dist/electron/modules/redact.js.map +1 -0
- package/dist/electron/modules/scroll-capture.d.ts +19 -0
- package/dist/electron/modules/scroll-capture.d.ts.map +1 -0
- package/dist/electron/modules/scroll-capture.js +185 -0
- package/dist/electron/modules/scroll-capture.js.map +1 -0
- package/dist/electron/modules/store.d.ts +59 -0
- package/dist/electron/modules/store.d.ts.map +1 -0
- package/dist/electron/modules/store.js +100 -0
- package/dist/electron/modules/store.js.map +1 -0
- package/dist/electron/modules/tce/content-analyzer.d.ts +20 -0
- package/dist/electron/modules/tce/content-analyzer.d.ts.map +1 -0
- package/dist/electron/modules/tce/content-analyzer.js +123 -0
- package/dist/electron/modules/tce/content-analyzer.js.map +1 -0
- package/dist/electron/modules/tce/index.d.ts +54 -0
- package/dist/electron/modules/tce/index.d.ts.map +1 -0
- package/dist/electron/modules/tce/index.js +174 -0
- package/dist/electron/modules/tce/index.js.map +1 -0
- package/dist/electron/modules/tce/layout-engine.d.ts +68 -0
- package/dist/electron/modules/tce/layout-engine.d.ts.map +1 -0
- package/dist/electron/modules/tce/layout-engine.js +313 -0
- package/dist/electron/modules/tce/layout-engine.js.map +1 -0
- package/dist/electron/modules/tce/renderer.d.ts +16 -0
- package/dist/electron/modules/tce/renderer.d.ts.map +1 -0
- package/dist/electron/modules/tce/renderer.js +196 -0
- package/dist/electron/modules/tce/renderer.js.map +1 -0
- package/dist/electron/modules/tce/themes.d.ts +14 -0
- package/dist/electron/modules/tce/themes.d.ts.map +1 -0
- package/dist/electron/modules/tce/themes.js +68 -0
- package/dist/electron/modules/tce/themes.js.map +1 -0
- package/dist/electron/modules/tce/token-estimator.d.ts +30 -0
- package/dist/electron/modules/tce/token-estimator.d.ts.map +1 -0
- package/dist/electron/modules/tce/token-estimator.js +59 -0
- package/dist/electron/modules/tce/token-estimator.js.map +1 -0
- package/dist/electron/modules/telemetry.d.ts +44 -0
- package/dist/electron/modules/telemetry.d.ts.map +1 -0
- package/dist/electron/modules/telemetry.js +316 -0
- package/dist/electron/modules/telemetry.js.map +1 -0
- package/dist/electron/modules/tray.d.ts +22 -0
- package/dist/electron/modules/tray.d.ts.map +1 -0
- package/dist/electron/modules/tray.js +221 -0
- package/dist/electron/modules/tray.js.map +1 -0
- package/dist/electron/modules/updater.d.ts +14 -0
- package/dist/electron/modules/updater.d.ts.map +1 -0
- package/dist/electron/modules/updater.js +102 -0
- package/dist/electron/modules/updater.js.map +1 -0
- package/dist/electron/modules/usage-link.d.ts +7 -0
- package/dist/electron/modules/usage-link.d.ts.map +1 -0
- package/dist/electron/modules/usage-link.js +63 -0
- package/dist/electron/modules/usage-link.js.map +1 -0
- package/dist/electron/modules/version-check.d.ts +3 -0
- package/dist/electron/modules/version-check.d.ts.map +1 -0
- package/dist/electron/modules/version-check.js +76 -0
- package/dist/electron/modules/version-check.js.map +1 -0
- package/dist/electron/modules/window-picker.d.ts +6 -0
- package/dist/electron/modules/window-picker.d.ts.map +1 -0
- package/dist/electron/modules/window-picker.js +192 -0
- package/dist/electron/modules/window-picker.js.map +1 -0
- package/dist/headless/electron/ai/ai-client.js +204 -0
- package/dist/headless/electron/ai/context-builder.js +27 -0
- package/dist/headless/electron/ai/instruction-parser.js +46 -0
- package/dist/headless/electron/core/auth-store.js +85 -0
- package/dist/headless/electron/core/config.js +80 -0
- package/dist/headless/electron/core/file-logger.js +73 -0
- package/dist/headless/electron/core/json-store.js +117 -0
- package/dist/headless/electron/core/paths.js +116 -0
- package/dist/headless/electron/core/platform.js +17 -0
- package/dist/headless/electron/core/process-coord.js +123 -0
- package/dist/headless/electron/db/database.js +636 -0
- package/dist/headless/electron/db/models.js +3 -0
- package/dist/headless/electron/logger.js +17 -0
- package/dist/headless/electron/modules/active-window.js +67 -0
- package/dist/headless/electron/modules/api-server.js +1323 -0
- package/dist/headless/electron/modules/auth.js +149 -0
- package/dist/headless/electron/modules/azure-speech-realtime.js +353 -0
- package/dist/headless/electron/modules/capture.js +138 -0
- package/dist/headless/electron/modules/clipboard.js +25 -0
- package/dist/headless/electron/modules/dictation.js +1057 -0
- package/dist/headless/electron/modules/keystroke.js +52 -0
- package/dist/headless/electron/modules/license.js +174 -0
- package/dist/headless/electron/modules/mcp-config.js +145 -0
- package/dist/headless/electron/modules/ocr.js +175 -0
- package/dist/headless/electron/modules/recording/ai-analysis.js +87 -0
- package/dist/headless/electron/modules/recording/capture-queue.js +375 -0
- package/dist/headless/electron/modules/recording/cli.js +134 -0
- package/dist/headless/electron/modules/recording/http-api.js +235 -0
- package/dist/headless/electron/modules/recording/index.js +147 -0
- package/dist/headless/electron/modules/recording/input-hook-provider.js +4 -0
- package/dist/headless/electron/modules/recording/mcp-tool.js +80 -0
- package/dist/headless/electron/modules/recording/providers/periodic-provider.js +54 -0
- package/dist/headless/electron/modules/recording/providers/provider-factory.js +69 -0
- package/dist/headless/electron/modules/recording/providers/uiohook-provider.js +262 -0
- package/dist/headless/electron/modules/recording/recording-session.js +316 -0
- package/dist/headless/electron/modules/recording/session-alignment.js +102 -0
- package/dist/headless/electron/modules/recording/session-export.js +286 -0
- package/dist/headless/electron/modules/recording/trigger-engine.js +545 -0
- package/dist/headless/electron/modules/recording/visual-diff.js +108 -0
- package/dist/headless/electron/modules/redact.js +582 -0
- package/dist/headless/electron/modules/store.js +99 -0
- package/dist/headless/electron/modules/tce/content-analyzer.js +122 -0
- package/dist/headless/electron/modules/tce/index.js +173 -0
- package/dist/headless/electron/modules/tce/layout-engine.js +312 -0
- package/dist/headless/electron/modules/tce/renderer.js +195 -0
- package/dist/headless/electron/modules/tce/themes.js +67 -0
- package/dist/headless/electron/modules/tce/token-estimator.js +58 -0
- package/dist/headless/electron/modules/telemetry.js +315 -0
- package/dist/headless/headless/capture-hotkey.js +155 -0
- package/dist/headless/headless/cli-auth.js +158 -0
- package/dist/headless/headless/cli.js +220 -0
- package/dist/headless/headless/dictation-hotkey.js +360 -0
- package/dist/headless/headless/mic-capture.js +312 -0
- package/dist/headless/headless/platform-headless.js +121 -0
- package/dist/headless/headless/server.js +159 -0
- package/dist/headless/mic-capture.d.ts +29 -0
- package/dist/headless/mic-capture.d.ts.map +1 -0
- package/dist/headless/mic-capture.js +313 -0
- package/dist/headless/mic-capture.js.map +1 -0
- package/dist/headless/shared/constants.js +63 -0
- package/dist/headless/shared/design-tokens.js +189 -0
- package/dist/headless/shared/recording-types.js +93 -0
- package/dist/headless/shared/types.js +3 -0
- package/dist/shared/constants.d.ts +98 -0
- package/dist/shared/constants.d.ts.map +1 -0
- package/dist/shared/constants.js +64 -0
- package/dist/shared/constants.js.map +1 -0
- package/dist/shared/design-tokens.d.ts +112 -0
- package/dist/shared/design-tokens.d.ts.map +1 -0
- package/dist/shared/design-tokens.js +190 -0
- package/dist/shared/design-tokens.js.map +1 -0
- package/dist/shared/recording-types.d.ts +174 -0
- package/dist/shared/recording-types.d.ts.map +1 -0
- package/dist/shared/recording-types.js +94 -0
- package/dist/shared/recording-types.js.map +1 -0
- package/dist/shared/types.d.ts +135 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +4 -0
- package/dist/shared/types.js.map +1 -0
- package/mcp-server/dist/api-client.js +261 -0
- package/mcp-server/dist/index.js +824 -0
- package/mcp-server/package.json +16 -0
- package/package.json +125 -0
|
@@ -0,0 +1,1323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Always-on HTTP API server for MCP and external tool integration.
|
|
3
|
+
// Starts on app launch, binds to 127.0.0.1 only (localhost, no external access).
|
|
4
|
+
// Exposes capture, AI, gallery, settings, presets, and recording endpoints.
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.registerRecordingRoutesOnServer = registerRecordingRoutesOnServer;
|
|
43
|
+
exports.startApiServer = startApiServer;
|
|
44
|
+
exports.stopApiServer = stopApiServer;
|
|
45
|
+
exports.getApiAuthToken = getApiAuthToken;
|
|
46
|
+
exports.getApiServer = getApiServer;
|
|
47
|
+
exports.isApiServerRunning = isApiServerRunning;
|
|
48
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const platform_1 = require("../core/platform");
|
|
52
|
+
const config_1 = require("../core/config");
|
|
53
|
+
// Electron imports — used when running in desktop mode.
|
|
54
|
+
// Headless mode uses platform adapter instead.
|
|
55
|
+
let electronScreen = null;
|
|
56
|
+
try {
|
|
57
|
+
electronScreen = require('electron').screen;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Running headless — no Electron available
|
|
61
|
+
}
|
|
62
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
63
|
+
const capture_1 = require("./capture");
|
|
64
|
+
// captureFullScreen available via captureScreen() which handles all platforms
|
|
65
|
+
const active_window_1 = require("./active-window");
|
|
66
|
+
const ai_client_1 = require("../ai/ai-client");
|
|
67
|
+
const instruction_parser_1 = require("../ai/instruction-parser");
|
|
68
|
+
const context_builder_1 = require("../ai/context-builder");
|
|
69
|
+
const auth_1 = require("./auth");
|
|
70
|
+
const license_1 = require("./license");
|
|
71
|
+
const store_1 = require("./store");
|
|
72
|
+
const ocr_1 = require("./ocr");
|
|
73
|
+
const redact_1 = require("./redact");
|
|
74
|
+
const database_1 = require("../db/database");
|
|
75
|
+
const constants_1 = require("../../shared/constants");
|
|
76
|
+
const API_PORT = 47592;
|
|
77
|
+
const API_HOST = '127.0.0.1';
|
|
78
|
+
let server = null;
|
|
79
|
+
let startTime = Date.now();
|
|
80
|
+
// Auth token generated per launch for defense-in-depth
|
|
81
|
+
let authToken = null;
|
|
82
|
+
// Settings keys that must never be exposed or modified via API
|
|
83
|
+
const BLOCKED_SETTINGS_KEYS = ['apiKeys', 'encryptedApiKeys', 'onboardingComplete'];
|
|
84
|
+
// ── Helpers ──
|
|
85
|
+
function getCapturesDir(projectDir) {
|
|
86
|
+
if (projectDir) {
|
|
87
|
+
return path.join(projectDir, '.superbased', 'captures');
|
|
88
|
+
}
|
|
89
|
+
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
90
|
+
if (custom && fs.existsSync(custom))
|
|
91
|
+
return custom;
|
|
92
|
+
return path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
93
|
+
}
|
|
94
|
+
function ensureCapturesDir(projectDir) {
|
|
95
|
+
const dir = getCapturesDir(projectDir);
|
|
96
|
+
if (!fs.existsSync(dir)) {
|
|
97
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function isValidProjectDir(dir) {
|
|
101
|
+
// Must be absolute, no traversal
|
|
102
|
+
if (!path.isAbsolute(dir))
|
|
103
|
+
return false;
|
|
104
|
+
if (dir.includes('..'))
|
|
105
|
+
return false;
|
|
106
|
+
return fs.existsSync(dir) && fs.statSync(dir).isDirectory();
|
|
107
|
+
}
|
|
108
|
+
function sanitizeSettings(settings) {
|
|
109
|
+
const sanitized = { ...settings };
|
|
110
|
+
for (const key of BLOCKED_SETTINGS_KEYS) {
|
|
111
|
+
delete sanitized[key];
|
|
112
|
+
}
|
|
113
|
+
return sanitized;
|
|
114
|
+
}
|
|
115
|
+
function generateAuthToken() {
|
|
116
|
+
const { randomUUID } = require('crypto');
|
|
117
|
+
return randomUUID();
|
|
118
|
+
}
|
|
119
|
+
async function resizeImageForAI(imageBuffer) {
|
|
120
|
+
try {
|
|
121
|
+
const sharp = require('sharp');
|
|
122
|
+
const meta = await sharp(imageBuffer).metadata();
|
|
123
|
+
const maxDim = Math.max(meta.width || 0, meta.height || 0);
|
|
124
|
+
if (maxDim > 1568) {
|
|
125
|
+
const resized = await sharp(imageBuffer)
|
|
126
|
+
.resize({
|
|
127
|
+
width: maxDim === meta.width ? 1568 : undefined,
|
|
128
|
+
height: maxDim === meta.height ? 1568 : undefined,
|
|
129
|
+
fit: 'inside',
|
|
130
|
+
})
|
|
131
|
+
.png()
|
|
132
|
+
.toBuffer();
|
|
133
|
+
return resized.toString('base64');
|
|
134
|
+
}
|
|
135
|
+
return imageBuffer.toString('base64');
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return imageBuffer.toString('base64');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/** Resize a capture buffer to a target resolution for token efficiency. */
|
|
142
|
+
async function resizeCapture(buffer, resolution, maxWidth, maxHeight) {
|
|
143
|
+
const sharp = require('sharp');
|
|
144
|
+
const meta = await sharp(buffer).metadata();
|
|
145
|
+
const w = meta.width || 1920;
|
|
146
|
+
let targetW;
|
|
147
|
+
let targetH;
|
|
148
|
+
if (maxWidth || maxHeight) {
|
|
149
|
+
targetW = maxWidth;
|
|
150
|
+
targetH = maxHeight;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
switch (resolution) {
|
|
154
|
+
case 'high':
|
|
155
|
+
targetW = Math.min(w, 1568);
|
|
156
|
+
break;
|
|
157
|
+
case 'half':
|
|
158
|
+
targetW = Math.min(w, 960);
|
|
159
|
+
break;
|
|
160
|
+
case 'quarter':
|
|
161
|
+
targetW = Math.min(w, 480);
|
|
162
|
+
break;
|
|
163
|
+
case 'thumbnail':
|
|
164
|
+
targetW = Math.min(w, 200);
|
|
165
|
+
break;
|
|
166
|
+
default: return buffer; // 'full' or unspecified
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (targetW && targetW >= w && !targetH)
|
|
170
|
+
return buffer;
|
|
171
|
+
return sharp(buffer).resize({ width: targetW, height: targetH, fit: 'inside' }).png().toBuffer();
|
|
172
|
+
}
|
|
173
|
+
// ── Route Registration ──
|
|
174
|
+
function registerHealthRoutes(server) {
|
|
175
|
+
server.get('/api/health', async (_req, reply) => {
|
|
176
|
+
const version = (0, config_1.getVersion)();
|
|
177
|
+
return reply.code(200).send({
|
|
178
|
+
status: 'ok',
|
|
179
|
+
version,
|
|
180
|
+
uptime: Math.round((Date.now() - startTime) / 1000),
|
|
181
|
+
platform: process.platform,
|
|
182
|
+
features: {
|
|
183
|
+
capture: true,
|
|
184
|
+
ai: (0, auth_1.isAuthenticated)(),
|
|
185
|
+
gallery: true,
|
|
186
|
+
settings: true,
|
|
187
|
+
presets: true,
|
|
188
|
+
ocr: true,
|
|
189
|
+
recording: !!(0, store_1.getSetting)('recordingFeatureEnabled'),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function registerCaptureRoutes(server) {
|
|
195
|
+
// POST /api/capture/fullscreen
|
|
196
|
+
server.post('/api/capture/fullscreen', async (req, reply) => {
|
|
197
|
+
try {
|
|
198
|
+
const body = req.body || {};
|
|
199
|
+
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
200
|
+
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
201
|
+
}
|
|
202
|
+
const buffer = await (0, capture_1.captureScreen)();
|
|
203
|
+
// Auto-redact if enabled
|
|
204
|
+
let finalBuffer = buffer;
|
|
205
|
+
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
206
|
+
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
207
|
+
if (redactSecrets || redactPII) {
|
|
208
|
+
const result = await (0, redact_1.autoRedact)(finalBuffer, { secrets: redactSecrets, pii: redactPII });
|
|
209
|
+
finalBuffer = result.buffer;
|
|
210
|
+
}
|
|
211
|
+
ensureCapturesDir(body.projectDir);
|
|
212
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
213
|
+
const filename = `capture-${timestamp}.png`;
|
|
214
|
+
const capturesDir = getCapturesDir(body.projectDir);
|
|
215
|
+
const filepath = path.join(capturesDir, filename);
|
|
216
|
+
fs.writeFileSync(filepath, finalBuffer);
|
|
217
|
+
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
218
|
+
const { width, height } = primaryDisplay.size;
|
|
219
|
+
const captureId = (0, database_1.saveCapture)({
|
|
220
|
+
screenshotPath: filepath,
|
|
221
|
+
regionX: 0,
|
|
222
|
+
regionY: 0,
|
|
223
|
+
regionW: width,
|
|
224
|
+
regionH: height,
|
|
225
|
+
sourceApp: 'API',
|
|
226
|
+
windowTitle: 'Fullscreen Capture',
|
|
227
|
+
});
|
|
228
|
+
const imageBase64 = finalBuffer.toString('base64');
|
|
229
|
+
return reply.code(200).send({
|
|
230
|
+
captureId,
|
|
231
|
+
screenshotPath: filepath,
|
|
232
|
+
imageBase64,
|
|
233
|
+
width,
|
|
234
|
+
height,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
logger_1.default.error('[API] Fullscreen capture failed:', err);
|
|
239
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
// POST /api/capture/region
|
|
243
|
+
server.post('/api/capture/region', async (req, reply) => {
|
|
244
|
+
try {
|
|
245
|
+
const body = req.body || {};
|
|
246
|
+
if (body.x === undefined || body.y === undefined || body.width === undefined || body.height === undefined) {
|
|
247
|
+
return reply.code(400).send({ error: 'x, y, width, height are required' });
|
|
248
|
+
}
|
|
249
|
+
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
250
|
+
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
251
|
+
}
|
|
252
|
+
const region = { x: body.x, y: body.y, width: body.width, height: body.height };
|
|
253
|
+
const fullScreenBuffer = await (0, capture_1.captureScreen)();
|
|
254
|
+
let croppedBuffer = await (0, capture_1.cropRegion)(fullScreenBuffer, region);
|
|
255
|
+
// Auto-redact if enabled
|
|
256
|
+
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
257
|
+
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
258
|
+
if (redactSecrets || redactPII) {
|
|
259
|
+
const result = await (0, redact_1.autoRedact)(croppedBuffer, { secrets: redactSecrets, pii: redactPII });
|
|
260
|
+
croppedBuffer = result.buffer;
|
|
261
|
+
}
|
|
262
|
+
ensureCapturesDir(body.projectDir);
|
|
263
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
264
|
+
const filename = `capture-${timestamp}.png`;
|
|
265
|
+
const capturesDir = getCapturesDir(body.projectDir);
|
|
266
|
+
const filepath = path.join(capturesDir, filename);
|
|
267
|
+
fs.writeFileSync(filepath, croppedBuffer);
|
|
268
|
+
const captureId = (0, database_1.saveCapture)({
|
|
269
|
+
screenshotPath: filepath,
|
|
270
|
+
regionX: region.x,
|
|
271
|
+
regionY: region.y,
|
|
272
|
+
regionW: region.width,
|
|
273
|
+
regionH: region.height,
|
|
274
|
+
sourceApp: 'API',
|
|
275
|
+
windowTitle: 'Region Capture',
|
|
276
|
+
});
|
|
277
|
+
const imageBase64 = croppedBuffer.toString('base64');
|
|
278
|
+
return reply.code(200).send({
|
|
279
|
+
captureId,
|
|
280
|
+
screenshotPath: filepath,
|
|
281
|
+
imageBase64,
|
|
282
|
+
width: region.width,
|
|
283
|
+
height: region.height,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
logger_1.default.error('[API] Region capture failed:', err);
|
|
288
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
// POST /api/capture/active-window
|
|
292
|
+
server.post('/api/capture/active-window', async (_req, reply) => {
|
|
293
|
+
try {
|
|
294
|
+
const windowInfo = await (0, active_window_1.getActiveWindowInfo)();
|
|
295
|
+
const buffer = await (0, capture_1.captureScreen)();
|
|
296
|
+
return reply.code(200).send({
|
|
297
|
+
windowInfo,
|
|
298
|
+
imageBase64: buffer.toString('base64'),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
logger_1.default.error('[API] Active window capture failed:', err);
|
|
303
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
// POST /api/capture/ocr
|
|
307
|
+
server.post('/api/capture/ocr', async (req, reply) => {
|
|
308
|
+
try {
|
|
309
|
+
const body = req.body || {};
|
|
310
|
+
let imageBuffer;
|
|
311
|
+
if (body.imageBase64) {
|
|
312
|
+
imageBuffer = Buffer.from(body.imageBase64, 'base64');
|
|
313
|
+
}
|
|
314
|
+
else if (body.screenshotPath && fs.existsSync(body.screenshotPath)) {
|
|
315
|
+
imageBuffer = fs.readFileSync(body.screenshotPath);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return reply.code(400).send({ error: 'imageBase64 or screenshotPath required' });
|
|
319
|
+
}
|
|
320
|
+
const text = await (0, ocr_1.performOCR)(imageBuffer);
|
|
321
|
+
return reply.code(200).send({ text });
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
logger_1.default.error('[API] OCR failed:', err);
|
|
325
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function registerAIRoutes(server) {
|
|
330
|
+
// POST /api/ai/process
|
|
331
|
+
server.post('/api/ai/process', async (req, reply) => {
|
|
332
|
+
try {
|
|
333
|
+
const body = req.body || {};
|
|
334
|
+
if (!body.instruction) {
|
|
335
|
+
return reply.code(400).send({ error: 'instruction is required' });
|
|
336
|
+
}
|
|
337
|
+
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
338
|
+
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
339
|
+
}
|
|
340
|
+
// Require authentication for AI features
|
|
341
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
342
|
+
return reply.code(401).send({ error: 'Please sign in to use AI features.' });
|
|
343
|
+
}
|
|
344
|
+
// Get image(s)
|
|
345
|
+
const imagesBase64 = [];
|
|
346
|
+
let captureSourceApp = null;
|
|
347
|
+
let captureWindowTitle = null;
|
|
348
|
+
if (body.captureId) {
|
|
349
|
+
const capture = (0, database_1.getCapture)(body.captureId);
|
|
350
|
+
if (!capture || !capture.screenshot_path) {
|
|
351
|
+
return reply.code(404).send({ error: `Capture ${body.captureId} not found` });
|
|
352
|
+
}
|
|
353
|
+
if (fs.existsSync(capture.screenshot_path)) {
|
|
354
|
+
const buf = fs.readFileSync(capture.screenshot_path);
|
|
355
|
+
imagesBase64.push(await resizeImageForAI(buf));
|
|
356
|
+
captureSourceApp = capture.source_app || null;
|
|
357
|
+
captureWindowTitle = capture.window_title || null;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (body.imageBase64) {
|
|
361
|
+
imagesBase64.push(body.imageBase64);
|
|
362
|
+
}
|
|
363
|
+
else if (body.screenshotPath && fs.existsSync(body.screenshotPath)) {
|
|
364
|
+
const buf = fs.readFileSync(body.screenshotPath);
|
|
365
|
+
imagesBase64.push(await resizeImageForAI(buf));
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
// No image — capture fullscreen automatically
|
|
369
|
+
const buffer = await (0, capture_1.captureScreen)();
|
|
370
|
+
ensureCapturesDir(body.projectDir);
|
|
371
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
372
|
+
const filename = `capture-${timestamp}.png`;
|
|
373
|
+
const capturesDir = getCapturesDir(body.projectDir);
|
|
374
|
+
const filepath = path.join(capturesDir, filename);
|
|
375
|
+
fs.writeFileSync(filepath, buffer);
|
|
376
|
+
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
377
|
+
const { width, height } = primaryDisplay.size;
|
|
378
|
+
(0, database_1.saveCapture)({
|
|
379
|
+
screenshotPath: filepath,
|
|
380
|
+
regionX: 0,
|
|
381
|
+
regionY: 0,
|
|
382
|
+
regionW: width,
|
|
383
|
+
regionH: height,
|
|
384
|
+
sourceApp: 'API',
|
|
385
|
+
windowTitle: 'Auto Capture for AI',
|
|
386
|
+
});
|
|
387
|
+
imagesBase64.push(await resizeImageForAI(buffer));
|
|
388
|
+
}
|
|
389
|
+
// Parse instruction and build prompt
|
|
390
|
+
const { instruction } = (0, instruction_parser_1.parseInstruction)(body.instruction);
|
|
391
|
+
const systemPrompt = (0, store_1.getSetting)('systemPrompt') || '';
|
|
392
|
+
const contexts = imagesBase64.map((imageBase64, i) => ({
|
|
393
|
+
imageBase64,
|
|
394
|
+
sourceApp: captureSourceApp,
|
|
395
|
+
windowTitle: captureWindowTitle,
|
|
396
|
+
regionIndex: i,
|
|
397
|
+
}));
|
|
398
|
+
const fullPrompt = (systemPrompt ? systemPrompt + '\n\n' : '') + (0, context_builder_1.buildPrompt)(instruction, contexts);
|
|
399
|
+
// Stream AI via backend proxy and buffer complete response
|
|
400
|
+
let fullResponse = '';
|
|
401
|
+
for await (const chunk of (0, ai_client_1.streamAIFromBackend)({
|
|
402
|
+
imagesBase64,
|
|
403
|
+
instruction: fullPrompt,
|
|
404
|
+
})) {
|
|
405
|
+
fullResponse += chunk;
|
|
406
|
+
}
|
|
407
|
+
// Save AI response to capture if captureId provided
|
|
408
|
+
if (body.captureId) {
|
|
409
|
+
(0, database_1.updateCapture)(body.captureId, {
|
|
410
|
+
aiResponse: fullResponse,
|
|
411
|
+
instruction: body.instruction,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return reply.code(200).send({
|
|
415
|
+
response: fullResponse,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
logger_1.default.error('[API] AI process failed:', err);
|
|
420
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
// GET /api/ai/commands
|
|
424
|
+
server.get('/api/ai/commands', async (_req, reply) => {
|
|
425
|
+
const commands = (0, instruction_parser_1.getAvailableCommands)();
|
|
426
|
+
return reply.code(200).send({ commands });
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
function registerGalleryRoutes(server) {
|
|
430
|
+
// GET /api/gallery/captures
|
|
431
|
+
server.get('/api/gallery/captures', async (req, reply) => {
|
|
432
|
+
const query = req.query;
|
|
433
|
+
const limit = parseInt(query.limit || '50', 10);
|
|
434
|
+
const captures = (0, database_1.getCaptures)(limit);
|
|
435
|
+
return reply.code(200).send({ captures, total: captures.length });
|
|
436
|
+
});
|
|
437
|
+
// GET /api/gallery/captures/:id
|
|
438
|
+
server.get('/api/gallery/captures/:id', async (req, reply) => {
|
|
439
|
+
const params = req.params;
|
|
440
|
+
const id = parseInt(params.id, 10);
|
|
441
|
+
if (isNaN(id)) {
|
|
442
|
+
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
443
|
+
}
|
|
444
|
+
const capture = (0, database_1.getCapture)(id);
|
|
445
|
+
if (!capture) {
|
|
446
|
+
return reply.code(404).send({ error: 'Capture not found' });
|
|
447
|
+
}
|
|
448
|
+
return reply.code(200).send({ capture });
|
|
449
|
+
});
|
|
450
|
+
// GET /api/gallery/search
|
|
451
|
+
server.get('/api/gallery/search', async (req, reply) => {
|
|
452
|
+
const query = req.query;
|
|
453
|
+
if (!query.q) {
|
|
454
|
+
return reply.code(400).send({ error: 'q parameter required' });
|
|
455
|
+
}
|
|
456
|
+
const limit = parseInt(query.limit || '50', 10);
|
|
457
|
+
const captures = (0, database_1.searchCaptures)(query.q, limit);
|
|
458
|
+
return reply.code(200).send({ captures });
|
|
459
|
+
});
|
|
460
|
+
// GET /api/gallery/stats
|
|
461
|
+
server.get('/api/gallery/stats', async (_req, reply) => {
|
|
462
|
+
const stats = (0, database_1.getCaptureStats)();
|
|
463
|
+
return reply.code(200).send(stats);
|
|
464
|
+
});
|
|
465
|
+
// PUT /api/gallery/captures/:id/tags
|
|
466
|
+
server.put('/api/gallery/captures/:id/tags', async (req, reply) => {
|
|
467
|
+
const params = req.params;
|
|
468
|
+
const id = parseInt(params.id, 10);
|
|
469
|
+
if (isNaN(id)) {
|
|
470
|
+
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
471
|
+
}
|
|
472
|
+
const body = req.body || {};
|
|
473
|
+
if (body.tags === undefined) {
|
|
474
|
+
return reply.code(400).send({ error: 'tags field required' });
|
|
475
|
+
}
|
|
476
|
+
(0, database_1.updateCaptureTags)(id, body.tags);
|
|
477
|
+
return reply.code(200).send({ success: true });
|
|
478
|
+
});
|
|
479
|
+
// PUT /api/gallery/captures/:id/notes
|
|
480
|
+
server.put('/api/gallery/captures/:id/notes', async (req, reply) => {
|
|
481
|
+
const params = req.params;
|
|
482
|
+
const id = parseInt(params.id, 10);
|
|
483
|
+
if (isNaN(id)) {
|
|
484
|
+
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
485
|
+
}
|
|
486
|
+
const body = req.body || {};
|
|
487
|
+
if (body.notes === undefined) {
|
|
488
|
+
return reply.code(400).send({ error: 'notes field required' });
|
|
489
|
+
}
|
|
490
|
+
(0, database_1.updateCaptureNotes)(id, body.notes);
|
|
491
|
+
return reply.code(200).send({ success: true });
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function registerSettingsRoutes(server) {
|
|
495
|
+
// GET /api/settings
|
|
496
|
+
server.get('/api/settings', async (_req, reply) => {
|
|
497
|
+
const settings = (0, store_1.getAllSettings)();
|
|
498
|
+
const safe = sanitizeSettings(settings);
|
|
499
|
+
return reply.code(200).send({ settings: safe });
|
|
500
|
+
});
|
|
501
|
+
// PUT /api/settings
|
|
502
|
+
server.put('/api/settings', async (req, reply) => {
|
|
503
|
+
const body = req.body || {};
|
|
504
|
+
if (!body.key) {
|
|
505
|
+
return reply.code(400).send({ error: 'key is required' });
|
|
506
|
+
}
|
|
507
|
+
if (BLOCKED_SETTINGS_KEYS.includes(body.key)) {
|
|
508
|
+
return reply.code(403).send({ error: `Setting '${body.key}' cannot be modified via API` });
|
|
509
|
+
}
|
|
510
|
+
(0, store_1.setSetting)(body.key, body.value);
|
|
511
|
+
return reply.code(200).send({ success: true });
|
|
512
|
+
});
|
|
513
|
+
// GET /api/settings/provider
|
|
514
|
+
server.get('/api/settings/provider', async (_req, reply) => {
|
|
515
|
+
return reply.code(200).send({
|
|
516
|
+
provider: 'server-managed',
|
|
517
|
+
model: 'server-managed',
|
|
518
|
+
hasKey: (0, auth_1.isAuthenticated)(),
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function registerPresetsRoutes(server) {
|
|
523
|
+
// GET /api/presets
|
|
524
|
+
server.get('/api/presets', async (_req, reply) => {
|
|
525
|
+
const presets = (0, database_1.getPresets)();
|
|
526
|
+
return reply.code(200).send({ presets });
|
|
527
|
+
});
|
|
528
|
+
// POST /api/presets
|
|
529
|
+
server.post('/api/presets', async (req, reply) => {
|
|
530
|
+
const body = req.body || {};
|
|
531
|
+
if (!body.name || !body.instruction) {
|
|
532
|
+
return reply.code(400).send({ error: 'name and instruction are required' });
|
|
533
|
+
}
|
|
534
|
+
const id = (0, database_1.createPreset)({
|
|
535
|
+
name: body.name,
|
|
536
|
+
instruction: body.instruction,
|
|
537
|
+
shortcut: body.shortcut || null,
|
|
538
|
+
});
|
|
539
|
+
return reply.code(201).send({ id });
|
|
540
|
+
});
|
|
541
|
+
// PUT /api/presets/:id
|
|
542
|
+
server.put('/api/presets/:id', async (req, reply) => {
|
|
543
|
+
const params = req.params;
|
|
544
|
+
const id = parseInt(params.id, 10);
|
|
545
|
+
if (isNaN(id)) {
|
|
546
|
+
return reply.code(400).send({ error: 'Invalid preset ID' });
|
|
547
|
+
}
|
|
548
|
+
const body = req.body || {};
|
|
549
|
+
if (!body.name || !body.instruction) {
|
|
550
|
+
return reply.code(400).send({ error: 'name and instruction are required' });
|
|
551
|
+
}
|
|
552
|
+
(0, database_1.updatePreset)({
|
|
553
|
+
id,
|
|
554
|
+
name: body.name,
|
|
555
|
+
instruction: body.instruction,
|
|
556
|
+
shortcut: body.shortcut || null,
|
|
557
|
+
});
|
|
558
|
+
return reply.code(200).send({ success: true });
|
|
559
|
+
});
|
|
560
|
+
// DELETE /api/presets/:id
|
|
561
|
+
server.delete('/api/presets/:id', async (req, reply) => {
|
|
562
|
+
const params = req.params;
|
|
563
|
+
const id = parseInt(params.id, 10);
|
|
564
|
+
if (isNaN(id)) {
|
|
565
|
+
return reply.code(400).send({ error: 'Invalid preset ID' });
|
|
566
|
+
}
|
|
567
|
+
(0, database_1.deletePreset)(id);
|
|
568
|
+
return reply.code(200).send({ success: true });
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
// ── Token Compression Engine Routes ──
|
|
572
|
+
function registerCompressRoutes(server) {
|
|
573
|
+
server.post('/api/compress', async (req, reply) => {
|
|
574
|
+
try {
|
|
575
|
+
const body = (req.body || {});
|
|
576
|
+
if (!body.text) {
|
|
577
|
+
return reply.code(400).send({ error: 'Missing required field: text' });
|
|
578
|
+
}
|
|
579
|
+
const { compressText } = await Promise.resolve().then(() => __importStar(require('./tce')));
|
|
580
|
+
const settings = {};
|
|
581
|
+
if (body.preset)
|
|
582
|
+
settings.preset = body.preset;
|
|
583
|
+
if (body.columns)
|
|
584
|
+
settings.columnMode = body.columns === 'auto' ? 'auto' : Number(body.columns);
|
|
585
|
+
if (body.theme)
|
|
586
|
+
settings.theme = body.theme;
|
|
587
|
+
if (body.render_style)
|
|
588
|
+
settings.renderStyle = body.render_style;
|
|
589
|
+
if (body.overlap_lines !== undefined)
|
|
590
|
+
settings.overlapLines = body.overlap_lines;
|
|
591
|
+
const result = await compressText(body.text, settings);
|
|
592
|
+
return reply.code(200).send({
|
|
593
|
+
pages: result.pages.map((p) => ({
|
|
594
|
+
page_number: p.pageNumber,
|
|
595
|
+
total_pages: p.totalPages,
|
|
596
|
+
image_tokens: p.imageTokens,
|
|
597
|
+
line_range: p.lineRange,
|
|
598
|
+
data: p.buffer.toString('base64'),
|
|
599
|
+
})),
|
|
600
|
+
metadata: {
|
|
601
|
+
total_image_tokens: result.metadata.totalImageTokens,
|
|
602
|
+
estimated_text_tokens: result.metadata.estimatedTextTokens,
|
|
603
|
+
compression_ratio: result.metadata.compressionRatio,
|
|
604
|
+
savings_percent: result.metadata.savingsPercent,
|
|
605
|
+
columns_used: result.metadata.columnsUsed,
|
|
606
|
+
preset_used: result.metadata.presetUsed,
|
|
607
|
+
resolution: result.metadata.resolution,
|
|
608
|
+
content_type: result.metadata.contentType,
|
|
609
|
+
language: result.metadata.language,
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
catch (err) {
|
|
614
|
+
logger_1.default.error('[API] Compress failed:', err);
|
|
615
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
// ── Recording Routes (delegate to recording module if available) ──
|
|
620
|
+
let recordingRoutesRegistered = false;
|
|
621
|
+
function registerRecordingRoutesOnServer() {
|
|
622
|
+
if (!server || recordingRoutesRegistered)
|
|
623
|
+
return;
|
|
624
|
+
recordingRoutesRegistered = true;
|
|
625
|
+
// Lazy-import recording modules to avoid loading them at startup
|
|
626
|
+
const registerRoutes = async () => {
|
|
627
|
+
try {
|
|
628
|
+
const { getRecordingSessions, getSessionFrames } = await Promise.resolve().then(() => __importStar(require('../db/database')));
|
|
629
|
+
const { startSession, stopCurrentSession, pauseCurrentSession, resumeCurrentSession, getCurrentSession, triggerManualCapture, } = await Promise.resolve().then(() => __importStar(require('./recording/recording-session')));
|
|
630
|
+
const { alignSessions } = await Promise.resolve().then(() => __importStar(require('./recording/session-alignment')));
|
|
631
|
+
const { exportSession } = await Promise.resolve().then(() => __importStar(require('./recording/session-export')));
|
|
632
|
+
const s = server;
|
|
633
|
+
// POST /api/recording/start
|
|
634
|
+
s.post('/api/recording/start', async (request, reply) => {
|
|
635
|
+
try {
|
|
636
|
+
const body = request.body || {};
|
|
637
|
+
const options = {
|
|
638
|
+
name: body.name || `API Recording ${new Date().toLocaleString()}`,
|
|
639
|
+
profile: (body.profile || 'automated_test'),
|
|
640
|
+
scope: (body.scope || 'all'),
|
|
641
|
+
targetProcessName: body.targetProcessName,
|
|
642
|
+
targetWindowTitle: body.targetWindowTitle,
|
|
643
|
+
showInGallery: body.showInGallery !== false,
|
|
644
|
+
};
|
|
645
|
+
const session = await startSession(options);
|
|
646
|
+
return reply.code(200).send({ sessionId: session.id, status: 'recording' });
|
|
647
|
+
}
|
|
648
|
+
catch (err) {
|
|
649
|
+
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
// POST /api/recording/stop
|
|
653
|
+
s.post('/api/recording/stop', async (_request, reply) => {
|
|
654
|
+
try {
|
|
655
|
+
const session = await stopCurrentSession();
|
|
656
|
+
if (!session) {
|
|
657
|
+
return reply.code(400).send({ error: 'No active recording session' });
|
|
658
|
+
}
|
|
659
|
+
return reply.code(200).send({
|
|
660
|
+
sessionId: session.id,
|
|
661
|
+
status: 'completed',
|
|
662
|
+
frameCount: session.frameCount,
|
|
663
|
+
duration: Date.now() - session.startedAt,
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
catch (err) {
|
|
667
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
// POST /api/recording/pause
|
|
671
|
+
s.post('/api/recording/pause', async (_request, reply) => {
|
|
672
|
+
try {
|
|
673
|
+
await pauseCurrentSession();
|
|
674
|
+
return reply.code(200).send({ success: true });
|
|
675
|
+
}
|
|
676
|
+
catch (err) {
|
|
677
|
+
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
// POST /api/recording/resume
|
|
681
|
+
s.post('/api/recording/resume', async (_request, reply) => {
|
|
682
|
+
try {
|
|
683
|
+
await resumeCurrentSession();
|
|
684
|
+
return reply.code(200).send({ success: true });
|
|
685
|
+
}
|
|
686
|
+
catch (err) {
|
|
687
|
+
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
// GET /api/recording/status
|
|
691
|
+
s.get('/api/recording/status', async (_request, reply) => {
|
|
692
|
+
const session = getCurrentSession();
|
|
693
|
+
if (!session) {
|
|
694
|
+
return reply.code(200).send({ status: 'idle' });
|
|
695
|
+
}
|
|
696
|
+
return reply.code(200).send({
|
|
697
|
+
status: session.status === 'paused' ? 'paused' : 'recording',
|
|
698
|
+
sessionId: session.id,
|
|
699
|
+
frameCount: session.frameCount,
|
|
700
|
+
duration: Date.now() - session.startedAt,
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
// POST /api/recording/capture
|
|
704
|
+
s.post('/api/recording/capture', async (_request, reply) => {
|
|
705
|
+
const session = getCurrentSession();
|
|
706
|
+
if (!session) {
|
|
707
|
+
return reply.code(400).send({ error: 'No active recording session' });
|
|
708
|
+
}
|
|
709
|
+
triggerManualCapture();
|
|
710
|
+
return reply.code(200).send({ success: true, message: 'Manual capture triggered' });
|
|
711
|
+
});
|
|
712
|
+
// GET /api/sessions
|
|
713
|
+
s.get('/api/sessions', async (_request, reply) => {
|
|
714
|
+
const sessions = getRecordingSessions(100);
|
|
715
|
+
return reply.code(200).send({ sessions });
|
|
716
|
+
});
|
|
717
|
+
// GET /api/sessions/:id/frames
|
|
718
|
+
s.get('/api/sessions/:id/frames', async (request, reply) => {
|
|
719
|
+
const params = request.params;
|
|
720
|
+
const frames = getSessionFrames(params.id);
|
|
721
|
+
return reply.code(200).send({ sessionId: params.id, frames });
|
|
722
|
+
});
|
|
723
|
+
// POST /api/diff
|
|
724
|
+
s.post('/api/diff', async (request, reply) => {
|
|
725
|
+
try {
|
|
726
|
+
const body = request.body;
|
|
727
|
+
if (!body?.baselineSessionId || !body?.currentSessionId) {
|
|
728
|
+
return reply.code(400).send({ error: 'baselineSessionId and currentSessionId required' });
|
|
729
|
+
}
|
|
730
|
+
const baselineFrames = getSessionFrames(body.baselineSessionId);
|
|
731
|
+
const currentFrames = getSessionFrames(body.currentSessionId);
|
|
732
|
+
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
733
|
+
const baseDir = custom && fs.existsSync(custom) ? custom : path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
734
|
+
const diffDir = path.join(baseDir, 'sessions', `diff_${body.baselineSessionId}_${body.currentSessionId}`);
|
|
735
|
+
fs.mkdirSync(diffDir, { recursive: true });
|
|
736
|
+
const result = await alignSessions(baselineFrames, currentFrames, diffDir);
|
|
737
|
+
return reply.code(200).send(result);
|
|
738
|
+
}
|
|
739
|
+
catch (err) {
|
|
740
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
// POST /api/export
|
|
744
|
+
s.post('/api/export', async (request, reply) => {
|
|
745
|
+
try {
|
|
746
|
+
const body = request.body;
|
|
747
|
+
if (!body?.sessionId || !body?.format) {
|
|
748
|
+
return reply.code(400).send({ error: 'sessionId and format required' });
|
|
749
|
+
}
|
|
750
|
+
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
751
|
+
const baseDir = custom && fs.existsSync(custom) ? custom : path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
752
|
+
const outputPath = body.output || path.join(baseDir, 'exports', `${body.sessionId}.${body.format}`);
|
|
753
|
+
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
754
|
+
const filePath = await exportSession(body.sessionId, body.format, outputPath);
|
|
755
|
+
return reply.code(200).send({ filePath });
|
|
756
|
+
}
|
|
757
|
+
catch (err) {
|
|
758
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
logger_1.default.info('[API] Recording routes registered');
|
|
762
|
+
}
|
|
763
|
+
catch (err) {
|
|
764
|
+
logger_1.default.error('[API] Failed to register recording routes:', err);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
registerRoutes().catch((err) => logger_1.default.error('[API] Recording route registration error:', err));
|
|
768
|
+
}
|
|
769
|
+
// ── Expanded Routes (Tier 1 + Tier 2) ──
|
|
770
|
+
function registerExpandedRoutes(server) {
|
|
771
|
+
// GET /api/auth/status — auth state
|
|
772
|
+
server.get('/api/auth/status', async (_req, reply) => {
|
|
773
|
+
const state = (0, auth_1.getAuthState)();
|
|
774
|
+
return reply.code(200).send({
|
|
775
|
+
authenticated: (0, auth_1.isAuthenticated)(),
|
|
776
|
+
email: state.email || null,
|
|
777
|
+
name: state.name || null,
|
|
778
|
+
userId: state.userId || null,
|
|
779
|
+
plan: state.plan || 'free',
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
// GET /api/license/info — plan limits, feature gates, device
|
|
783
|
+
server.get('/api/license/info', async (_req, reply) => {
|
|
784
|
+
const state = (0, license_1.getLicenseState)();
|
|
785
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
786
|
+
const checkFeature = license_1.isFeatureAllowed;
|
|
787
|
+
return reply.code(200).send({
|
|
788
|
+
...state,
|
|
789
|
+
deviceId: (0, license_1.getMachineId)(),
|
|
790
|
+
features: {
|
|
791
|
+
ai: checkFeature('ai'),
|
|
792
|
+
recording: checkFeature('recording'),
|
|
793
|
+
mcp: checkFeature('mcp'),
|
|
794
|
+
},
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
// GET /api/ai/local-usage — daily AI quota
|
|
798
|
+
server.get('/api/ai/local-usage', async (_req, reply) => {
|
|
799
|
+
try {
|
|
800
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
801
|
+
return reply.code(401).send({ error: 'Not authenticated' });
|
|
802
|
+
}
|
|
803
|
+
const usage = await (0, ai_client_1.getAIUsage)();
|
|
804
|
+
return reply.code(200).send(usage);
|
|
805
|
+
}
|
|
806
|
+
catch (err) {
|
|
807
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
// GET /api/gallery/captures/:id/image — capture image as base64
|
|
811
|
+
server.get('/api/gallery/captures/:id/image', async (req, reply) => {
|
|
812
|
+
try {
|
|
813
|
+
const params = req.params;
|
|
814
|
+
const query = req.query;
|
|
815
|
+
const id = parseInt(params.id, 10);
|
|
816
|
+
if (isNaN(id))
|
|
817
|
+
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
818
|
+
const capture = (0, database_1.getCapture)(id);
|
|
819
|
+
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
820
|
+
return reply.code(404).send({ error: 'Capture image not found' });
|
|
821
|
+
}
|
|
822
|
+
const rawBuf = fs.readFileSync(capture.screenshot_path);
|
|
823
|
+
const buffer = await resizeCapture(rawBuf, query.resolution, query.maxWidth ? parseInt(query.maxWidth) : undefined, query.maxHeight ? parseInt(query.maxHeight) : undefined);
|
|
824
|
+
return reply.code(200).send({
|
|
825
|
+
imageBase64: buffer.toString('base64'),
|
|
826
|
+
mimeType: 'image/png',
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
catch (err) {
|
|
830
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
// POST /api/capture/fullscreen-image — capture with resolution + window targeting
|
|
834
|
+
server.post('/api/capture/fullscreen-image', async (req, reply) => {
|
|
835
|
+
try {
|
|
836
|
+
const body = req.body || {};
|
|
837
|
+
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
838
|
+
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
839
|
+
}
|
|
840
|
+
// Window targeting: find matching window and capture it
|
|
841
|
+
let windowInfo = null;
|
|
842
|
+
if (body.window) {
|
|
843
|
+
const sources = await (0, platform_1.getPlatform)().listWindows();
|
|
844
|
+
const match = sources.find((s) => s.name.toLowerCase().includes(body.window.toLowerCase()));
|
|
845
|
+
if (!match) {
|
|
846
|
+
return reply.code(404).send({ error: `No window matching "${body.window}"`, availableWindows: sources.map((s) => s.name) });
|
|
847
|
+
}
|
|
848
|
+
windowInfo = { appName: match.name, windowTitle: match.name };
|
|
849
|
+
}
|
|
850
|
+
let buffer = await (0, capture_1.captureScreen)();
|
|
851
|
+
// Auto-redact if enabled
|
|
852
|
+
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
853
|
+
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
854
|
+
if (redactSecrets || redactPII) {
|
|
855
|
+
const result = await (0, redact_1.autoRedact)(buffer, { secrets: redactSecrets, pii: redactPII });
|
|
856
|
+
buffer = result.buffer;
|
|
857
|
+
}
|
|
858
|
+
// Resize for token efficiency
|
|
859
|
+
buffer = await resizeCapture(buffer, body.resolution, body.maxWidth, body.maxHeight);
|
|
860
|
+
// Save to gallery
|
|
861
|
+
ensureCapturesDir(body.projectDir);
|
|
862
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
863
|
+
const filename = `capture-${timestamp}.png`;
|
|
864
|
+
const capturesDir = getCapturesDir(body.projectDir);
|
|
865
|
+
const filepath = path.join(capturesDir, filename);
|
|
866
|
+
fs.writeFileSync(filepath, buffer);
|
|
867
|
+
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
868
|
+
const { width, height } = primaryDisplay.size;
|
|
869
|
+
const captureId = (0, database_1.saveCapture)({
|
|
870
|
+
screenshotPath: filepath, regionX: 0, regionY: 0,
|
|
871
|
+
regionW: width, regionH: height,
|
|
872
|
+
sourceApp: windowInfo?.appName || 'API',
|
|
873
|
+
windowTitle: windowInfo?.windowTitle || 'Fullscreen Capture',
|
|
874
|
+
});
|
|
875
|
+
return reply.code(200).send({
|
|
876
|
+
captureId, width, height,
|
|
877
|
+
imageBase64: buffer.toString('base64'),
|
|
878
|
+
mimeType: 'image/png',
|
|
879
|
+
windowInfo,
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
catch (err) {
|
|
883
|
+
logger_1.default.error('[API] Fullscreen-image capture failed:', err);
|
|
884
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
// POST /api/redact — auto-redact secrets/PII
|
|
888
|
+
server.post('/api/redact', async (req, reply) => {
|
|
889
|
+
try {
|
|
890
|
+
const body = req.body || {};
|
|
891
|
+
let imageBuffer;
|
|
892
|
+
if (body.captureId) {
|
|
893
|
+
const capture = (0, database_1.getCapture)(body.captureId);
|
|
894
|
+
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
895
|
+
return reply.code(404).send({ error: 'Capture not found' });
|
|
896
|
+
}
|
|
897
|
+
imageBuffer = fs.readFileSync(capture.screenshot_path);
|
|
898
|
+
}
|
|
899
|
+
else if (body.imageBase64) {
|
|
900
|
+
imageBuffer = Buffer.from(body.imageBase64, 'base64');
|
|
901
|
+
}
|
|
902
|
+
else if (body.screenshotPath && fs.existsSync(body.screenshotPath)) {
|
|
903
|
+
imageBuffer = fs.readFileSync(body.screenshotPath);
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
return reply.code(400).send({ error: 'captureId, imageBase64, or screenshotPath required' });
|
|
907
|
+
}
|
|
908
|
+
const result = await (0, redact_1.autoRedact)(imageBuffer, {
|
|
909
|
+
secrets: body.secrets !== false,
|
|
910
|
+
pii: body.pii ?? false,
|
|
911
|
+
});
|
|
912
|
+
return reply.code(200).send({
|
|
913
|
+
imageBase64: result.buffer.toString('base64'),
|
|
914
|
+
regionsFound: result.regionsFound,
|
|
915
|
+
regions: result.regions,
|
|
916
|
+
mimeType: 'image/png',
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
catch (err) {
|
|
920
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
// POST /api/transcribe — audio transcription via backend Whisper
|
|
924
|
+
server.post('/api/transcribe', async (req, reply) => {
|
|
925
|
+
try {
|
|
926
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
927
|
+
return reply.code(401).send({ error: 'Authentication required for transcription' });
|
|
928
|
+
}
|
|
929
|
+
const body = req.body || {};
|
|
930
|
+
let audioBase64 = body.audioBase64;
|
|
931
|
+
if (!audioBase64 && body.audioPath && fs.existsSync(body.audioPath)) {
|
|
932
|
+
audioBase64 = fs.readFileSync(body.audioPath).toString('base64');
|
|
933
|
+
}
|
|
934
|
+
if (!audioBase64) {
|
|
935
|
+
return reply.code(400).send({ error: 'audioBase64 or audioPath required' });
|
|
936
|
+
}
|
|
937
|
+
const text = await (0, ai_client_1.transcribeViaBackend)(audioBase64, body.language, 'api');
|
|
938
|
+
return reply.code(200).send({ text });
|
|
939
|
+
}
|
|
940
|
+
catch (err) {
|
|
941
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
// GET /api/windows — list visible windows
|
|
945
|
+
server.get('/api/windows', async (_req, reply) => {
|
|
946
|
+
try {
|
|
947
|
+
const sources = await (0, platform_1.getPlatform)().listWindows();
|
|
948
|
+
const active = await (0, active_window_1.getActiveWindowInfo)();
|
|
949
|
+
return reply.code(200).send({
|
|
950
|
+
windows: sources.map((s) => ({
|
|
951
|
+
id: s.id,
|
|
952
|
+
name: s.name,
|
|
953
|
+
isActive: s.name === active.windowTitle,
|
|
954
|
+
})),
|
|
955
|
+
activeWindow: active,
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
catch (err) {
|
|
959
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
// GET /api/dictation/history — past transcriptions
|
|
963
|
+
server.get('/api/dictation/history', async (req, reply) => {
|
|
964
|
+
try {
|
|
965
|
+
const query = req.query;
|
|
966
|
+
const limit = parseInt(query.limit || '50', 10);
|
|
967
|
+
const entries = (0, database_1.getDictationHistory)(limit);
|
|
968
|
+
return reply.code(200).send({ entries });
|
|
969
|
+
}
|
|
970
|
+
catch (err) {
|
|
971
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
972
|
+
}
|
|
973
|
+
});
|
|
974
|
+
// GET /api/analytics/summary — local usage analytics
|
|
975
|
+
server.get('/api/analytics/summary', async (_req, reply) => {
|
|
976
|
+
try {
|
|
977
|
+
const summary = (0, database_1.getAnalyticsSummary)();
|
|
978
|
+
return reply.code(200).send({ summary });
|
|
979
|
+
}
|
|
980
|
+
catch (err) {
|
|
981
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
// GET /api/analytics/trend — time series for an event type
|
|
985
|
+
server.get('/api/analytics/trend', async (req, reply) => {
|
|
986
|
+
try {
|
|
987
|
+
const query = req.query;
|
|
988
|
+
if (!query.eventType)
|
|
989
|
+
return reply.code(400).send({ error: 'eventType required' });
|
|
990
|
+
const count = parseInt(query.count || '30', 10);
|
|
991
|
+
let data;
|
|
992
|
+
switch (query.granularity) {
|
|
993
|
+
case 'hourly':
|
|
994
|
+
data = (0, database_1.getHourlyTrend)(query.eventType, count);
|
|
995
|
+
break;
|
|
996
|
+
default:
|
|
997
|
+
data = (0, database_1.getDailyTrend)(query.eventType, count);
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
return reply.code(200).send({ trend: data });
|
|
1001
|
+
}
|
|
1002
|
+
catch (err) {
|
|
1003
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
// POST /api/baseline — set/get/list workflow baselines
|
|
1007
|
+
server.post('/api/baseline', async (req, reply) => {
|
|
1008
|
+
try {
|
|
1009
|
+
const body = req.body || { action: '' };
|
|
1010
|
+
switch (body.action) {
|
|
1011
|
+
case 'set':
|
|
1012
|
+
if (!body.workflowName || !body.sessionId)
|
|
1013
|
+
return reply.code(400).send({ error: 'workflowName and sessionId required' });
|
|
1014
|
+
(0, database_1.setBaseline)(body.workflowName, body.sessionId);
|
|
1015
|
+
return reply.code(200).send({ success: true });
|
|
1016
|
+
case 'get':
|
|
1017
|
+
if (!body.workflowName)
|
|
1018
|
+
return reply.code(400).send({ error: 'workflowName required' });
|
|
1019
|
+
return reply.code(200).send({ baseline: (0, database_1.getCurrentBaseline)(body.workflowName) });
|
|
1020
|
+
case 'history':
|
|
1021
|
+
if (!body.workflowName)
|
|
1022
|
+
return reply.code(400).send({ error: 'workflowName required' });
|
|
1023
|
+
return reply.code(200).send({ history: (0, database_1.getBaselineHistory)(body.workflowName) });
|
|
1024
|
+
default:
|
|
1025
|
+
return reply.code(400).send({ error: 'action must be set, get, or history' });
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
catch (err) {
|
|
1029
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
// POST /api/clipboard — read/write clipboard
|
|
1033
|
+
server.post('/api/clipboard', async (req, reply) => {
|
|
1034
|
+
try {
|
|
1035
|
+
const body = req.body || { action: '' };
|
|
1036
|
+
switch (body.action) {
|
|
1037
|
+
case 'read':
|
|
1038
|
+
return reply.code(200).send({ text: (0, platform_1.getPlatform)().getClipboardText() });
|
|
1039
|
+
case 'write':
|
|
1040
|
+
if (body.text === undefined)
|
|
1041
|
+
return reply.code(400).send({ error: 'text required' });
|
|
1042
|
+
(0, platform_1.getPlatform)().setClipboardText(body.text);
|
|
1043
|
+
return reply.code(200).send({ success: true });
|
|
1044
|
+
case 'readImage': {
|
|
1045
|
+
const imgBuf = (0, platform_1.getPlatform)().getClipboardImage();
|
|
1046
|
+
if (!imgBuf)
|
|
1047
|
+
return reply.code(200).send({ imageBase64: null });
|
|
1048
|
+
return reply.code(200).send({ imageBase64: imgBuf.toString('base64'), mimeType: 'image/png' });
|
|
1049
|
+
}
|
|
1050
|
+
default:
|
|
1051
|
+
return reply.code(400).send({ error: 'action must be read, write, or readImage' });
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
catch (err) {
|
|
1055
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1056
|
+
}
|
|
1057
|
+
});
|
|
1058
|
+
// POST /api/dictate — accept audio, transcribe, return text
|
|
1059
|
+
server.post('/api/dictate', async (req, reply) => {
|
|
1060
|
+
try {
|
|
1061
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
1062
|
+
return reply.code(401).send({ error: 'Authentication required for dictation' });
|
|
1063
|
+
}
|
|
1064
|
+
const body = req.body || {};
|
|
1065
|
+
let audioBase64 = body.audioBase64;
|
|
1066
|
+
if (!audioBase64 && body.audioPath && fs.existsSync(body.audioPath)) {
|
|
1067
|
+
audioBase64 = fs.readFileSync(body.audioPath).toString('base64');
|
|
1068
|
+
}
|
|
1069
|
+
if (!audioBase64) {
|
|
1070
|
+
return reply.code(400).send({ error: 'audioBase64 or audioPath required' });
|
|
1071
|
+
}
|
|
1072
|
+
const rawText = await (0, ai_client_1.transcribeViaBackend)(audioBase64, body.language, 'dictation');
|
|
1073
|
+
// Optional AI cleanup
|
|
1074
|
+
let finalText = rawText;
|
|
1075
|
+
if (body.cleanup !== false) {
|
|
1076
|
+
try {
|
|
1077
|
+
const { removeFillerWords, deduplicateConsecutiveWords } = await Promise.resolve().then(() => __importStar(require('./dictation')));
|
|
1078
|
+
finalText = deduplicateConsecutiveWords(removeFillerWords(rawText));
|
|
1079
|
+
}
|
|
1080
|
+
catch {
|
|
1081
|
+
// Dictation module may not be available — return raw text
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return reply.code(200).send({ text: finalText, rawText });
|
|
1085
|
+
}
|
|
1086
|
+
catch (err) {
|
|
1087
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
// POST /api/dictate/mic — record from microphone, transcribe, return text
|
|
1091
|
+
server.post('/api/dictate/mic', async (req, reply) => {
|
|
1092
|
+
try {
|
|
1093
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
1094
|
+
return reply.code(401).send({ error: 'Authentication required for dictation' });
|
|
1095
|
+
}
|
|
1096
|
+
const body = req.body || {};
|
|
1097
|
+
const duration = body.duration || 10;
|
|
1098
|
+
// Mic capture — pipes audio to memory (no temp file I/O)
|
|
1099
|
+
let audioBase64;
|
|
1100
|
+
try {
|
|
1101
|
+
const { recordForDuration, isMicAvailable, getMicBackend } = await Promise.resolve().then(() => __importStar(require('../../headless/mic-capture')));
|
|
1102
|
+
if (!isMicAvailable()) {
|
|
1103
|
+
return reply.code(400).send({
|
|
1104
|
+
error: 'Live mic requires ffmpeg (bundled automatically). If this persists, install: winget install ffmpeg (Windows), brew install ffmpeg (macOS).',
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
logger_1.default.info(`[API] Mic recording via ${getMicBackend()}, duration=${duration}s`);
|
|
1108
|
+
const audioBuffer = await recordForDuration(duration);
|
|
1109
|
+
audioBase64 = audioBuffer.toString('base64');
|
|
1110
|
+
}
|
|
1111
|
+
catch (err) {
|
|
1112
|
+
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1113
|
+
}
|
|
1114
|
+
const rawText = await (0, ai_client_1.transcribeViaBackend)(audioBase64, body.language, 'dictation-mic');
|
|
1115
|
+
let finalText = rawText;
|
|
1116
|
+
if (body.cleanup !== false) {
|
|
1117
|
+
try {
|
|
1118
|
+
const { removeFillerWords, deduplicateConsecutiveWords } = await Promise.resolve().then(() => __importStar(require('./dictation')));
|
|
1119
|
+
finalText = deduplicateConsecutiveWords(removeFillerWords(rawText));
|
|
1120
|
+
}
|
|
1121
|
+
catch { /* fallback to raw */ }
|
|
1122
|
+
}
|
|
1123
|
+
return reply.code(200).send({ text: finalText, rawText, source: 'mic', duration });
|
|
1124
|
+
}
|
|
1125
|
+
catch (err) {
|
|
1126
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
// POST /api/capture/:id/annotate — add annotations to a capture
|
|
1130
|
+
server.post('/api/capture/:id/annotate', async (req, reply) => {
|
|
1131
|
+
try {
|
|
1132
|
+
const params = req.params;
|
|
1133
|
+
const id = parseInt(params.id, 10);
|
|
1134
|
+
if (isNaN(id))
|
|
1135
|
+
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
1136
|
+
const capture = (0, database_1.getCapture)(id);
|
|
1137
|
+
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
1138
|
+
return reply.code(404).send({ error: 'Capture not found' });
|
|
1139
|
+
}
|
|
1140
|
+
const body = req.body || { annotations: [] };
|
|
1141
|
+
if (!body.annotations?.length) {
|
|
1142
|
+
return reply.code(400).send({ error: 'annotations array required' });
|
|
1143
|
+
}
|
|
1144
|
+
const sharp = require('sharp');
|
|
1145
|
+
let image = sharp(capture.screenshot_path);
|
|
1146
|
+
const meta = await image.metadata();
|
|
1147
|
+
const imgW = meta.width || 1920;
|
|
1148
|
+
const imgH = meta.height || 1080;
|
|
1149
|
+
// Build SVG overlay for non-blur annotations
|
|
1150
|
+
const svgParts = [];
|
|
1151
|
+
const blurRegions = [];
|
|
1152
|
+
for (const a of body.annotations) {
|
|
1153
|
+
const color = a.color || '#ff0000';
|
|
1154
|
+
if (a.type === 'rectangle') {
|
|
1155
|
+
svgParts.push(`<rect x="${a.x}" y="${a.y}" width="${a.width || 100}" height="${a.height || 100}" fill="none" stroke="${color}" stroke-width="3"/>`);
|
|
1156
|
+
}
|
|
1157
|
+
else if (a.type === 'highlight') {
|
|
1158
|
+
svgParts.push(`<rect x="${a.x}" y="${a.y}" width="${a.width || 100}" height="${a.height || 100}" fill="${color}" fill-opacity="0.3"/>`);
|
|
1159
|
+
}
|
|
1160
|
+
else if (a.type === 'text') {
|
|
1161
|
+
const fs2 = a.fontSize || 24;
|
|
1162
|
+
svgParts.push(`<text x="${a.x}" y="${a.y}" font-size="${fs2}" fill="${color}" font-family="Arial, sans-serif">${escapeXml(a.text || '')}</text>`);
|
|
1163
|
+
}
|
|
1164
|
+
else if (a.type === 'arrow' && a.toX !== undefined && a.toY !== undefined) {
|
|
1165
|
+
svgParts.push(`<defs><marker id="ah" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto"><polygon points="0 0, 10 3.5, 0 7" fill="${color}"/></marker></defs>`);
|
|
1166
|
+
svgParts.push(`<line x1="${a.x}" y1="${a.y}" x2="${a.toX}" y2="${a.toY}" stroke="${color}" stroke-width="2" marker-end="url(#ah)"/>`);
|
|
1167
|
+
}
|
|
1168
|
+
else if (a.type === 'blur') {
|
|
1169
|
+
blurRegions.push({ x: a.x, y: a.y, width: a.width || 100, height: a.height || 100 });
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
// Apply blur regions first
|
|
1173
|
+
let baseBuffer = await image.png().toBuffer();
|
|
1174
|
+
for (const region of blurRegions) {
|
|
1175
|
+
const extracted = await sharp(baseBuffer).extract({
|
|
1176
|
+
left: Math.max(0, Math.round(region.x)),
|
|
1177
|
+
top: Math.max(0, Math.round(region.y)),
|
|
1178
|
+
width: Math.min(Math.round(region.width), imgW - Math.round(region.x)),
|
|
1179
|
+
height: Math.min(Math.round(region.height), imgH - Math.round(region.y)),
|
|
1180
|
+
}).blur(15).toBuffer();
|
|
1181
|
+
baseBuffer = await sharp(baseBuffer).composite([{
|
|
1182
|
+
input: extracted,
|
|
1183
|
+
left: Math.max(0, Math.round(region.x)),
|
|
1184
|
+
top: Math.max(0, Math.round(region.y)),
|
|
1185
|
+
}]).png().toBuffer();
|
|
1186
|
+
}
|
|
1187
|
+
// Apply SVG overlay
|
|
1188
|
+
if (svgParts.length > 0) {
|
|
1189
|
+
const svg = `<svg width="${imgW}" height="${imgH}" xmlns="http://www.w3.org/2000/svg">${svgParts.join('')}</svg>`;
|
|
1190
|
+
baseBuffer = await sharp(baseBuffer).composite([{ input: Buffer.from(svg), top: 0, left: 0 }]).png().toBuffer();
|
|
1191
|
+
}
|
|
1192
|
+
// Optionally save over the original
|
|
1193
|
+
if (body.save) {
|
|
1194
|
+
fs.writeFileSync(capture.screenshot_path, baseBuffer);
|
|
1195
|
+
}
|
|
1196
|
+
return reply.code(200).send({
|
|
1197
|
+
imageBase64: baseBuffer.toString('base64'),
|
|
1198
|
+
mimeType: 'image/png',
|
|
1199
|
+
annotationsApplied: body.annotations.length,
|
|
1200
|
+
saved: !!body.save,
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
catch (err) {
|
|
1204
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
// POST /api/recording/describe-frames — AI description of recording frames
|
|
1208
|
+
server.post('/api/recording/describe-frames', async (req, reply) => {
|
|
1209
|
+
try {
|
|
1210
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
1211
|
+
return reply.code(401).send({ error: 'Authentication required' });
|
|
1212
|
+
}
|
|
1213
|
+
const { getSessionFrames: getFrames } = await Promise.resolve().then(() => __importStar(require('../db/database')));
|
|
1214
|
+
const body = req.body || { sessionId: '' };
|
|
1215
|
+
if (!body.sessionId)
|
|
1216
|
+
return reply.code(400).send({ error: 'sessionId required' });
|
|
1217
|
+
const frames = getFrames(body.sessionId);
|
|
1218
|
+
if (!frames.length)
|
|
1219
|
+
return reply.code(404).send({ error: 'No frames found' });
|
|
1220
|
+
const limit = body.limit || 20;
|
|
1221
|
+
const selectedFrames = frames.slice(0, limit);
|
|
1222
|
+
const descriptions = [];
|
|
1223
|
+
for (const frame of selectedFrames) {
|
|
1224
|
+
if (!fs.existsSync(frame.screenshot_path))
|
|
1225
|
+
continue;
|
|
1226
|
+
const buf = fs.readFileSync(frame.screenshot_path);
|
|
1227
|
+
const imageBase64 = await resizeImageForAI(buf);
|
|
1228
|
+
let description = '';
|
|
1229
|
+
for await (const chunk of (0, ai_client_1.streamAIFromBackend)({
|
|
1230
|
+
imagesBase64: [imageBase64],
|
|
1231
|
+
instruction: `Briefly describe what's visible in this screenshot (frame #${frame.frame_number} of a recording session). Focus on the application state, visible UI elements, and any notable changes. Keep it to 1-2 sentences.`,
|
|
1232
|
+
})) {
|
|
1233
|
+
description += chunk;
|
|
1234
|
+
}
|
|
1235
|
+
descriptions.push({ frameNumber: frame.frame_number, description });
|
|
1236
|
+
}
|
|
1237
|
+
return reply.code(200).send({ sessionId: body.sessionId, descriptions });
|
|
1238
|
+
}
|
|
1239
|
+
catch (err) {
|
|
1240
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1241
|
+
}
|
|
1242
|
+
});
|
|
1243
|
+
// POST /api/recording/narrate — generate prose summary of a session
|
|
1244
|
+
server.post('/api/recording/narrate', async (req, reply) => {
|
|
1245
|
+
try {
|
|
1246
|
+
if (!(0, auth_1.isAuthenticated)()) {
|
|
1247
|
+
return reply.code(401).send({ error: 'Authentication required' });
|
|
1248
|
+
}
|
|
1249
|
+
const body = req.body || { sessionId: '' };
|
|
1250
|
+
if (!body.sessionId)
|
|
1251
|
+
return reply.code(400).send({ error: 'sessionId required' });
|
|
1252
|
+
// If descriptions not provided, generate them first
|
|
1253
|
+
let descriptions = body.descriptions;
|
|
1254
|
+
if (!descriptions) {
|
|
1255
|
+
return reply.code(400).send({ error: 'descriptions array required (use /api/recording/describe-frames first)' });
|
|
1256
|
+
}
|
|
1257
|
+
const frameList = descriptions.map((d) => `Frame ${d.frameNumber}: ${d.description}`).join('\n');
|
|
1258
|
+
let narration = '';
|
|
1259
|
+
for await (const chunk of (0, ai_client_1.streamAIFromBackend)({
|
|
1260
|
+
imagesBase64: [],
|
|
1261
|
+
instruction: `You are narrating a screen recording session. Based on these frame descriptions, write a concise narrative summary of what happened during this session. Use past tense.\n\n${frameList}`,
|
|
1262
|
+
})) {
|
|
1263
|
+
narration += chunk;
|
|
1264
|
+
}
|
|
1265
|
+
return reply.code(200).send({ sessionId: body.sessionId, narration });
|
|
1266
|
+
}
|
|
1267
|
+
catch (err) {
|
|
1268
|
+
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
}
|
|
1272
|
+
function escapeXml(s) {
|
|
1273
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
1274
|
+
}
|
|
1275
|
+
// ── Server Lifecycle ──
|
|
1276
|
+
async function startApiServer() {
|
|
1277
|
+
if (server)
|
|
1278
|
+
return;
|
|
1279
|
+
startTime = Date.now();
|
|
1280
|
+
authToken = generateAuthToken();
|
|
1281
|
+
server = (0, fastify_1.default)({ logger: false, bodyLimit: 50 * 1024 * 1024 }); // 50MB body limit for images
|
|
1282
|
+
// Register all route groups
|
|
1283
|
+
registerHealthRoutes(server);
|
|
1284
|
+
registerCaptureRoutes(server);
|
|
1285
|
+
registerAIRoutes(server);
|
|
1286
|
+
registerGalleryRoutes(server);
|
|
1287
|
+
registerSettingsRoutes(server);
|
|
1288
|
+
registerPresetsRoutes(server);
|
|
1289
|
+
// Token Compression Engine route
|
|
1290
|
+
registerCompressRoutes(server);
|
|
1291
|
+
// Expanded routes (auth, license, AI usage, redact, transcribe, windows, etc.)
|
|
1292
|
+
registerExpandedRoutes(server);
|
|
1293
|
+
// Recording routes are registered separately when the recording module is enabled
|
|
1294
|
+
// They can also be registered immediately if recording is already enabled
|
|
1295
|
+
if ((0, store_1.getSetting)('recordingFeatureEnabled')) {
|
|
1296
|
+
registerRecordingRoutesOnServer();
|
|
1297
|
+
}
|
|
1298
|
+
try {
|
|
1299
|
+
await server.listen({ port: API_PORT, host: API_HOST });
|
|
1300
|
+
logger_1.default.info(`[API] HTTP API listening on http://${API_HOST}:${API_PORT}`);
|
|
1301
|
+
}
|
|
1302
|
+
catch (err) {
|
|
1303
|
+
logger_1.default.error('[API] Failed to start HTTP API:', err);
|
|
1304
|
+
server = null;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
async function stopApiServer() {
|
|
1308
|
+
if (server) {
|
|
1309
|
+
await server.close();
|
|
1310
|
+
server = null;
|
|
1311
|
+
recordingRoutesRegistered = false;
|
|
1312
|
+
logger_1.default.info('[API] HTTP API stopped');
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
function getApiAuthToken() {
|
|
1316
|
+
return authToken;
|
|
1317
|
+
}
|
|
1318
|
+
function getApiServer() {
|
|
1319
|
+
return server;
|
|
1320
|
+
}
|
|
1321
|
+
function isApiServerRunning() {
|
|
1322
|
+
return server !== null;
|
|
1323
|
+
}
|