superbased 2.0.9 → 3.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -26
- package/README.md +166 -258
- package/package.json +42 -140
- package/SUPERBASED_SKILL.md +0 -1660
- package/dist/electron/ai/ai-client.d.ts +0 -45
- package/dist/electron/ai/ai-client.d.ts.map +0 -1
- package/dist/electron/ai/ai-client.js +0 -205
- package/dist/electron/ai/ai-client.js.map +0 -1
- package/dist/electron/ai/context-builder.d.ts +0 -8
- package/dist/electron/ai/context-builder.d.ts.map +0 -1
- package/dist/electron/ai/context-builder.js +0 -28
- package/dist/electron/ai/context-builder.js.map +0 -1
- package/dist/electron/ai/instruction-parser.d.ts +0 -11
- package/dist/electron/ai/instruction-parser.d.ts.map +0 -1
- package/dist/electron/ai/instruction-parser.js +0 -47
- package/dist/electron/ai/instruction-parser.js.map +0 -1
- package/dist/electron/ai/orchestrator.d.ts +0 -17
- package/dist/electron/ai/orchestrator.d.ts.map +0 -1
- package/dist/electron/ai/orchestrator.js +0 -53
- package/dist/electron/ai/orchestrator.js.map +0 -1
- package/dist/electron/ai/providers/anthropic.d.ts +0 -6
- package/dist/electron/ai/providers/anthropic.d.ts.map +0 -1
- package/dist/electron/ai/providers/anthropic.js +0 -67
- package/dist/electron/ai/providers/anthropic.js.map +0 -1
- package/dist/electron/ai/providers/azure-openai.d.ts +0 -12
- package/dist/electron/ai/providers/azure-openai.d.ts.map +0 -1
- package/dist/electron/ai/providers/azure-openai.js +0 -87
- package/dist/electron/ai/providers/azure-openai.js.map +0 -1
- package/dist/electron/ai/providers/gemini.d.ts +0 -6
- package/dist/electron/ai/providers/gemini.d.ts.map +0 -1
- package/dist/electron/ai/providers/gemini.js +0 -49
- package/dist/electron/ai/providers/gemini.js.map +0 -1
- package/dist/electron/ai/providers/openai.d.ts +0 -6
- package/dist/electron/ai/providers/openai.d.ts.map +0 -1
- package/dist/electron/ai/providers/openai.js +0 -68
- package/dist/electron/ai/providers/openai.js.map +0 -1
- package/dist/electron/core/auth-store.d.ts +0 -15
- package/dist/electron/core/auth-store.d.ts.map +0 -1
- package/dist/electron/core/auth-store.js +0 -86
- package/dist/electron/core/auth-store.js.map +0 -1
- package/dist/electron/core/config.d.ts +0 -6
- package/dist/electron/core/config.d.ts.map +0 -1
- package/dist/electron/core/config.js +0 -81
- package/dist/electron/core/config.js.map +0 -1
- package/dist/electron/core/file-logger.d.ts +0 -17
- package/dist/electron/core/file-logger.d.ts.map +0 -1
- package/dist/electron/core/file-logger.js +0 -74
- package/dist/electron/core/file-logger.js.map +0 -1
- package/dist/electron/core/input-injection/index.d.ts +0 -6
- package/dist/electron/core/input-injection/index.d.ts.map +0 -1
- package/dist/electron/core/input-injection/index.js +0 -31
- package/dist/electron/core/input-injection/index.js.map +0 -1
- package/dist/electron/core/input-injection/macos.d.ts +0 -3
- package/dist/electron/core/input-injection/macos.d.ts.map +0 -1
- package/dist/electron/core/input-injection/macos.js +0 -14
- package/dist/electron/core/input-injection/macos.js.map +0 -1
- package/dist/electron/core/input-injection/windows.d.ts +0 -3
- package/dist/electron/core/input-injection/windows.d.ts.map +0 -1
- package/dist/electron/core/input-injection/windows.js +0 -119
- package/dist/electron/core/input-injection/windows.js.map +0 -1
- package/dist/electron/core/json-store.d.ts +0 -26
- package/dist/electron/core/json-store.d.ts.map +0 -1
- package/dist/electron/core/json-store.js +0 -132
- package/dist/electron/core/json-store.js.map +0 -1
- package/dist/electron/core/paths.d.ts +0 -17
- package/dist/electron/core/paths.d.ts.map +0 -1
- package/dist/electron/core/paths.js +0 -117
- package/dist/electron/core/paths.js.map +0 -1
- package/dist/electron/core/platform.d.ts +0 -24
- package/dist/electron/core/platform.d.ts.map +0 -1
- package/dist/electron/core/platform.js +0 -18
- package/dist/electron/core/platform.js.map +0 -1
- package/dist/electron/core/process-coord.d.ts +0 -19
- package/dist/electron/core/process-coord.d.ts.map +0 -1
- package/dist/electron/core/process-coord.js +0 -124
- package/dist/electron/core/process-coord.js.map +0 -1
- package/dist/electron/core/serialize-schema.d.ts +0 -35
- package/dist/electron/core/serialize-schema.d.ts.map +0 -1
- package/dist/electron/core/serialize-schema.js +0 -89
- package/dist/electron/core/serialize-schema.js.map +0 -1
- package/dist/electron/core/settings-schema.d.ts +0 -81
- package/dist/electron/core/settings-schema.d.ts.map +0 -1
- package/dist/electron/core/settings-schema.js +0 -1370
- package/dist/electron/core/settings-schema.js.map +0 -1
- package/dist/electron/db/database.d.ts +0 -154
- package/dist/electron/db/database.d.ts.map +0 -1
- package/dist/electron/db/database.js +0 -637
- package/dist/electron/db/database.js.map +0 -1
- package/dist/electron/db/models.d.ts +0 -26
- package/dist/electron/db/models.d.ts.map +0 -1
- package/dist/electron/db/models.js +0 -4
- package/dist/electron/db/models.js.map +0 -1
- package/dist/electron/logger.d.ts +0 -9
- package/dist/electron/logger.d.ts.map +0 -1
- package/dist/electron/logger.js +0 -32
- package/dist/electron/logger.js.map +0 -1
- package/dist/electron/main.js +0 -3652
- package/dist/electron/modules/accessibility/macos-provider.d.ts +0 -8
- package/dist/electron/modules/accessibility/macos-provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/macos-provider.js +0 -94
- package/dist/electron/modules/accessibility/macos-provider.js.map +0 -1
- package/dist/electron/modules/accessibility/provider.d.ts +0 -12
- package/dist/electron/modules/accessibility/provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/provider.js +0 -52
- package/dist/electron/modules/accessibility/provider.js.map +0 -1
- package/dist/electron/modules/accessibility/types.d.ts +0 -63
- package/dist/electron/modules/accessibility/types.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/types.js +0 -6
- package/dist/electron/modules/accessibility/types.js.map +0 -1
- package/dist/electron/modules/accessibility/windows-provider.d.ts +0 -8
- package/dist/electron/modules/accessibility/windows-provider.d.ts.map +0 -1
- package/dist/electron/modules/accessibility/windows-provider.js +0 -85
- package/dist/electron/modules/accessibility/windows-provider.js.map +0 -1
- package/dist/electron/modules/active-window.d.ts +0 -6
- package/dist/electron/modules/active-window.d.ts.map +0 -1
- package/dist/electron/modules/active-window.js +0 -76
- package/dist/electron/modules/active-window.js.map +0 -1
- package/dist/electron/modules/api-server.d.ts +0 -11
- package/dist/electron/modules/api-server.d.ts.map +0 -1
- package/dist/electron/modules/api-server.js +0 -2759
- package/dist/electron/modules/api-server.js.map +0 -1
- package/dist/electron/modules/auth.d.ts +0 -42
- package/dist/electron/modules/auth.d.ts.map +0 -1
- package/dist/electron/modules/auth.js +0 -193
- package/dist/electron/modules/auth.js.map +0 -1
- package/dist/electron/modules/azure-speech-realtime.d.ts +0 -48
- package/dist/electron/modules/azure-speech-realtime.d.ts.map +0 -1
- package/dist/electron/modules/azure-speech-realtime.js +0 -543
- package/dist/electron/modules/azure-speech-realtime.js.map +0 -1
- package/dist/electron/modules/capture-modes.d.ts +0 -19
- package/dist/electron/modules/capture-modes.d.ts.map +0 -1
- package/dist/electron/modules/capture-modes.js +0 -100
- package/dist/electron/modules/capture-modes.js.map +0 -1
- package/dist/electron/modules/capture.d.ts +0 -24
- package/dist/electron/modules/capture.d.ts.map +0 -1
- package/dist/electron/modules/capture.js +0 -191
- package/dist/electron/modules/capture.js.map +0 -1
- package/dist/electron/modules/clipboard.d.ts +0 -6
- package/dist/electron/modules/clipboard.d.ts.map +0 -1
- package/dist/electron/modules/clipboard.js +0 -26
- package/dist/electron/modules/clipboard.js.map +0 -1
- package/dist/electron/modules/color-picker.d.ts +0 -4
- package/dist/electron/modules/color-picker.d.ts.map +0 -1
- package/dist/electron/modules/color-picker.js +0 -233
- package/dist/electron/modules/color-picker.js.map +0 -1
- package/dist/electron/modules/compose-screenshots.d.ts +0 -8
- package/dist/electron/modules/compose-screenshots.d.ts.map +0 -1
- package/dist/electron/modules/compose-screenshots.js +0 -86
- package/dist/electron/modules/compose-screenshots.js.map +0 -1
- package/dist/electron/modules/context-menu-detect.d.ts +0 -47
- package/dist/electron/modules/context-menu-detect.d.ts.map +0 -1
- package/dist/electron/modules/context-menu-detect.js +0 -272
- package/dist/electron/modules/context-menu-detect.js.map +0 -1
- package/dist/electron/modules/dictation.d.ts +0 -27
- package/dist/electron/modules/dictation.d.ts.map +0 -1
- package/dist/electron/modules/dictation.js +0 -1231
- package/dist/electron/modules/dictation.js.map +0 -1
- package/dist/electron/modules/error-reporter.d.ts +0 -7
- package/dist/electron/modules/error-reporter.d.ts.map +0 -1
- package/dist/electron/modules/error-reporter.js +0 -65
- package/dist/electron/modules/error-reporter.js.map +0 -1
- package/dist/electron/modules/gif-util.d.ts +0 -9
- package/dist/electron/modules/gif-util.d.ts.map +0 -1
- package/dist/electron/modules/gif-util.js +0 -63
- package/dist/electron/modules/gif-util.js.map +0 -1
- package/dist/electron/modules/gui-automation-errors.d.ts +0 -11
- package/dist/electron/modules/gui-automation-errors.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation-errors.js +0 -79
- package/dist/electron/modules/gui-automation-errors.js.map +0 -1
- package/dist/electron/modules/gui-automation-telemetry.d.ts +0 -38
- package/dist/electron/modules/gui-automation-telemetry.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation-telemetry.js +0 -200
- package/dist/electron/modules/gui-automation-telemetry.js.map +0 -1
- package/dist/electron/modules/gui-automation.d.ts +0 -1143
- package/dist/electron/modules/gui-automation.d.ts.map +0 -1
- package/dist/electron/modules/gui-automation.js +0 -8769
- package/dist/electron/modules/gui-automation.js.map +0 -1
- package/dist/electron/modules/hotkeys.d.ts +0 -5
- package/dist/electron/modules/hotkeys.d.ts.map +0 -1
- package/dist/electron/modules/hotkeys.js +0 -64
- package/dist/electron/modules/hotkeys.js.map +0 -1
- package/dist/electron/modules/human-input/index.d.ts +0 -35
- package/dist/electron/modules/human-input/index.d.ts.map +0 -1
- package/dist/electron/modules/human-input/index.js +0 -163
- package/dist/electron/modules/human-input/index.js.map +0 -1
- package/dist/electron/modules/human-input/keyboard/timing.d.ts +0 -38
- package/dist/electron/modules/human-input/keyboard/timing.d.ts.map +0 -1
- package/dist/electron/modules/human-input/keyboard/timing.js +0 -57
- package/dist/electron/modules/human-input/keyboard/timing.js.map +0 -1
- package/dist/electron/modules/human-input/mouse/path.d.ts +0 -24
- package/dist/electron/modules/human-input/mouse/path.d.ts.map +0 -1
- package/dist/electron/modules/human-input/mouse/path.js +0 -80
- package/dist/electron/modules/human-input/mouse/path.js.map +0 -1
- package/dist/electron/modules/human-input/mouse/velocity.d.ts +0 -48
- package/dist/electron/modules/human-input/mouse/velocity.d.ts.map +0 -1
- package/dist/electron/modules/human-input/mouse/velocity.js +0 -93
- package/dist/electron/modules/human-input/mouse/velocity.js.map +0 -1
- package/dist/electron/modules/human-input/profiles.d.ts +0 -90
- package/dist/electron/modules/human-input/profiles.d.ts.map +0 -1
- package/dist/electron/modules/human-input/profiles.js +0 -124
- package/dist/electron/modules/human-input/profiles.js.map +0 -1
- package/dist/electron/modules/human-input/rng.d.ts +0 -16
- package/dist/electron/modules/human-input/rng.d.ts.map +0 -1
- package/dist/electron/modules/human-input/rng.js +0 -101
- package/dist/electron/modules/human-input/rng.js.map +0 -1
- package/dist/electron/modules/human-input/salt.d.ts +0 -15
- package/dist/electron/modules/human-input/salt.d.ts.map +0 -1
- package/dist/electron/modules/human-input/salt.js +0 -48
- package/dist/electron/modules/human-input/salt.js.map +0 -1
- package/dist/electron/modules/image-utils.d.ts +0 -20
- package/dist/electron/modules/image-utils.d.ts.map +0 -1
- package/dist/electron/modules/image-utils.js +0 -80
- package/dist/electron/modules/image-utils.js.map +0 -1
- package/dist/electron/modules/keystroke.d.ts +0 -7
- package/dist/electron/modules/keystroke.d.ts.map +0 -1
- package/dist/electron/modules/keystroke.js +0 -53
- package/dist/electron/modules/keystroke.js.map +0 -1
- package/dist/electron/modules/license.d.ts +0 -25
- package/dist/electron/modules/license.d.ts.map +0 -1
- package/dist/electron/modules/license.js +0 -175
- package/dist/electron/modules/license.js.map +0 -1
- package/dist/electron/modules/mcp-config.d.ts +0 -16
- package/dist/electron/modules/mcp-config.d.ts.map +0 -1
- package/dist/electron/modules/mcp-config.js +0 -146
- package/dist/electron/modules/mcp-config.js.map +0 -1
- package/dist/electron/modules/ocr.d.ts +0 -3
- package/dist/electron/modules/ocr.d.ts.map +0 -1
- package/dist/electron/modules/ocr.js +0 -188
- package/dist/electron/modules/ocr.js.map +0 -1
- package/dist/electron/modules/ollama/capability.d.ts +0 -32
- package/dist/electron/modules/ollama/capability.d.ts.map +0 -1
- package/dist/electron/modules/ollama/capability.js +0 -117
- package/dist/electron/modules/ollama/capability.js.map +0 -1
- package/dist/electron/modules/ollama/client.d.ts +0 -14
- package/dist/electron/modules/ollama/client.d.ts.map +0 -1
- package/dist/electron/modules/ollama/client.js +0 -134
- package/dist/electron/modules/ollama/client.js.map +0 -1
- package/dist/electron/modules/ollama/detector.d.ts +0 -29
- package/dist/electron/modules/ollama/detector.d.ts.map +0 -1
- package/dist/electron/modules/ollama/detector.js +0 -177
- package/dist/electron/modules/ollama/detector.js.map +0 -1
- package/dist/electron/modules/ollama/dispatcher.d.ts +0 -36
- package/dist/electron/modules/ollama/dispatcher.d.ts.map +0 -1
- package/dist/electron/modules/ollama/dispatcher.js +0 -97
- package/dist/electron/modules/ollama/dispatcher.js.map +0 -1
- package/dist/electron/modules/ollama/router.d.ts +0 -51
- package/dist/electron/modules/ollama/router.d.ts.map +0 -1
- package/dist/electron/modules/ollama/router.js +0 -201
- package/dist/electron/modules/ollama/router.js.map +0 -1
- package/dist/electron/modules/pin-window.d.ts +0 -3
- package/dist/electron/modules/pin-window.d.ts.map +0 -1
- package/dist/electron/modules/pin-window.js +0 -64
- package/dist/electron/modules/pin-window.js.map +0 -1
- package/dist/electron/modules/platform/dpi.d.ts +0 -2
- package/dist/electron/modules/platform/dpi.d.ts.map +0 -1
- package/dist/electron/modules/platform/dpi.js +0 -48
- package/dist/electron/modules/platform/dpi.js.map +0 -1
- package/dist/electron/modules/platform/errors.d.ts +0 -13
- package/dist/electron/modules/platform/errors.d.ts.map +0 -1
- package/dist/electron/modules/platform/errors.js +0 -36
- package/dist/electron/modules/platform/errors.js.map +0 -1
- package/dist/electron/modules/platform/index.d.ts +0 -24
- package/dist/electron/modules/platform/index.d.ts.map +0 -1
- package/dist/electron/modules/platform/index.js +0 -133
- package/dist/electron/modules/platform/index.js.map +0 -1
- package/dist/electron/modules/platform/interfaces.d.ts +0 -140
- package/dist/electron/modules/platform/interfaces.d.ts.map +0 -1
- package/dist/electron/modules/platform/interfaces.js +0 -14
- package/dist/electron/modules/platform/interfaces.js.map +0 -1
- package/dist/electron/modules/platform/macos/ax.d.ts +0 -15
- package/dist/electron/modules/platform/macos/ax.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/ax.js +0 -222
- package/dist/electron/modules/platform/macos/ax.js.map +0 -1
- package/dist/electron/modules/platform/macos/capture.d.ts +0 -14
- package/dist/electron/modules/platform/macos/capture.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/capture.js +0 -106
- package/dist/electron/modules/platform/macos/capture.js.map +0 -1
- package/dist/electron/modules/platform/macos/input.d.ts +0 -16
- package/dist/electron/modules/platform/macos/input.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/input.js +0 -342
- package/dist/electron/modules/platform/macos/input.js.map +0 -1
- package/dist/electron/modules/platform/macos/launch.d.ts +0 -10
- package/dist/electron/modules/platform/macos/launch.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/launch.js +0 -114
- package/dist/electron/modules/platform/macos/launch.js.map +0 -1
- package/dist/electron/modules/platform/macos/session.d.ts +0 -8
- package/dist/electron/modules/platform/macos/session.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/session.js +0 -17
- package/dist/electron/modules/platform/macos/session.js.map +0 -1
- package/dist/electron/modules/platform/macos/window.d.ts +0 -31
- package/dist/electron/modules/platform/macos/window.d.ts.map +0 -1
- package/dist/electron/modules/platform/macos/window.js +0 -271
- package/dist/electron/modules/platform/macos/window.js.map +0 -1
- package/dist/electron/modules/platform/shared.d.ts +0 -10
- package/dist/electron/modules/platform/shared.d.ts.map +0 -1
- package/dist/electron/modules/platform/shared.js +0 -201
- package/dist/electron/modules/platform/shared.js.map +0 -1
- package/dist/electron/modules/platform/types.d.ts +0 -182
- package/dist/electron/modules/platform/types.d.ts.map +0 -1
- package/dist/electron/modules/platform/types.js +0 -24
- package/dist/electron/modules/platform/types.js.map +0 -1
- package/dist/electron/modules/platform/windows/ax.d.ts +0 -15
- package/dist/electron/modules/platform/windows/ax.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/ax.js +0 -277
- package/dist/electron/modules/platform/windows/ax.js.map +0 -1
- package/dist/electron/modules/platform/windows/capture.d.ts +0 -14
- package/dist/electron/modules/platform/windows/capture.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/capture.js +0 -115
- package/dist/electron/modules/platform/windows/capture.js.map +0 -1
- package/dist/electron/modules/platform/windows/input.d.ts +0 -17
- package/dist/electron/modules/platform/windows/input.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/input.js +0 -422
- package/dist/electron/modules/platform/windows/input.js.map +0 -1
- package/dist/electron/modules/platform/windows/launch.d.ts +0 -10
- package/dist/electron/modules/platform/windows/launch.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/launch.js +0 -185
- package/dist/electron/modules/platform/windows/launch.js.map +0 -1
- package/dist/electron/modules/platform/windows/session.d.ts +0 -8
- package/dist/electron/modules/platform/windows/session.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/session.js +0 -87
- package/dist/electron/modules/platform/windows/session.js.map +0 -1
- package/dist/electron/modules/platform/windows/tray.d.ts +0 -13
- package/dist/electron/modules/platform/windows/tray.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/tray.js +0 -390
- package/dist/electron/modules/platform/windows/tray.js.map +0 -1
- package/dist/electron/modules/platform/windows/window.d.ts +0 -30
- package/dist/electron/modules/platform/windows/window.d.ts.map +0 -1
- package/dist/electron/modules/platform/windows/window.js +0 -444
- package/dist/electron/modules/platform/windows/window.js.map +0 -1
- package/dist/electron/modules/recording/ai-analysis.d.ts +0 -8
- package/dist/electron/modules/recording/ai-analysis.d.ts.map +0 -1
- package/dist/electron/modules/recording/ai-analysis.js +0 -88
- package/dist/electron/modules/recording/ai-analysis.js.map +0 -1
- package/dist/electron/modules/recording/capture-queue.d.ts +0 -48
- package/dist/electron/modules/recording/capture-queue.d.ts.map +0 -1
- package/dist/electron/modules/recording/capture-queue.js +0 -409
- package/dist/electron/modules/recording/capture-queue.js.map +0 -1
- package/dist/electron/modules/recording/cli.d.ts +0 -13
- package/dist/electron/modules/recording/cli.d.ts.map +0 -1
- package/dist/electron/modules/recording/cli.js +0 -135
- package/dist/electron/modules/recording/cli.js.map +0 -1
- package/dist/electron/modules/recording/http-api.d.ts +0 -3
- package/dist/electron/modules/recording/http-api.d.ts.map +0 -1
- package/dist/electron/modules/recording/http-api.js +0 -236
- package/dist/electron/modules/recording/http-api.js.map +0 -1
- package/dist/electron/modules/recording/index.d.ts +0 -15
- package/dist/electron/modules/recording/index.d.ts.map +0 -1
- package/dist/electron/modules/recording/index.js +0 -154
- package/dist/electron/modules/recording/index.js.map +0 -1
- package/dist/electron/modules/recording/input-hook-provider.d.ts +0 -15
- package/dist/electron/modules/recording/input-hook-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/input-hook-provider.js +0 -5
- package/dist/electron/modules/recording/input-hook-provider.js.map +0 -1
- package/dist/electron/modules/recording/mcp-tool.d.ts +0 -13
- package/dist/electron/modules/recording/mcp-tool.d.ts.map +0 -1
- package/dist/electron/modules/recording/mcp-tool.js +0 -81
- package/dist/electron/modules/recording/mcp-tool.js.map +0 -1
- package/dist/electron/modules/recording/monitor-analyzer.d.ts +0 -40
- package/dist/electron/modules/recording/monitor-analyzer.d.ts.map +0 -1
- package/dist/electron/modules/recording/monitor-analyzer.js +0 -220
- package/dist/electron/modules/recording/monitor-analyzer.js.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts +0 -28
- package/dist/electron/modules/recording/providers/change-detect-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-provider.js +0 -181
- package/dist/electron/modules/recording/providers/change-detect-provider.js.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts +0 -15
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js +0 -62
- package/dist/electron/modules/recording/providers/change-detect-shared-wrapper.js.map +0 -1
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts +0 -15
- package/dist/electron/modules/recording/providers/periodic-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/periodic-provider.js +0 -55
- package/dist/electron/modules/recording/providers/periodic-provider.js.map +0 -1
- package/dist/electron/modules/recording/providers/provider-factory.d.ts +0 -15
- package/dist/electron/modules/recording/providers/provider-factory.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/provider-factory.js +0 -97
- package/dist/electron/modules/recording/providers/provider-factory.js.map +0 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts +0 -19
- package/dist/electron/modules/recording/providers/uiohook-provider.d.ts.map +0 -1
- package/dist/electron/modules/recording/providers/uiohook-provider.js +0 -267
- package/dist/electron/modules/recording/providers/uiohook-provider.js.map +0 -1
- package/dist/electron/modules/recording/recording-session.d.ts +0 -29
- package/dist/electron/modules/recording/recording-session.d.ts.map +0 -1
- package/dist/electron/modules/recording/recording-session.js +0 -389
- package/dist/electron/modules/recording/recording-session.js.map +0 -1
- package/dist/electron/modules/recording/session-alignment.d.ts +0 -32
- package/dist/electron/modules/recording/session-alignment.d.ts.map +0 -1
- package/dist/electron/modules/recording/session-alignment.js +0 -103
- package/dist/electron/modules/recording/session-alignment.js.map +0 -1
- package/dist/electron/modules/recording/session-export.d.ts +0 -2
- package/dist/electron/modules/recording/session-export.d.ts.map +0 -1
- package/dist/electron/modules/recording/session-export.js +0 -287
- package/dist/electron/modules/recording/session-export.js.map +0 -1
- package/dist/electron/modules/recording/trigger-engine.d.ts +0 -62
- package/dist/electron/modules/recording/trigger-engine.d.ts.map +0 -1
- package/dist/electron/modules/recording/trigger-engine.js +0 -553
- package/dist/electron/modules/recording/trigger-engine.js.map +0 -1
- package/dist/electron/modules/recording/visual-diff.d.ts +0 -17
- package/dist/electron/modules/recording/visual-diff.d.ts.map +0 -1
- package/dist/electron/modules/recording/visual-diff.js +0 -109
- package/dist/electron/modules/recording/visual-diff.js.map +0 -1
- package/dist/electron/modules/redact.d.ts +0 -34
- package/dist/electron/modules/redact.d.ts.map +0 -1
- package/dist/electron/modules/redact.js +0 -583
- package/dist/electron/modules/redact.js.map +0 -1
- package/dist/electron/modules/scroll-calibration.d.ts +0 -152
- package/dist/electron/modules/scroll-calibration.d.ts.map +0 -1
- package/dist/electron/modules/scroll-calibration.js +0 -271
- package/dist/electron/modules/scroll-calibration.js.map +0 -1
- package/dist/electron/modules/scroll-capture.d.ts +0 -21
- package/dist/electron/modules/scroll-capture.d.ts.map +0 -1
- package/dist/electron/modules/scroll-capture.js +0 -134
- package/dist/electron/modules/scroll-capture.js.map +0 -1
- package/dist/electron/modules/sequence-locate.d.ts +0 -126
- package/dist/electron/modules/sequence-locate.d.ts.map +0 -1
- package/dist/electron/modules/sequence-locate.js +0 -356
- package/dist/electron/modules/sequence-locate.js.map +0 -1
- package/dist/electron/modules/store.d.ts +0 -18
- package/dist/electron/modules/store.d.ts.map +0 -1
- package/dist/electron/modules/store.js +0 -126
- package/dist/electron/modules/store.js.map +0 -1
- package/dist/electron/modules/stt/capability-probe.d.ts +0 -67
- package/dist/electron/modules/stt/capability-probe.d.ts.map +0 -1
- package/dist/electron/modules/stt/capability-probe.js +0 -331
- package/dist/electron/modules/stt/capability-probe.js.map +0 -1
- package/dist/electron/modules/stt/macos-engine.d.ts +0 -20
- package/dist/electron/modules/stt/macos-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/macos-engine.js +0 -259
- package/dist/electron/modules/stt/macos-engine.js.map +0 -1
- package/dist/electron/modules/stt/model-manager.d.ts +0 -87
- package/dist/electron/modules/stt/model-manager.d.ts.map +0 -1
- package/dist/electron/modules/stt/model-manager.js +0 -321
- package/dist/electron/modules/stt/model-manager.js.map +0 -1
- package/dist/electron/modules/stt/router.d.ts +0 -35
- package/dist/electron/modules/stt/router.d.ts.map +0 -1
- package/dist/electron/modules/stt/router.js +0 -263
- package/dist/electron/modules/stt/router.js.map +0 -1
- package/dist/electron/modules/stt/sherpa-engine.d.ts +0 -43
- package/dist/electron/modules/stt/sherpa-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/sherpa-engine.js +0 -521
- package/dist/electron/modules/stt/sherpa-engine.js.map +0 -1
- package/dist/electron/modules/stt/types.d.ts +0 -72
- package/dist/electron/modules/stt/types.d.ts.map +0 -1
- package/dist/electron/modules/stt/types.js +0 -16
- package/dist/electron/modules/stt/types.js.map +0 -1
- package/dist/electron/modules/stt/winrt-engine.d.ts +0 -20
- package/dist/electron/modules/stt/winrt-engine.d.ts.map +0 -1
- package/dist/electron/modules/stt/winrt-engine.js +0 -238
- package/dist/electron/modules/stt/winrt-engine.js.map +0 -1
- package/dist/electron/modules/tce/content-analyzer.d.ts +0 -20
- package/dist/electron/modules/tce/content-analyzer.d.ts.map +0 -1
- package/dist/electron/modules/tce/content-analyzer.js +0 -123
- package/dist/electron/modules/tce/content-analyzer.js.map +0 -1
- package/dist/electron/modules/tce/index.d.ts +0 -54
- package/dist/electron/modules/tce/index.d.ts.map +0 -1
- package/dist/electron/modules/tce/index.js +0 -174
- package/dist/electron/modules/tce/index.js.map +0 -1
- package/dist/electron/modules/tce/layout-engine.d.ts +0 -68
- package/dist/electron/modules/tce/layout-engine.d.ts.map +0 -1
- package/dist/electron/modules/tce/layout-engine.js +0 -313
- package/dist/electron/modules/tce/layout-engine.js.map +0 -1
- package/dist/electron/modules/tce/renderer.d.ts +0 -16
- package/dist/electron/modules/tce/renderer.d.ts.map +0 -1
- package/dist/electron/modules/tce/renderer.js +0 -196
- package/dist/electron/modules/tce/renderer.js.map +0 -1
- package/dist/electron/modules/tce/themes.d.ts +0 -14
- package/dist/electron/modules/tce/themes.d.ts.map +0 -1
- package/dist/electron/modules/tce/themes.js +0 -68
- package/dist/electron/modules/tce/themes.js.map +0 -1
- package/dist/electron/modules/tce/token-estimator.d.ts +0 -30
- package/dist/electron/modules/tce/token-estimator.d.ts.map +0 -1
- package/dist/electron/modules/tce/token-estimator.js +0 -59
- package/dist/electron/modules/tce/token-estimator.js.map +0 -1
- package/dist/electron/modules/telemetry.d.ts +0 -44
- package/dist/electron/modules/telemetry.d.ts.map +0 -1
- package/dist/electron/modules/telemetry.js +0 -316
- package/dist/electron/modules/telemetry.js.map +0 -1
- package/dist/electron/modules/template-match.d.ts +0 -62
- package/dist/electron/modules/template-match.d.ts.map +0 -1
- package/dist/electron/modules/template-match.js +0 -205
- package/dist/electron/modules/template-match.js.map +0 -1
- package/dist/electron/modules/tray.d.ts +0 -24
- package/dist/electron/modules/tray.d.ts.map +0 -1
- package/dist/electron/modules/tray.js +0 -349
- package/dist/electron/modules/tray.js.map +0 -1
- package/dist/electron/modules/uiohook-manager.d.ts +0 -19
- package/dist/electron/modules/uiohook-manager.d.ts.map +0 -1
- package/dist/electron/modules/uiohook-manager.js +0 -101
- package/dist/electron/modules/uiohook-manager.js.map +0 -1
- package/dist/electron/modules/undo-stack.d.ts +0 -22
- package/dist/electron/modules/undo-stack.d.ts.map +0 -1
- package/dist/electron/modules/undo-stack.js +0 -41
- package/dist/electron/modules/undo-stack.js.map +0 -1
- package/dist/electron/modules/updater.d.ts +0 -14
- package/dist/electron/modules/updater.d.ts.map +0 -1
- package/dist/electron/modules/updater.js +0 -102
- package/dist/electron/modules/updater.js.map +0 -1
- package/dist/electron/modules/usage-link.d.ts +0 -7
- package/dist/electron/modules/usage-link.d.ts.map +0 -1
- package/dist/electron/modules/usage-link.js +0 -63
- package/dist/electron/modules/usage-link.js.map +0 -1
- package/dist/electron/modules/version-check.d.ts +0 -3
- package/dist/electron/modules/version-check.d.ts.map +0 -1
- package/dist/electron/modules/version-check.js +0 -76
- package/dist/electron/modules/version-check.js.map +0 -1
- package/dist/electron/modules/watchers/active-window-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/active-window-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/active-window-watcher.js +0 -152
- package/dist/electron/modules/watchers/active-window-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/clipboard-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/clipboard-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/clipboard-watcher.js +0 -90
- package/dist/electron/modules/watchers/clipboard-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/file-watcher.d.ts +0 -5
- package/dist/electron/modules/watchers/file-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/file-watcher.js +0 -91
- package/dist/electron/modules/watchers/file-watcher.js.map +0 -1
- package/dist/electron/modules/watchers/registry.d.ts +0 -34
- package/dist/electron/modules/watchers/registry.d.ts.map +0 -1
- package/dist/electron/modules/watchers/registry.js +0 -108
- package/dist/electron/modules/watchers/registry.js.map +0 -1
- package/dist/electron/modules/watchers/screen-region-service.d.ts +0 -18
- package/dist/electron/modules/watchers/screen-region-service.d.ts.map +0 -1
- package/dist/electron/modules/watchers/screen-region-service.js +0 -126
- package/dist/electron/modules/watchers/screen-region-service.js.map +0 -1
- package/dist/electron/modules/watchers/screen-region-watcher.d.ts +0 -6
- package/dist/electron/modules/watchers/screen-region-watcher.d.ts.map +0 -1
- package/dist/electron/modules/watchers/screen-region-watcher.js +0 -70
- package/dist/electron/modules/watchers/screen-region-watcher.js.map +0 -1
- package/dist/electron/modules/window-activate.d.ts +0 -103
- package/dist/electron/modules/window-activate.d.ts.map +0 -1
- package/dist/electron/modules/window-activate.js +0 -630
- package/dist/electron/modules/window-activate.js.map +0 -1
- package/dist/electron/modules/window-input.d.ts +0 -43
- package/dist/electron/modules/window-input.d.ts.map +0 -1
- package/dist/electron/modules/window-input.js +0 -623
- package/dist/electron/modules/window-input.js.map +0 -1
- package/dist/electron/modules/window-picker.d.ts +0 -6
- package/dist/electron/modules/window-picker.d.ts.map +0 -1
- package/dist/electron/modules/window-picker.js +0 -192
- package/dist/electron/modules/window-picker.js.map +0 -1
- package/dist/electron/modules/window-resolver.d.ts +0 -35
- package/dist/electron/modules/window-resolver.d.ts.map +0 -1
- package/dist/electron/modules/window-resolver.js +0 -210
- package/dist/electron/modules/window-resolver.js.map +0 -1
- package/dist/headless/electron/ai/ai-client.js +0 -204
- package/dist/headless/electron/ai/context-builder.js +0 -27
- package/dist/headless/electron/ai/instruction-parser.js +0 -46
- package/dist/headless/electron/core/auth-store.js +0 -85
- package/dist/headless/electron/core/config.js +0 -80
- package/dist/headless/electron/core/file-logger.js +0 -73
- package/dist/headless/electron/core/input-injection/index.js +0 -30
- package/dist/headless/electron/core/input-injection/macos.js +0 -13
- package/dist/headless/electron/core/input-injection/windows.js +0 -118
- package/dist/headless/electron/core/json-store.js +0 -131
- package/dist/headless/electron/core/paths.js +0 -116
- package/dist/headless/electron/core/platform.js +0 -17
- package/dist/headless/electron/core/process-coord.js +0 -123
- package/dist/headless/electron/core/serialize-schema.js +0 -88
- package/dist/headless/electron/core/settings-schema.js +0 -1369
- package/dist/headless/electron/db/database.js +0 -636
- package/dist/headless/electron/db/models.js +0 -3
- package/dist/headless/electron/logger.js +0 -31
- package/dist/headless/electron/modules/accessibility/macos-provider.js +0 -93
- package/dist/headless/electron/modules/accessibility/provider.js +0 -51
- package/dist/headless/electron/modules/accessibility/types.js +0 -5
- package/dist/headless/electron/modules/accessibility/windows-provider.js +0 -84
- package/dist/headless/electron/modules/active-window.js +0 -75
- package/dist/headless/electron/modules/api-server.js +0 -2758
- package/dist/headless/electron/modules/auth.js +0 -192
- package/dist/headless/electron/modules/azure-speech-realtime.js +0 -542
- package/dist/headless/electron/modules/capture.js +0 -190
- package/dist/headless/electron/modules/clipboard.js +0 -25
- package/dist/headless/electron/modules/context-menu-detect.js +0 -271
- package/dist/headless/electron/modules/dictation.js +0 -1230
- package/dist/headless/electron/modules/gui-automation-errors.js +0 -78
- package/dist/headless/electron/modules/gui-automation-telemetry.js +0 -199
- package/dist/headless/electron/modules/gui-automation.js +0 -8768
- package/dist/headless/electron/modules/human-input/keyboard/timing.js +0 -56
- package/dist/headless/electron/modules/human-input/mouse/path.js +0 -79
- package/dist/headless/electron/modules/human-input/mouse/velocity.js +0 -92
- package/dist/headless/electron/modules/human-input/profiles.js +0 -123
- package/dist/headless/electron/modules/human-input/rng.js +0 -100
- package/dist/headless/electron/modules/human-input/salt.js +0 -47
- package/dist/headless/electron/modules/image-utils.js +0 -79
- package/dist/headless/electron/modules/keystroke.js +0 -52
- package/dist/headless/electron/modules/license.js +0 -174
- package/dist/headless/electron/modules/mcp-config.js +0 -145
- package/dist/headless/electron/modules/ocr.js +0 -187
- package/dist/headless/electron/modules/ollama/capability.js +0 -116
- package/dist/headless/electron/modules/ollama/client.js +0 -133
- package/dist/headless/electron/modules/ollama/detector.js +0 -176
- package/dist/headless/electron/modules/ollama/dispatcher.js +0 -96
- package/dist/headless/electron/modules/ollama/router.js +0 -200
- package/dist/headless/electron/modules/platform/dpi.js +0 -47
- package/dist/headless/electron/modules/platform/errors.js +0 -35
- package/dist/headless/electron/modules/platform/index.js +0 -132
- package/dist/headless/electron/modules/platform/interfaces.js +0 -13
- package/dist/headless/electron/modules/platform/macos/ax.js +0 -221
- package/dist/headless/electron/modules/platform/macos/capture.js +0 -105
- package/dist/headless/electron/modules/platform/macos/input.js +0 -341
- package/dist/headless/electron/modules/platform/macos/launch.js +0 -113
- package/dist/headless/electron/modules/platform/macos/session.js +0 -16
- package/dist/headless/electron/modules/platform/macos/window.js +0 -270
- package/dist/headless/electron/modules/platform/shared.js +0 -200
- package/dist/headless/electron/modules/platform/types.js +0 -23
- package/dist/headless/electron/modules/platform/windows/ax.js +0 -276
- package/dist/headless/electron/modules/platform/windows/capture.js +0 -114
- package/dist/headless/electron/modules/platform/windows/input.js +0 -421
- package/dist/headless/electron/modules/platform/windows/launch.js +0 -184
- package/dist/headless/electron/modules/platform/windows/session.js +0 -86
- package/dist/headless/electron/modules/platform/windows/tray.js +0 -389
- package/dist/headless/electron/modules/platform/windows/window.js +0 -443
- package/dist/headless/electron/modules/recording/ai-analysis.js +0 -87
- package/dist/headless/electron/modules/recording/capture-queue.js +0 -408
- package/dist/headless/electron/modules/recording/cli.js +0 -134
- package/dist/headless/electron/modules/recording/http-api.js +0 -235
- package/dist/headless/electron/modules/recording/index.js +0 -153
- package/dist/headless/electron/modules/recording/input-hook-provider.js +0 -4
- package/dist/headless/electron/modules/recording/mcp-tool.js +0 -80
- package/dist/headless/electron/modules/recording/monitor-analyzer.js +0 -219
- package/dist/headless/electron/modules/recording/providers/change-detect-provider.js +0 -180
- package/dist/headless/electron/modules/recording/providers/change-detect-shared-wrapper.js +0 -61
- package/dist/headless/electron/modules/recording/providers/periodic-provider.js +0 -54
- package/dist/headless/electron/modules/recording/providers/provider-factory.js +0 -96
- package/dist/headless/electron/modules/recording/providers/uiohook-provider.js +0 -266
- package/dist/headless/electron/modules/recording/recording-session.js +0 -388
- package/dist/headless/electron/modules/recording/session-alignment.js +0 -102
- package/dist/headless/electron/modules/recording/session-export.js +0 -286
- package/dist/headless/electron/modules/recording/trigger-engine.js +0 -552
- package/dist/headless/electron/modules/recording/visual-diff.js +0 -108
- package/dist/headless/electron/modules/redact.js +0 -582
- package/dist/headless/electron/modules/scroll-calibration.js +0 -270
- package/dist/headless/electron/modules/sequence-locate.js +0 -355
- package/dist/headless/electron/modules/store.js +0 -125
- package/dist/headless/electron/modules/stt/capability-probe.js +0 -330
- package/dist/headless/electron/modules/stt/macos-engine.js +0 -258
- package/dist/headless/electron/modules/stt/model-manager.js +0 -320
- package/dist/headless/electron/modules/stt/router.js +0 -262
- package/dist/headless/electron/modules/stt/sherpa-engine.js +0 -520
- package/dist/headless/electron/modules/stt/types.js +0 -15
- package/dist/headless/electron/modules/stt/winrt-engine.js +0 -237
- package/dist/headless/electron/modules/tce/content-analyzer.js +0 -122
- package/dist/headless/electron/modules/tce/index.js +0 -173
- package/dist/headless/electron/modules/tce/layout-engine.js +0 -312
- package/dist/headless/electron/modules/tce/renderer.js +0 -195
- package/dist/headless/electron/modules/tce/themes.js +0 -67
- package/dist/headless/electron/modules/tce/token-estimator.js +0 -58
- package/dist/headless/electron/modules/telemetry.js +0 -315
- package/dist/headless/electron/modules/template-match.js +0 -204
- package/dist/headless/electron/modules/uiohook-manager.js +0 -100
- package/dist/headless/electron/modules/undo-stack.js +0 -40
- package/dist/headless/electron/modules/watchers/active-window-watcher.js +0 -151
- package/dist/headless/electron/modules/watchers/clipboard-watcher.js +0 -89
- package/dist/headless/electron/modules/watchers/file-watcher.js +0 -90
- package/dist/headless/electron/modules/watchers/registry.js +0 -107
- package/dist/headless/electron/modules/watchers/screen-region-service.js +0 -125
- package/dist/headless/electron/modules/watchers/screen-region-watcher.js +0 -69
- package/dist/headless/electron/modules/window-activate.js +0 -629
- package/dist/headless/electron/modules/window-input.js +0 -622
- package/dist/headless/electron/modules/window-resolver.js +0 -209
- package/dist/headless/headless/capture-hotkey.js +0 -155
- package/dist/headless/headless/cli-auth.js +0 -158
- package/dist/headless/headless/cli.js +0 -278
- package/dist/headless/headless/config-cmd.js +0 -306
- package/dist/headless/headless/dictation-hotkey.js +0 -525
- package/dist/headless/headless/dictation-overlay.js +0 -218
- package/dist/headless/headless/doctor.js +0 -599
- package/dist/headless/headless/mic-capture.js +0 -406
- package/dist/headless/headless/ollama-cmd.js +0 -211
- package/dist/headless/headless/platform-headless.js +0 -233
- package/dist/headless/headless/server.js +0 -195
- package/dist/headless/headless/stt-cmd.js +0 -213
- package/dist/headless/headless/tui/index.mjs +0 -7
- package/dist/headless/headless/tui/plain-dump.js +0 -41
- package/dist/headless/headless/tui/settings-app.mjs +0 -744
- package/dist/headless/headless/tui/setup-wizard.mjs +0 -257
- package/dist/headless/headless/tui-bridge.js +0 -80
- package/dist/headless/headless/win32-text-injector.js +0 -359
- package/dist/headless/mic-capture.d.ts +0 -49
- package/dist/headless/mic-capture.d.ts.map +0 -1
- package/dist/headless/mic-capture.js +0 -407
- package/dist/headless/mic-capture.js.map +0 -1
- package/dist/headless/shared/constants.js +0 -65
- package/dist/headless/shared/design-tokens.js +0 -189
- package/dist/headless/shared/recording-types.js +0 -93
- package/dist/headless/shared/types.js +0 -3
- package/dist/shared/constants.d.ts +0 -100
- package/dist/shared/constants.d.ts.map +0 -1
- package/dist/shared/constants.js +0 -66
- package/dist/shared/constants.js.map +0 -1
- package/dist/shared/design-tokens.d.ts +0 -112
- package/dist/shared/design-tokens.d.ts.map +0 -1
- package/dist/shared/design-tokens.js +0 -190
- package/dist/shared/design-tokens.js.map +0 -1
- package/dist/shared/recording-types.d.ts +0 -186
- package/dist/shared/recording-types.d.ts.map +0 -1
- package/dist/shared/recording-types.js +0 -94
- package/dist/shared/recording-types.js.map +0 -1
- package/dist/shared/types.d.ts +0 -143
- package/dist/shared/types.d.ts.map +0 -1
- package/dist/shared/types.js +0 -4
- package/dist/shared/types.js.map +0 -1
- package/mcp-server/dist/api-client.js +0 -521
- package/mcp-server/dist/index.js +0 -2550
- package/mcp-server/dist/project-sense.js +0 -161
- package/mcp-server/dist/tool-categories.js +0 -161
- package/mcp-server/package.json +0 -22
|
@@ -1,2758 +0,0 @@
|
|
|
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.getApiPort = getApiPort;
|
|
44
|
-
exports.startApiServer = startApiServer;
|
|
45
|
-
exports.stopApiServer = stopApiServer;
|
|
46
|
-
exports.getApiAuthToken = getApiAuthToken;
|
|
47
|
-
exports.getApiServer = getApiServer;
|
|
48
|
-
exports.isApiServerRunning = isApiServerRunning;
|
|
49
|
-
const fastify_1 = __importDefault(require("fastify"));
|
|
50
|
-
const fs = __importStar(require("fs"));
|
|
51
|
-
const path = __importStar(require("path"));
|
|
52
|
-
const platform_1 = require("../core/platform");
|
|
53
|
-
const config_1 = require("../core/config");
|
|
54
|
-
// Electron imports — used when running in desktop mode.
|
|
55
|
-
// Headless mode uses platform adapter instead.
|
|
56
|
-
let electronScreen = null;
|
|
57
|
-
try {
|
|
58
|
-
electronScreen = require('electron').screen;
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
// Running headless — no Electron available
|
|
62
|
-
}
|
|
63
|
-
const logger_1 = __importDefault(require("../logger"));
|
|
64
|
-
const capture_1 = require("./capture");
|
|
65
|
-
// captureFullScreen available via captureScreen() which handles all platforms
|
|
66
|
-
const active_window_1 = require("./active-window");
|
|
67
|
-
const ai_client_1 = require("../ai/ai-client");
|
|
68
|
-
const instruction_parser_1 = require("../ai/instruction-parser");
|
|
69
|
-
const context_builder_1 = require("../ai/context-builder");
|
|
70
|
-
const auth_1 = require("./auth");
|
|
71
|
-
const license_1 = require("./license");
|
|
72
|
-
const store_1 = require("./store");
|
|
73
|
-
const ocr_1 = require("./ocr");
|
|
74
|
-
const redact_1 = require("./redact");
|
|
75
|
-
const database_1 = require("../db/database");
|
|
76
|
-
const constants_1 = require("../../shared/constants");
|
|
77
|
-
const image_utils_1 = require("./image-utils");
|
|
78
|
-
const API_PORT = 47592;
|
|
79
|
-
const API_HOST = '127.0.0.1';
|
|
80
|
-
let server = null;
|
|
81
|
-
let startTime = Date.now();
|
|
82
|
-
// Auth token generated per launch for defense-in-depth
|
|
83
|
-
let authToken = null;
|
|
84
|
-
// Settings keys that must never be exposed or modified via API
|
|
85
|
-
const BLOCKED_SETTINGS_KEYS = ['apiKeys', 'encryptedApiKeys', 'onboardingComplete'];
|
|
86
|
-
// ── Helpers ──
|
|
87
|
-
function getCapturesDir(projectDir) {
|
|
88
|
-
if (projectDir) {
|
|
89
|
-
return path.join(projectDir, '.superbased', 'captures');
|
|
90
|
-
}
|
|
91
|
-
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
92
|
-
if (custom && fs.existsSync(custom))
|
|
93
|
-
return custom;
|
|
94
|
-
return path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
95
|
-
}
|
|
96
|
-
function ensureCapturesDir(projectDir) {
|
|
97
|
-
const dir = getCapturesDir(projectDir);
|
|
98
|
-
if (!fs.existsSync(dir)) {
|
|
99
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function isValidProjectDir(dir) {
|
|
103
|
-
// Must be absolute, no traversal. We DON'T require the directory to exist
|
|
104
|
-
// here — `ensureCapturesDir` runs `fs.mkdirSync(..., { recursive: true })`
|
|
105
|
-
// which creates the whole tree on demand. The original existence check
|
|
106
|
-
// tripped on OpenCode + similar MCP clients that launch with a cwd that
|
|
107
|
-
// hasn't been materialized on disk yet (e.g., a project the agent is
|
|
108
|
-
// about to scaffold), surfacing as a confusing "Invalid projectDir" 400.
|
|
109
|
-
// Security note: absolute + no `..` is the actual security gate; an agent
|
|
110
|
-
// can already direct writes anywhere reachable from the user's session.
|
|
111
|
-
if (!path.isAbsolute(dir))
|
|
112
|
-
return false;
|
|
113
|
-
if (dir.includes('..'))
|
|
114
|
-
return false;
|
|
115
|
-
// If the path exists, it must actually be a directory — refuses an
|
|
116
|
-
// explicit file path with a misleading 400 instead of a later mkdir EEXIST.
|
|
117
|
-
if (fs.existsSync(dir) && !fs.statSync(dir).isDirectory())
|
|
118
|
-
return false;
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
function isValidScreenshotPath(filePath) {
|
|
122
|
-
if (!filePath || !path.isAbsolute(filePath))
|
|
123
|
-
return false;
|
|
124
|
-
const resolved = path.resolve(filePath);
|
|
125
|
-
if (resolved.includes('..'))
|
|
126
|
-
return false;
|
|
127
|
-
// Allow captures dir, data dir, temp dir, and project .superbased/captures dirs
|
|
128
|
-
const capturesDir = getCapturesDir();
|
|
129
|
-
const dataDir = (0, platform_1.getPlatform)().getDataDir();
|
|
130
|
-
const tmpDir = require('os').tmpdir();
|
|
131
|
-
if (resolved.startsWith(capturesDir) || resolved.startsWith(dataDir) || resolved.startsWith(tmpDir)) {
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
// Allow project-specific captures: {projectDir}/.superbased/captures/
|
|
135
|
-
const sep = path.sep;
|
|
136
|
-
const marker = `${sep}.superbased${sep}captures${sep}`;
|
|
137
|
-
if (resolved.includes(marker))
|
|
138
|
-
return true;
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
function sanitizeSettings(settings) {
|
|
142
|
-
const sanitized = { ...settings };
|
|
143
|
-
for (const key of BLOCKED_SETTINGS_KEYS) {
|
|
144
|
-
delete sanitized[key];
|
|
145
|
-
}
|
|
146
|
-
return sanitized;
|
|
147
|
-
}
|
|
148
|
-
function generateAuthToken() {
|
|
149
|
-
const { randomUUID } = require('crypto');
|
|
150
|
-
return randomUUID();
|
|
151
|
-
}
|
|
152
|
-
/** Resize a capture buffer to a target resolution for token efficiency. */
|
|
153
|
-
async function resizeCapture(buffer, resolution, maxWidth, maxHeight) {
|
|
154
|
-
const sharp = require('sharp');
|
|
155
|
-
const meta = await sharp(buffer).metadata();
|
|
156
|
-
const w = meta.width || 1920;
|
|
157
|
-
let targetW;
|
|
158
|
-
let targetH;
|
|
159
|
-
if (maxWidth || maxHeight) {
|
|
160
|
-
targetW = maxWidth;
|
|
161
|
-
targetH = maxHeight;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
switch (resolution) {
|
|
165
|
-
case 'high':
|
|
166
|
-
targetW = Math.min(w, 1568);
|
|
167
|
-
break;
|
|
168
|
-
case 'half':
|
|
169
|
-
targetW = Math.min(w, 960);
|
|
170
|
-
break;
|
|
171
|
-
case 'quarter':
|
|
172
|
-
targetW = Math.min(w, 480);
|
|
173
|
-
break;
|
|
174
|
-
case 'thumbnail':
|
|
175
|
-
targetW = Math.min(w, 200);
|
|
176
|
-
break;
|
|
177
|
-
default: return buffer; // 'full' or unspecified
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (targetW && targetW >= w && !targetH)
|
|
181
|
-
return buffer;
|
|
182
|
-
return sharp(buffer).resize({ width: targetW, height: targetH, fit: 'inside' }).png().toBuffer();
|
|
183
|
-
}
|
|
184
|
-
// ── Route Registration ──
|
|
185
|
-
function registerHealthRoutes(server) {
|
|
186
|
-
server.get('/api/health', async (_req, reply) => {
|
|
187
|
-
const version = (0, config_1.getVersion)();
|
|
188
|
-
// Capability manifest (Phase 2a.5) — agents self-check before invoking
|
|
189
|
-
// optional features (GUI automation, watchers, etc.). Lazy-load so the
|
|
190
|
-
// health endpoint stays cheap when the module is missing.
|
|
191
|
-
let guiCaps;
|
|
192
|
-
try {
|
|
193
|
-
const { getCapabilityManifest } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
194
|
-
guiCaps = getCapabilityManifest();
|
|
195
|
-
}
|
|
196
|
-
catch { /* gui-automation may be unavailable; omit from manifest */ }
|
|
197
|
-
// Ollama detection (Phase 6.1) — short form for /api/health. Full detail
|
|
198
|
-
// at /api/ollama/status. Respects `ollama.detection.enabled`.
|
|
199
|
-
let ollamaShort;
|
|
200
|
-
try {
|
|
201
|
-
const { probeOllama, toHealthShort } = await Promise.resolve().then(() => __importStar(require('./ollama/detector')));
|
|
202
|
-
const status = await probeOllama();
|
|
203
|
-
ollamaShort = toHealthShort(status);
|
|
204
|
-
}
|
|
205
|
-
catch { /* detector unavailable; omit */ }
|
|
206
|
-
// §6.11 — gui-automation telemetry. Opt-in only (guiAutomation.telemetryOptIn).
|
|
207
|
-
// When opt-in is OFF, the key is omitted entirely so /api/health response
|
|
208
|
-
// shape doesn't hint at the feature to unprivileged callers.
|
|
209
|
-
let guiTelemetry;
|
|
210
|
-
try {
|
|
211
|
-
const { getSettings } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
212
|
-
const settings = getSettings();
|
|
213
|
-
if (settings.telemetryOptIn) {
|
|
214
|
-
const { snapshot } = await Promise.resolve().then(() => __importStar(require('./gui-automation-telemetry')));
|
|
215
|
-
guiTelemetry = snapshot();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
catch { /* telemetry module optional */ }
|
|
219
|
-
return reply.code(200).send({
|
|
220
|
-
status: 'ok',
|
|
221
|
-
version,
|
|
222
|
-
uptime: Math.round((Date.now() - startTime) / 1000),
|
|
223
|
-
platform: process.platform,
|
|
224
|
-
features: {
|
|
225
|
-
capture: true,
|
|
226
|
-
ai: (0, auth_1.isAuthenticated)(),
|
|
227
|
-
gallery: true,
|
|
228
|
-
settings: true,
|
|
229
|
-
presets: true,
|
|
230
|
-
ocr: true,
|
|
231
|
-
recording: !!(0, store_1.getSetting)('recordingFeatureEnabled'),
|
|
232
|
-
},
|
|
233
|
-
capabilities: {
|
|
234
|
-
...(guiCaps || {}),
|
|
235
|
-
},
|
|
236
|
-
ollama: ollamaShort,
|
|
237
|
-
...(guiTelemetry ? { telemetry: guiTelemetry } : {}),
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
// ── Accessibility Routes (Phase 8.1 — native AX / UIA tree dump) ──
|
|
242
|
-
function registerAccessibilityRoutes(s) {
|
|
243
|
-
s.get('/api/accessibility/status', async (_request, reply) => {
|
|
244
|
-
const { getProviderStatus } = await Promise.resolve().then(() => __importStar(require('./accessibility/provider')));
|
|
245
|
-
return reply.code(200).send(getProviderStatus());
|
|
246
|
-
});
|
|
247
|
-
s.get('/api/accessibility/tree', async (request, reply) => {
|
|
248
|
-
const { getProvider } = await Promise.resolve().then(() => __importStar(require('./accessibility/provider')));
|
|
249
|
-
const provider = getProvider();
|
|
250
|
-
if (!provider) {
|
|
251
|
-
return reply.code(501).send({
|
|
252
|
-
ok: false,
|
|
253
|
-
error: 'no_provider',
|
|
254
|
-
message: 'No accessibility provider is available on this platform.',
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
const q = request.query || {};
|
|
258
|
-
const pid = q.pid !== undefined ? Number(q.pid) : undefined;
|
|
259
|
-
const hwnd = q.hwnd !== undefined ? Number(q.hwnd) : undefined;
|
|
260
|
-
const maxDepth = q.maxDepth !== undefined ? Number(q.maxDepth) : undefined;
|
|
261
|
-
const includeAttributes = q.includeAttributes === '1' || q.includeAttributes === 'true';
|
|
262
|
-
try {
|
|
263
|
-
const tree = await provider.getTree({ pid, hwnd, maxDepth, includeAttributes });
|
|
264
|
-
return reply.code(200).send({ ok: true, tree });
|
|
265
|
-
}
|
|
266
|
-
catch (err) {
|
|
267
|
-
const e = err;
|
|
268
|
-
const code = e.code ?? 'tree_failed';
|
|
269
|
-
const httpCode = code === 'accessibility_not_trusted' ? 403
|
|
270
|
-
: code === 'pid_required' || code === 'no_application_for_pid' ? 400
|
|
271
|
-
: code === 'binding_unavailable' ? 501
|
|
272
|
-
: 500;
|
|
273
|
-
return reply.code(httpCode).send({
|
|
274
|
-
ok: false,
|
|
275
|
-
error: code,
|
|
276
|
-
message: e.message ?? String(err),
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
s.get('/api/accessibility/focused', async (_request, reply) => {
|
|
281
|
-
const { getProvider } = await Promise.resolve().then(() => __importStar(require('./accessibility/provider')));
|
|
282
|
-
const provider = getProvider();
|
|
283
|
-
if (!provider) {
|
|
284
|
-
return reply.code(501).send({
|
|
285
|
-
ok: false,
|
|
286
|
-
error: 'no_provider',
|
|
287
|
-
message: 'No accessibility provider is available on this platform.',
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
const node = await provider.getFocusedElement();
|
|
292
|
-
return reply.code(200).send({ ok: true, node });
|
|
293
|
-
}
|
|
294
|
-
catch (err) {
|
|
295
|
-
const e = err;
|
|
296
|
-
const code = e.code ?? 'focused_failed';
|
|
297
|
-
const httpCode = code === 'accessibility_not_trusted' ? 403 : 500;
|
|
298
|
-
return reply.code(httpCode).send({
|
|
299
|
-
ok: false,
|
|
300
|
-
error: code,
|
|
301
|
-
message: e.message ?? String(err),
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
s.post('/api/accessibility/prompt-permission', async (_request, reply) => {
|
|
306
|
-
const { getProvider } = await Promise.resolve().then(() => __importStar(require('./accessibility/provider')));
|
|
307
|
-
const provider = getProvider();
|
|
308
|
-
if (!provider) {
|
|
309
|
-
return reply.code(501).send({
|
|
310
|
-
ok: false,
|
|
311
|
-
error: 'no_provider',
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
const state = await provider.promptForPermission();
|
|
315
|
-
return reply.code(200).send({ ok: true, permission: state });
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
// ── Ollama Routes (Phase 6.1 — detection only; routing ships in 6.2) ──
|
|
319
|
-
function registerOllamaRoutes(s) {
|
|
320
|
-
s.get('/api/ollama/status', async (request, reply) => {
|
|
321
|
-
const { probeOllama } = await Promise.resolve().then(() => __importStar(require('./ollama/detector')));
|
|
322
|
-
const q = request.query || {};
|
|
323
|
-
const force = q.force === '1' || q.force === 'true' || q.force === true;
|
|
324
|
-
const status = await probeOllama({ force });
|
|
325
|
-
return reply.code(200).send(status);
|
|
326
|
-
});
|
|
327
|
-
// POST /api/ollama/test-connection — for the first-opt-in UX flow (Phase 6.2).
|
|
328
|
-
// Body: { host?: string, model?: string }. When `host` is provided, probes
|
|
329
|
-
// that host without writing it to settings — lets users validate before
|
|
330
|
-
// committing. When `model` is provided, checks that model is present in the
|
|
331
|
-
// daemon's catalog.
|
|
332
|
-
s.post('/api/ollama/test-connection', async (request, reply) => {
|
|
333
|
-
const body = (request.body ?? {});
|
|
334
|
-
const { probeOllama, getConfiguredHost } = await Promise.resolve().then(() => __importStar(require('./ollama/detector')));
|
|
335
|
-
const hostOverride = typeof body.host === 'string' && body.host.trim().length > 0
|
|
336
|
-
? body.host.trim()
|
|
337
|
-
: undefined;
|
|
338
|
-
const effectiveHost = hostOverride ?? getConfiguredHost();
|
|
339
|
-
const status = await probeOllama({ force: true, hostOverride });
|
|
340
|
-
const result = {
|
|
341
|
-
ok: status.detected,
|
|
342
|
-
host: effectiveHost,
|
|
343
|
-
detected: status.detected,
|
|
344
|
-
version: status.version,
|
|
345
|
-
modelCount: status.models.length,
|
|
346
|
-
error: status.detected ? undefined : (status.probeError || 'Ollama did not respond'),
|
|
347
|
-
};
|
|
348
|
-
if (typeof body.model === 'string' && body.model.trim().length > 0 && status.detected) {
|
|
349
|
-
const wanted = body.model.trim();
|
|
350
|
-
// Exact match first; then tag-stripped prefix (e.g. 'llama3.1' matches 'llama3.1:8b').
|
|
351
|
-
const matches = status.models
|
|
352
|
-
.map((m) => m.name)
|
|
353
|
-
.filter((n) => n === wanted || n.startsWith(`${wanted}:`) || n.startsWith(`${wanted.split(':')[0]}:`));
|
|
354
|
-
const exact = status.models.some((m) => m.name === wanted);
|
|
355
|
-
result.modelCheck = {
|
|
356
|
-
requested: wanted,
|
|
357
|
-
found: exact,
|
|
358
|
-
matches: matches.length > 0 ? matches.slice(0, 10) : undefined,
|
|
359
|
-
};
|
|
360
|
-
if (!exact) {
|
|
361
|
-
result.ok = false;
|
|
362
|
-
result.error = matches.length > 0
|
|
363
|
-
? `Model ${wanted} not installed. Similar models present: ${matches.slice(0, 5).join(', ')}. Pull with: ollama pull ${wanted}`
|
|
364
|
-
: `Model ${wanted} not installed. Pull with: ollama pull ${wanted}`;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return reply.code(200).send(result);
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
function registerAutomationRoutes(server) {
|
|
371
|
-
// GUI automation endpoints (Phase 2a). All actions enforce the master toggle
|
|
372
|
-
// + per-action toggle + protected-apps blocklist via gui-automation.ts gates.
|
|
373
|
-
// The handlers themselves are thin — safety logic lives in the module.
|
|
374
|
-
server.post('/api/automation/click', async (req, reply) => {
|
|
375
|
-
// 0.10 adds label / automationId / role+name / caseSensitive fields.
|
|
376
|
-
// 2.1 adds clickCount + modifiers.
|
|
377
|
-
const body = req.body || {};
|
|
378
|
-
const { clickAt } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
379
|
-
const result = await clickAt({ ...body, caller: 'http' });
|
|
380
|
-
if (result.ok) {
|
|
381
|
-
const { pushUndo } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
382
|
-
pushUndo({ action: 'click', details: { x: body.x, y: body.y, window: body.window, processName: body.processName } });
|
|
383
|
-
}
|
|
384
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
385
|
-
});
|
|
386
|
-
server.post('/api/automation/type', async (req, reply) => {
|
|
387
|
-
// 0.10 adds label / automationId / role+name / caseSensitive — when set,
|
|
388
|
-
// the tool clicks the matched field first then types.
|
|
389
|
-
// 2.6 adds clearFirst (select-all + delete) and delayMs (inter-key pacing).
|
|
390
|
-
// 5.3 adds ime (JKC Unicode path via VK_PACKET / CGEventKeyboardSetUnicodeString).
|
|
391
|
-
const body = req.body || {};
|
|
392
|
-
const { typeText: typeAction } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
393
|
-
const result = await typeAction({
|
|
394
|
-
text: body.text || '',
|
|
395
|
-
confirm: body.confirm,
|
|
396
|
-
window: body.window,
|
|
397
|
-
processName: body.processName,
|
|
398
|
-
hwnd: body.hwnd,
|
|
399
|
-
restoreFocus: body.restoreFocus,
|
|
400
|
-
returnObservation: body.returnObservation,
|
|
401
|
-
label: body.label,
|
|
402
|
-
automationId: body.automationId,
|
|
403
|
-
role: body.role,
|
|
404
|
-
name: body.name,
|
|
405
|
-
caseSensitive: body.caseSensitive,
|
|
406
|
-
clearFirst: body.clearFirst,
|
|
407
|
-
delayMs: body.delayMs,
|
|
408
|
-
ime: body.ime,
|
|
409
|
-
humanize: body.humanize,
|
|
410
|
-
caller: 'http',
|
|
411
|
-
});
|
|
412
|
-
if (result.ok && body.text) {
|
|
413
|
-
const { pushUndo } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
414
|
-
pushUndo({ action: 'type', details: { text: body.text, window: body.window, processName: body.processName } });
|
|
415
|
-
}
|
|
416
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
417
|
-
});
|
|
418
|
-
server.post('/api/automation/hotkey', async (req, reply) => {
|
|
419
|
-
const body = req.body || {};
|
|
420
|
-
const { hotkey } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
421
|
-
const result = await hotkey({ combo: body.combo || '', confirm: body.confirm, window: body.window, processName: body.processName, hwnd: body.hwnd, restoreFocus: body.restoreFocus, returnObservation: body.returnObservation, method: body.method, caller: 'http' });
|
|
422
|
-
if (result.ok) {
|
|
423
|
-
const { pushUndo } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
424
|
-
pushUndo({ action: 'hotkey', details: { combo: body.combo, window: body.window, processName: body.processName } });
|
|
425
|
-
}
|
|
426
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
427
|
-
});
|
|
428
|
-
server.post('/api/automation/scroll', async (req, reply) => {
|
|
429
|
-
// 2.5 adds axis?: 'y' | 'x' for horizontal scroll.
|
|
430
|
-
const body = req.body || {};
|
|
431
|
-
const { scroll } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
432
|
-
const result = await scroll({ amount: typeof body.amount === 'number' ? body.amount : 0, confirm: body.confirm, window: body.window, processName: body.processName, hwnd: body.hwnd, restoreFocus: body.restoreFocus, method: body.method, returnObservation: body.returnObservation, unit: body.unit, axis: body.axis, anchorX: body.anchorX, anchorY: body.anchorY, recalibrate: body.recalibrate, caller: 'http' });
|
|
433
|
-
if (result.ok) {
|
|
434
|
-
const { pushUndo } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
435
|
-
pushUndo({ action: 'scroll', details: { amount: body.amount, window: body.window, processName: body.processName } });
|
|
436
|
-
}
|
|
437
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
438
|
-
});
|
|
439
|
-
// Multi-scroll multi-capture in ONE call. Calibrate → scroll one page →
|
|
440
|
-
// capture → repeat up to maxPages, stopping when no-movement detected.
|
|
441
|
-
// Returns all frames inline as a single response. Replaces N separate
|
|
442
|
-
// scroll+screenshot approvals with 1.
|
|
443
|
-
server.post('/api/automation/scroll-capture', async (req, reply) => {
|
|
444
|
-
const body = req.body || {};
|
|
445
|
-
const { runScrollCapture } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
446
|
-
const result = await runScrollCapture({
|
|
447
|
-
anchorX: typeof body.anchorX === 'number' ? body.anchorX : NaN,
|
|
448
|
-
anchorY: typeof body.anchorY === 'number' ? body.anchorY : NaN,
|
|
449
|
-
window: body.window, processName: body.processName, hwnd: body.hwnd,
|
|
450
|
-
direction: body.direction,
|
|
451
|
-
maxPages: body.maxPages,
|
|
452
|
-
confirm: body.confirm,
|
|
453
|
-
restoreFocus: body.restoreFocus,
|
|
454
|
-
recalibrate: body.recalibrate,
|
|
455
|
-
stopOnAtEnd: body.stopOnAtEnd,
|
|
456
|
-
settleMs: body.settleMs,
|
|
457
|
-
caller: 'http',
|
|
458
|
-
});
|
|
459
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
460
|
-
});
|
|
461
|
-
// Semantic scroll-until-found: loops ui_dump → search → scroll 1 page →
|
|
462
|
-
// retry under ONE activation window. Single approval covers the whole
|
|
463
|
-
// flow. Returns { found, pagesScrolled, atEnd?, match?, matches?, observation }.
|
|
464
|
-
server.post('/api/automation/scroll-to', async (req, reply) => {
|
|
465
|
-
const body = req.body || {};
|
|
466
|
-
const { runScrollTo } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
467
|
-
const result = await runScrollTo({
|
|
468
|
-
targetText: body.targetText || '',
|
|
469
|
-
direction: body.direction,
|
|
470
|
-
maxPages: body.maxPages,
|
|
471
|
-
matchMode: body.matchMode,
|
|
472
|
-
caseSensitive: body.caseSensitive,
|
|
473
|
-
confirm: body.confirm,
|
|
474
|
-
window: body.window, processName: body.processName, hwnd: body.hwnd,
|
|
475
|
-
restoreFocus: body.restoreFocus,
|
|
476
|
-
returnObservation: body.returnObservation,
|
|
477
|
-
ocrScaleFactor: body.ocrScaleFactor,
|
|
478
|
-
caller: 'http',
|
|
479
|
-
});
|
|
480
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
481
|
-
});
|
|
482
|
-
// 1.4 superbased_context_menu_select — right-click + popup detect + item click in one approval.
|
|
483
|
-
server.post('/api/automation/context-menu-select', async (req, reply) => {
|
|
484
|
-
const body = req.body || {};
|
|
485
|
-
const { contextMenuSelect } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
486
|
-
const result = await contextMenuSelect({
|
|
487
|
-
x: body.x ?? NaN, y: body.y ?? NaN, menuItemText: body.menuItemText ?? '',
|
|
488
|
-
caseSensitive: body.caseSensitive, timeoutMs: body.timeoutMs, confirm: body.confirm,
|
|
489
|
-
window: body.window, processName: body.processName, hwnd: body.hwnd,
|
|
490
|
-
restoreFocus: body.restoreFocus, returnObservation: body.returnObservation,
|
|
491
|
-
caller: 'http',
|
|
492
|
-
});
|
|
493
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
494
|
-
});
|
|
495
|
-
// 2.4 superbased_pixel_color — read the RGBA at (x, y). Pure screen-read, no input.
|
|
496
|
-
server.post('/api/automation/pixel-color', async (req, reply) => {
|
|
497
|
-
const body = req.body || {};
|
|
498
|
-
const { pixelColor } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
499
|
-
const result = await pixelColor({ x: body.x ?? NaN, y: body.y ?? NaN, expected: body.expected, tolerance: body.tolerance, confirm: body.confirm, caller: 'http' });
|
|
500
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
501
|
-
});
|
|
502
|
-
// 2.2 superbased_hover — move cursor + dwell. Reveals tooltips / hover-only UI.
|
|
503
|
-
server.post('/api/automation/hover', async (req, reply) => {
|
|
504
|
-
const body = req.body || {};
|
|
505
|
-
const { hoverAt } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
506
|
-
const result = await hoverAt({ ...body, caller: 'http' });
|
|
507
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
508
|
-
});
|
|
509
|
-
// 1.3 superbased_drag — press / interpolate / release. HTML5 DnD + native drag both supported.
|
|
510
|
-
// 3.3 — path[] with optional atMs; fromX/Y/toX/Y optional when path has ≥2 waypoints.
|
|
511
|
-
server.post('/api/automation/drag', async (req, reply) => {
|
|
512
|
-
const body = req.body || {};
|
|
513
|
-
const { dragAt } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
514
|
-
const result = await dragAt({
|
|
515
|
-
fromX: body.fromX, fromY: body.fromY, toX: body.toX, toY: body.toY,
|
|
516
|
-
path: body.path, durationMs: body.durationMs, steps: body.steps,
|
|
517
|
-
button: body.button, modifiers: body.modifiers, confirm: body.confirm,
|
|
518
|
-
window: body.window, processName: body.processName, hwnd: body.hwnd,
|
|
519
|
-
restoreFocus: body.restoreFocus, returnObservation: body.returnObservation,
|
|
520
|
-
humanize: body.humanize,
|
|
521
|
-
caller: 'http',
|
|
522
|
-
});
|
|
523
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
524
|
-
});
|
|
525
|
-
// 1.2 superbased_resize_window — presets (iphone/ipad/desktop/fullscreen) + custom.
|
|
526
|
-
server.post('/api/automation/resize-window', async (req, reply) => {
|
|
527
|
-
const body = req.body || {};
|
|
528
|
-
const { resizeWindow } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
529
|
-
const result = await resizeWindow({ ...body, caller: 'http' });
|
|
530
|
-
// resize_window is a state-changing action but not trivially reversible
|
|
531
|
-
// (needs stored original rect + display). Per Phase 5.4 judgment call L1,
|
|
532
|
-
// omit from undo-stack; agent/user restores manually if needed.
|
|
533
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
534
|
-
});
|
|
535
|
-
// 3.1 superbased_window_state — minimize/maximize/restore/close/always-on-top/move-to-display.
|
|
536
|
-
server.post('/api/automation/window-state', async (req, reply) => {
|
|
537
|
-
const body = req.body || {};
|
|
538
|
-
const { setWindowState } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
539
|
-
if (!body.action) {
|
|
540
|
-
return reply.code(400).send({ ok: false, error: 'window_state requires `action`', errorCode: 'INVALID_ARGS' });
|
|
541
|
-
}
|
|
542
|
-
const result = await setWindowState({ ...body, action: body.action, caller: 'http' });
|
|
543
|
-
// Like resize_window, window_state is state-changing but not in the undo
|
|
544
|
-
// stack (restoring close/move would need captured prior rect + display).
|
|
545
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
546
|
-
});
|
|
547
|
-
// superbased_window_bounds — read-only rect + state for a single window.
|
|
548
|
-
// Pure query — no gate. Resolves the target via the standard window /
|
|
549
|
-
// processName / hwnd pyramid then calls PlatformWindowAdapter.getBounds.
|
|
550
|
-
server.post('/api/automation/window-bounds', async (req, reply) => {
|
|
551
|
-
const body = req.body || {};
|
|
552
|
-
const { windowBounds } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
553
|
-
const result = await windowBounds({ ...body, caller: 'http' });
|
|
554
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
555
|
-
});
|
|
556
|
-
// superbased_find_title_bar_drag_region — pure query that runs ui_dump
|
|
557
|
-
// internally, walks the AX tree, and returns a safe pickup coord for
|
|
558
|
-
// title-bar drag. No gate. Same targeting as window_bounds.
|
|
559
|
-
server.post('/api/automation/find-title-bar-drag-region', async (req, reply) => {
|
|
560
|
-
const body = req.body || {};
|
|
561
|
-
const { findTitleBarDragRegion } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
562
|
-
const result = await findTitleBarDragRegion({ ...body, caller: 'http' });
|
|
563
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
564
|
-
});
|
|
565
|
-
// 3.6 superbased_display_list — enumerate displays with virtual-screen bounds + scale + primary flag + color space.
|
|
566
|
-
// Pure read — no gate. Thin wrapper around PlatformCaptureAdapter.enumerateDisplays().
|
|
567
|
-
server.get('/api/automation/display-list', async (_req, reply) => {
|
|
568
|
-
try {
|
|
569
|
-
const { platform } = await Promise.resolve().then(() => __importStar(require('./platform')));
|
|
570
|
-
const displays = await platform.capture.enumerateDisplays();
|
|
571
|
-
return reply.code(200).send({ ok: true, displays });
|
|
572
|
-
}
|
|
573
|
-
catch (err) {
|
|
574
|
-
return reply.code(500).send({ ok: false, error: err instanceof Error ? err.message : String(err), errorCode: 'TARGET_HOSTILE' });
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
// 3.5 superbased_find_image — sharp/NCC template match on downsampled buffers.
|
|
578
|
-
server.post('/api/automation/find-image', async (req, reply) => {
|
|
579
|
-
const body = req.body || {};
|
|
580
|
-
const { findImage } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
581
|
-
const result = await findImage({ ...body, caller: 'http' });
|
|
582
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
583
|
-
});
|
|
584
|
-
// 3.5 superbased_capture_template — snapshot a region + write metadata sidecar.
|
|
585
|
-
server.post('/api/automation/capture-template', async (req, reply) => {
|
|
586
|
-
const body = req.body || {};
|
|
587
|
-
const { captureTemplate } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
588
|
-
if (!body.region) {
|
|
589
|
-
return reply.code(400).send({ ok: false, error: 'capture_template requires `region`', errorCode: 'INVALID_ARGS' });
|
|
590
|
-
}
|
|
591
|
-
const result = await captureTemplate({ ...body, region: body.region, caller: 'http' });
|
|
592
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
593
|
-
});
|
|
594
|
-
// 6.7 superbased_dry_run — wrapper tool; returns errorCode: 'DRYRUN' with
|
|
595
|
-
// the named tool + args echoed back. Does not dispatch.
|
|
596
|
-
server.post('/api/automation/dry-run', async (req, reply) => {
|
|
597
|
-
const body = req.body || {};
|
|
598
|
-
const { dryRun } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
599
|
-
if (typeof body.tool !== 'string') {
|
|
600
|
-
return reply.code(400).send({ ok: false, error: 'dry_run requires `tool: string`', errorCode: 'INVALID_ARGS' });
|
|
601
|
-
}
|
|
602
|
-
const result = await dryRun({ tool: body.tool, args: body.args, caller: 'http' });
|
|
603
|
-
return reply.code(200).send(result);
|
|
604
|
-
});
|
|
605
|
-
// 6.8 superbased_replay — reconstructs a sequence from the audit log and
|
|
606
|
-
// dispatches via runSequence(). Default-safe: dryRun:true unless
|
|
607
|
-
// explicitly dryRun:false + confirm:true.
|
|
608
|
-
server.post('/api/automation/replay', async (req, reply) => {
|
|
609
|
-
const body = req.body || {};
|
|
610
|
-
const { replay } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
611
|
-
const result = await replay({ ...body, caller: 'http' });
|
|
612
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
613
|
-
});
|
|
614
|
-
// 6.9 superbased_doctor_gui_automation — hermetic probe against a canned
|
|
615
|
-
// target (Notepad / TextEdit). Bypasses launchAllowlist via direct adapter
|
|
616
|
-
// call; reports per-primitive pass/fail + TCC status (macOS).
|
|
617
|
-
server.post('/api/automation/doctor-gui-automation', async (req, reply) => {
|
|
618
|
-
const body = req.body || {};
|
|
619
|
-
const { doctorGuiAutomation } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
620
|
-
const result = await doctorGuiAutomation({ ...body, caller: 'http' });
|
|
621
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
622
|
-
});
|
|
623
|
-
// 4.7 superbased_open_url — ShellExecute (or Start-Process <browser>) with optional waitForLoad.
|
|
624
|
-
server.post('/api/automation/open-url', async (req, reply) => {
|
|
625
|
-
const body = req.body || {};
|
|
626
|
-
const { openUrl } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
627
|
-
if (typeof body.url !== 'string') {
|
|
628
|
-
return reply.code(400).send({ ok: false, error: 'open_url requires `url: string`', errorCode: 'INVALID_ARGS' });
|
|
629
|
-
}
|
|
630
|
-
const result = await openUrl({ ...body, url: body.url, caller: 'http' });
|
|
631
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
632
|
-
});
|
|
633
|
-
// 5.1 superbased_drag_file — scaffold only; returns UNSUPPORTED_YET pending
|
|
634
|
-
// the native OLE helper (IDataObject + DoDragDrop). API shape is stable.
|
|
635
|
-
server.post('/api/automation/drag-file', async (req, reply) => {
|
|
636
|
-
const body = req.body || {};
|
|
637
|
-
const { dragFile } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
638
|
-
if (typeof body.filePath !== 'string') {
|
|
639
|
-
return reply.code(400).send({ ok: false, error: 'drag_file requires `filePath: string`', errorCode: 'INVALID_ARGS' });
|
|
640
|
-
}
|
|
641
|
-
if (typeof body.toX !== 'number' || typeof body.toY !== 'number') {
|
|
642
|
-
return reply.code(400).send({ ok: false, error: 'drag_file requires `toX: number` and `toY: number`', errorCode: 'INVALID_ARGS' });
|
|
643
|
-
}
|
|
644
|
-
const result = await dragFile({ ...body, filePath: body.filePath, toX: body.toX, toY: body.toY, caller: 'http' });
|
|
645
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
646
|
-
});
|
|
647
|
-
// 5.6 superbased_virtual_desktop — Win+Ctrl+Left/Right (Windows), Ctrl+Left/Right (macOS Spaces).
|
|
648
|
-
server.post('/api/automation/virtual-desktop', async (req, reply) => {
|
|
649
|
-
const body = req.body || {};
|
|
650
|
-
const { virtualDesktop } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
651
|
-
if (body.direction !== 'left' && body.direction !== 'right') {
|
|
652
|
-
return reply.code(400).send({ ok: false, error: 'virtual_desktop requires direction: "left" | "right"', errorCode: 'INVALID_ARGS' });
|
|
653
|
-
}
|
|
654
|
-
const result = await virtualDesktop({ ...body, direction: body.direction, caller: 'http' });
|
|
655
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
656
|
-
});
|
|
657
|
-
// 5.2 superbased_tray_click — enumerate Windows tray, tooltip-match, click at resolved coords.
|
|
658
|
-
server.post('/api/automation/tray-click', async (req, reply) => {
|
|
659
|
-
const body = req.body || {};
|
|
660
|
-
const { clickTrayIcon } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
661
|
-
if (typeof body.tooltipMatch !== 'string') {
|
|
662
|
-
return reply.code(400).send({ ok: false, error: 'tray_click requires `tooltipMatch: string`', errorCode: 'INVALID_ARGS' });
|
|
663
|
-
}
|
|
664
|
-
const result = await clickTrayIcon({ ...body, tooltipMatch: body.tooltipMatch, caller: 'http' });
|
|
665
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
666
|
-
});
|
|
667
|
-
// 4.6 superbased_tab_management — browser hotkey wrappers (new/close/next/prev/switch_to).
|
|
668
|
-
server.post('/api/automation/tab-management', async (req, reply) => {
|
|
669
|
-
const body = req.body || {};
|
|
670
|
-
const { tabManagement } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
671
|
-
if (!body.tabAction) {
|
|
672
|
-
return reply.code(400).send({ ok: false, error: 'tab_management requires `tabAction`', errorCode: 'INVALID_ARGS' });
|
|
673
|
-
}
|
|
674
|
-
const result = await tabManagement({ ...body, tabAction: body.tabAction, caller: 'http' });
|
|
675
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
676
|
-
});
|
|
677
|
-
// 4.5 superbased_find_in_page — browser-hotkey wrapper: Ctrl+F → type → Enter.
|
|
678
|
-
server.post('/api/automation/find-in-page', async (req, reply) => {
|
|
679
|
-
const body = req.body || {};
|
|
680
|
-
const { findInPage } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
681
|
-
if (typeof body.query !== 'string') {
|
|
682
|
-
return reply.code(400).send({ ok: false, error: 'find_in_page requires `query: string`', errorCode: 'INVALID_ARGS' });
|
|
683
|
-
}
|
|
684
|
-
const result = await findInPage({ ...body, query: body.query, caller: 'http' });
|
|
685
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
686
|
-
});
|
|
687
|
-
// 4.3 superbased_dialog_handle — confirm/dismiss/fill_path against a modal dialog.
|
|
688
|
-
server.post('/api/automation/dialog-handle', async (req, reply) => {
|
|
689
|
-
const body = req.body || {};
|
|
690
|
-
const { dialogHandle } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
691
|
-
if (!body.dialogAction) {
|
|
692
|
-
return reply.code(400).send({ ok: false, error: 'dialog_handle requires `dialogAction`', errorCode: 'INVALID_ARGS' });
|
|
693
|
-
}
|
|
694
|
-
const result = await dialogHandle({ ...body, dialogAction: body.dialogAction, caller: 'http' });
|
|
695
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
696
|
-
});
|
|
697
|
-
// 4.2 superbased_form_fill — macro: ax-resolve + ValuePattern (or click+clearFirst+type) + Tab + optional Submit.
|
|
698
|
-
server.post('/api/automation/form-fill', async (req, reply) => {
|
|
699
|
-
const body = req.body || {};
|
|
700
|
-
const { formFill } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
701
|
-
if (!Array.isArray(body.fields)) {
|
|
702
|
-
return reply.code(400).send({ ok: false, error: 'form_fill requires `fields: [...]`', errorCode: 'INVALID_ARGS' });
|
|
703
|
-
}
|
|
704
|
-
// Assert each field has the shape formFill expects — route to the
|
|
705
|
-
// orchestrator which validates fully (value type, locator presence).
|
|
706
|
-
const result = await formFill({
|
|
707
|
-
...body,
|
|
708
|
-
fields: body.fields,
|
|
709
|
-
caller: 'http',
|
|
710
|
-
});
|
|
711
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
712
|
-
});
|
|
713
|
-
// 4.1 superbased_ax_invoke — UIA pattern invocation (Invoke/Toggle/Select/SetValue/Expand/Collapse).
|
|
714
|
-
server.post('/api/automation/ax-invoke', async (req, reply) => {
|
|
715
|
-
const body = req.body || {};
|
|
716
|
-
const { axInvoke } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
717
|
-
if (!body.pattern) {
|
|
718
|
-
return reply.code(400).send({ ok: false, error: 'ax_invoke requires `pattern`', errorCode: 'INVALID_ARGS' });
|
|
719
|
-
}
|
|
720
|
-
const result = await axInvoke({ ...body, pattern: body.pattern, caller: 'http' });
|
|
721
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
722
|
-
});
|
|
723
|
-
// 3.2 superbased_launch_app — Start-Process-backed launch gated by the allowlist.
|
|
724
|
-
server.post('/api/automation/launch-app', async (req, reply) => {
|
|
725
|
-
const body = req.body || {};
|
|
726
|
-
const { launchApp } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
727
|
-
const result = await launchApp({ ...body, caller: 'http' });
|
|
728
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
729
|
-
});
|
|
730
|
-
// UI dump — one-call "read the page": screenshot + OCR elements + AX tree
|
|
731
|
-
// in a single MCP turn. Read-only; no activation, no safety gate beyond
|
|
732
|
-
// the master toggle (if the caller can screenshot, they can ui_dump).
|
|
733
|
-
server.post('/api/automation/ui-dump', async (req, reply) => {
|
|
734
|
-
const body = req.body || {};
|
|
735
|
-
const { runUiDump } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
736
|
-
const result = await runUiDump({ ...body, caller: 'http' });
|
|
737
|
-
return reply.code(result.ok ? 200 : 500).send(result);
|
|
738
|
-
});
|
|
739
|
-
// Batched sequence — ONE approval, ONE activation window, N steps.
|
|
740
|
-
// Fixes the 20+-permission-prompt flood for any multi-step GUI task.
|
|
741
|
-
server.post('/api/automation/sequence', async (req, reply) => {
|
|
742
|
-
const body = req.body || {};
|
|
743
|
-
const { runSequence } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
744
|
-
const result = await runSequence({
|
|
745
|
-
steps: Array.isArray(body.steps) ? body.steps : [],
|
|
746
|
-
window: body.window, processName: body.processName, hwnd: body.hwnd,
|
|
747
|
-
restoreFocus: body.restoreFocus, confirm: body.confirm, stopOnError: body.stopOnError,
|
|
748
|
-
caller: 'http',
|
|
749
|
-
});
|
|
750
|
-
// Push each successful input-producing step to the undo stack. Screenshot,
|
|
751
|
-
// wait, and move are read-only / ephemeral — not recorded.
|
|
752
|
-
if (result.results && result.results.length > 0) {
|
|
753
|
-
const { pushUndo } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
754
|
-
for (let i = 0; i < result.results.length; i++) {
|
|
755
|
-
const r = result.results[i];
|
|
756
|
-
if (!r.ok)
|
|
757
|
-
continue;
|
|
758
|
-
const step = Array.isArray(body.steps) ? body.steps[i] : undefined;
|
|
759
|
-
if (!step)
|
|
760
|
-
continue;
|
|
761
|
-
if (step.action === 'click')
|
|
762
|
-
pushUndo({ action: 'click', details: { x: step.x, y: step.y, window: body.window, processName: body.processName } });
|
|
763
|
-
else if (step.action === 'type')
|
|
764
|
-
pushUndo({ action: 'type', details: { text: step.text, window: body.window, processName: body.processName } });
|
|
765
|
-
else if (step.action === 'hotkey')
|
|
766
|
-
pushUndo({ action: 'hotkey', details: { combo: step.combo, window: body.window, processName: body.processName } });
|
|
767
|
-
else if (step.action === 'scroll')
|
|
768
|
-
pushUndo({ action: 'scroll', details: { amount: step.amount, window: body.window, processName: body.processName } });
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
return reply.code(result.ok ? 200 : 403).send(result);
|
|
772
|
-
});
|
|
773
|
-
// Phase 5.4 — pop the top of the per-session undo stack and attempt to
|
|
774
|
-
// reverse the recorded action. type → press Backspace N times (N = length
|
|
775
|
-
// of the typed text). Everything else is recorded but not reversible;
|
|
776
|
-
// returns ok:false with a clear reason rather than pretending. Matches
|
|
777
|
-
// the "honest > clever" guidance from judgment call L1.
|
|
778
|
-
server.post('/api/automation/undo-last', async (_req, reply) => {
|
|
779
|
-
const { popUndo, undoDepth } = await Promise.resolve().then(() => __importStar(require('./undo-stack')));
|
|
780
|
-
const entry = popUndo();
|
|
781
|
-
if (!entry) {
|
|
782
|
-
return reply.code(200).send({ ok: false, error: 'stack_empty', message: 'No GUI automation actions to undo in this session.' });
|
|
783
|
-
}
|
|
784
|
-
if (entry.action === 'type') {
|
|
785
|
-
const text = entry.details.text ?? '';
|
|
786
|
-
const charCount = text.length;
|
|
787
|
-
if (charCount === 0) {
|
|
788
|
-
return reply.code(200).send({ ok: false, error: 'nothing_to_undo', action: entry.action, message: 'Typed empty string; nothing to reverse.' });
|
|
789
|
-
}
|
|
790
|
-
try {
|
|
791
|
-
const { hotkey } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
792
|
-
let deleted = 0;
|
|
793
|
-
for (let i = 0; i < charCount; i++) {
|
|
794
|
-
const r = await hotkey({ combo: 'Backspace', confirm: true, window: entry.details.window, processName: entry.details.processName, caller: 'http' });
|
|
795
|
-
if (!r.ok) {
|
|
796
|
-
// Partial undo — stop and report. Don't re-push; the backspaces
|
|
797
|
-
// already sent won't reverse themselves either.
|
|
798
|
-
return reply.code(200).send({
|
|
799
|
-
ok: false,
|
|
800
|
-
error: 'partial_undo',
|
|
801
|
-
action: entry.action,
|
|
802
|
-
charsDeleted: deleted,
|
|
803
|
-
charsTotal: charCount,
|
|
804
|
-
stackDepth: undoDepth(),
|
|
805
|
-
message: `Deleted ${deleted}/${charCount} characters before backspace failed.`,
|
|
806
|
-
reason: r.error ?? 'unknown',
|
|
807
|
-
});
|
|
808
|
-
}
|
|
809
|
-
deleted++;
|
|
810
|
-
}
|
|
811
|
-
return reply.code(200).send({
|
|
812
|
-
ok: true,
|
|
813
|
-
action: entry.action,
|
|
814
|
-
charsDeleted: deleted,
|
|
815
|
-
stackDepth: undoDepth(),
|
|
816
|
-
message: `Undid type action: deleted ${deleted} characters.`,
|
|
817
|
-
});
|
|
818
|
-
}
|
|
819
|
-
catch (err) {
|
|
820
|
-
return reply.code(200).send({
|
|
821
|
-
ok: false,
|
|
822
|
-
error: 'undo_failed',
|
|
823
|
-
action: entry.action,
|
|
824
|
-
message: err instanceof Error ? err.message : String(err),
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
// click / hotkey / scroll / focus-window — record only, not reversible.
|
|
829
|
-
return reply.code(200).send({
|
|
830
|
-
ok: false,
|
|
831
|
-
error: 'not_reversible',
|
|
832
|
-
action: entry.action,
|
|
833
|
-
details: entry.details,
|
|
834
|
-
stackDepth: undoDepth(),
|
|
835
|
-
message: `${entry.action} actions are not reversible. The entry has been popped from the stack; run undo_last again to reverse the next-most-recent entry.`,
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
server.post('/api/automation/focus-window', async (req, reply) => {
|
|
839
|
-
const body = req.body || {};
|
|
840
|
-
if (!body.window && !body.processName && !body.hwnd) {
|
|
841
|
-
return reply.code(400).send({ ok: false, error: 'window, processName, or hwnd is required' });
|
|
842
|
-
}
|
|
843
|
-
try {
|
|
844
|
-
const { resolveWindow } = await Promise.resolve().then(() => __importStar(require('./window-resolver')));
|
|
845
|
-
const matchResult = await resolveWindow({ window: body.window, processName: body.processName, hwnd: body.hwnd });
|
|
846
|
-
if (!matchResult.ok || !matchResult.best) {
|
|
847
|
-
return reply.code(404).send({
|
|
848
|
-
ok: false,
|
|
849
|
-
error: matchResult.error,
|
|
850
|
-
reason: matchResult.reason,
|
|
851
|
-
alternatives: matchResult.alternatives?.map((c) => ({
|
|
852
|
-
title: c.name, processName: c.processName, hwnd: c.hwnd, score: c.score, scoreReason: c.scoreReason,
|
|
853
|
-
})),
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
const match = matchResult.best;
|
|
857
|
-
const { activateWindow } = await Promise.resolve().then(() => __importStar(require('./window-activate')));
|
|
858
|
-
const diag = await activateWindow(match);
|
|
859
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
860
|
-
return reply.code(200).send({
|
|
861
|
-
ok: true,
|
|
862
|
-
method: 'window',
|
|
863
|
-
matchedWindow: {
|
|
864
|
-
title: match.name, processName: match.processName, hwnd: match.hwnd,
|
|
865
|
-
score: match.score, scoreReason: match.scoreReason,
|
|
866
|
-
},
|
|
867
|
-
alternatives: matchResult.alternatives && matchResult.alternatives.length > 0
|
|
868
|
-
? matchResult.alternatives.map((c) => ({ title: c.name, processName: c.processName, hwnd: c.hwnd, score: c.score, scoreReason: c.scoreReason }))
|
|
869
|
-
: undefined,
|
|
870
|
-
previousWindow: diag.previous || undefined,
|
|
871
|
-
verified: diag.verified,
|
|
872
|
-
attempted: diag.attempted,
|
|
873
|
-
postForeground: diag.postForeground,
|
|
874
|
-
warning: diag.verified === false
|
|
875
|
-
? `OS reports foreground is still ${diag.postForeground} (not target hwnd ${match.hwnd}). Subsequent input tools will refuse to type into the wrong window. Try clicking the target window once.`
|
|
876
|
-
: undefined,
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
catch (err) {
|
|
880
|
-
return reply.code(500).send({ ok: false, error: err.message || String(err) });
|
|
881
|
-
}
|
|
882
|
-
});
|
|
883
|
-
server.get('/api/automation/mouse-position', async (_req, reply) => {
|
|
884
|
-
const { getMousePosition } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
885
|
-
const result = await getMousePosition();
|
|
886
|
-
return reply.code(result.ok ? 200 : 500).send(result);
|
|
887
|
-
});
|
|
888
|
-
server.post('/api/automation/wait', async (req, reply) => {
|
|
889
|
-
const body = req.body || {};
|
|
890
|
-
const { waitMs } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
891
|
-
const result = await waitMs({ ms: typeof body.ms === 'number' ? body.ms : 0, caller: 'http' });
|
|
892
|
-
return reply.code(result.ok ? 200 : 400).send(result);
|
|
893
|
-
});
|
|
894
|
-
server.post('/api/automation/locate', async (req, reply) => {
|
|
895
|
-
const body = req.body || {};
|
|
896
|
-
if (!body.label)
|
|
897
|
-
return reply.code(400).send({ ok: false, error: 'label is required' });
|
|
898
|
-
const { locate } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
899
|
-
const result = await locate({ label: body.label, caseSensitive: body.caseSensitive, caller: 'http' });
|
|
900
|
-
return reply.code(result.ok ? 200 : 404).send(result);
|
|
901
|
-
});
|
|
902
|
-
// 0.9 wait_for — poll a condition until it holds or timeoutMs elapses.
|
|
903
|
-
// Read-only; no actions.* gate. Conditions: text, window, idle, pixelColor
|
|
904
|
-
// (pixelColor resolver arrives in S2 / 2.4).
|
|
905
|
-
server.post('/api/automation/wait-for', async (req, reply) => {
|
|
906
|
-
const body = req.body || {};
|
|
907
|
-
if (!body.condition || typeof body.condition !== 'object') {
|
|
908
|
-
return reply.code(400).send({ ok: false, error: 'condition is required', hint: 'Pass { condition: { type: "text"|"window"|"idle"|"pixelColor", ... }, timeoutMs }' });
|
|
909
|
-
}
|
|
910
|
-
if (typeof body.timeoutMs !== 'number' || body.timeoutMs <= 0) {
|
|
911
|
-
return reply.code(400).send({ ok: false, error: 'timeoutMs is required and must be > 0' });
|
|
912
|
-
}
|
|
913
|
-
const { runWaitFor } = await Promise.resolve().then(() => __importStar(require('./gui-automation')));
|
|
914
|
-
const result = await runWaitFor({
|
|
915
|
-
condition: body.condition,
|
|
916
|
-
timeoutMs: body.timeoutMs,
|
|
917
|
-
intervalMs: body.intervalMs,
|
|
918
|
-
caller: 'http',
|
|
919
|
-
});
|
|
920
|
-
return reply.code(result.ok ? 200 : 408).send(result);
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
function registerCaptureRoutes(server) {
|
|
924
|
-
// POST /api/capture/fullscreen
|
|
925
|
-
server.post('/api/capture/fullscreen', async (req, reply) => {
|
|
926
|
-
try {
|
|
927
|
-
const body = req.body || {};
|
|
928
|
-
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
929
|
-
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
930
|
-
}
|
|
931
|
-
const buffer = await (0, capture_1.captureScreen)();
|
|
932
|
-
// Auto-redact if enabled
|
|
933
|
-
let finalBuffer = buffer;
|
|
934
|
-
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
935
|
-
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
936
|
-
if (redactSecrets || redactPII) {
|
|
937
|
-
const result = await (0, redact_1.autoRedact)(finalBuffer, { secrets: redactSecrets, pii: redactPII });
|
|
938
|
-
finalBuffer = result.buffer;
|
|
939
|
-
}
|
|
940
|
-
ensureCapturesDir(body.projectDir);
|
|
941
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
942
|
-
const filename = `capture-${timestamp}.png`;
|
|
943
|
-
const capturesDir = getCapturesDir(body.projectDir);
|
|
944
|
-
const filepath = path.join(capturesDir, filename);
|
|
945
|
-
fs.writeFileSync(filepath, finalBuffer);
|
|
946
|
-
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
947
|
-
const { width, height } = primaryDisplay.size;
|
|
948
|
-
const captureId = (0, database_1.saveCapture)({
|
|
949
|
-
screenshotPath: filepath,
|
|
950
|
-
regionX: 0,
|
|
951
|
-
regionY: 0,
|
|
952
|
-
regionW: width,
|
|
953
|
-
regionH: height,
|
|
954
|
-
sourceApp: 'API',
|
|
955
|
-
windowTitle: 'Fullscreen Capture',
|
|
956
|
-
});
|
|
957
|
-
const imageBase64 = finalBuffer.toString('base64');
|
|
958
|
-
return reply.code(200).send({
|
|
959
|
-
captureId,
|
|
960
|
-
screenshotPath: filepath,
|
|
961
|
-
imageBase64,
|
|
962
|
-
width,
|
|
963
|
-
height,
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
catch (err) {
|
|
967
|
-
logger_1.default.error('[API] Fullscreen capture failed:', err);
|
|
968
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
969
|
-
}
|
|
970
|
-
});
|
|
971
|
-
// POST /api/capture/region
|
|
972
|
-
server.post('/api/capture/region', async (req, reply) => {
|
|
973
|
-
try {
|
|
974
|
-
const body = req.body || {};
|
|
975
|
-
if (body.x === undefined || body.y === undefined || body.width === undefined || body.height === undefined) {
|
|
976
|
-
return reply.code(400).send({ error: 'x, y, width, height are required' });
|
|
977
|
-
}
|
|
978
|
-
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
979
|
-
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
980
|
-
}
|
|
981
|
-
const region = { x: body.x, y: body.y, width: body.width, height: body.height };
|
|
982
|
-
const fullScreenBuffer = await (0, capture_1.captureScreen)();
|
|
983
|
-
let croppedBuffer = await (0, capture_1.cropRegion)(fullScreenBuffer, region);
|
|
984
|
-
// Auto-redact if enabled
|
|
985
|
-
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
986
|
-
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
987
|
-
if (redactSecrets || redactPII) {
|
|
988
|
-
const result = await (0, redact_1.autoRedact)(croppedBuffer, { secrets: redactSecrets, pii: redactPII });
|
|
989
|
-
croppedBuffer = result.buffer;
|
|
990
|
-
}
|
|
991
|
-
ensureCapturesDir(body.projectDir);
|
|
992
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
993
|
-
const filename = `capture-${timestamp}.png`;
|
|
994
|
-
const capturesDir = getCapturesDir(body.projectDir);
|
|
995
|
-
const filepath = path.join(capturesDir, filename);
|
|
996
|
-
fs.writeFileSync(filepath, croppedBuffer);
|
|
997
|
-
const captureId = (0, database_1.saveCapture)({
|
|
998
|
-
screenshotPath: filepath,
|
|
999
|
-
regionX: region.x,
|
|
1000
|
-
regionY: region.y,
|
|
1001
|
-
regionW: region.width,
|
|
1002
|
-
regionH: region.height,
|
|
1003
|
-
sourceApp: 'API',
|
|
1004
|
-
windowTitle: 'Region Capture',
|
|
1005
|
-
});
|
|
1006
|
-
const imageBase64 = croppedBuffer.toString('base64');
|
|
1007
|
-
return reply.code(200).send({
|
|
1008
|
-
captureId,
|
|
1009
|
-
screenshotPath: filepath,
|
|
1010
|
-
imageBase64,
|
|
1011
|
-
width: region.width,
|
|
1012
|
-
height: region.height,
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
catch (err) {
|
|
1016
|
-
logger_1.default.error('[API] Region capture failed:', err);
|
|
1017
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
// POST /api/capture/active-window
|
|
1021
|
-
server.post('/api/capture/active-window', async (_req, reply) => {
|
|
1022
|
-
try {
|
|
1023
|
-
const windowInfo = await (0, active_window_1.getActiveWindowInfo)();
|
|
1024
|
-
const buffer = await (0, capture_1.captureScreen)();
|
|
1025
|
-
return reply.code(200).send({
|
|
1026
|
-
windowInfo,
|
|
1027
|
-
imageBase64: buffer.toString('base64'),
|
|
1028
|
-
});
|
|
1029
|
-
}
|
|
1030
|
-
catch (err) {
|
|
1031
|
-
logger_1.default.error('[API] Active window capture failed:', err);
|
|
1032
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1035
|
-
// POST /api/capture/ocr
|
|
1036
|
-
server.post('/api/capture/ocr', async (req, reply) => {
|
|
1037
|
-
try {
|
|
1038
|
-
const body = req.body || {};
|
|
1039
|
-
let imageBuffer;
|
|
1040
|
-
if (body.imageBase64) {
|
|
1041
|
-
imageBuffer = Buffer.from(body.imageBase64, 'base64');
|
|
1042
|
-
}
|
|
1043
|
-
else if (body.screenshotPath) {
|
|
1044
|
-
if (!isValidScreenshotPath(body.screenshotPath) || !fs.existsSync(body.screenshotPath)) {
|
|
1045
|
-
return reply.code(400).send({ error: 'Invalid or inaccessible screenshotPath' });
|
|
1046
|
-
}
|
|
1047
|
-
imageBuffer = fs.readFileSync(body.screenshotPath);
|
|
1048
|
-
}
|
|
1049
|
-
else {
|
|
1050
|
-
return reply.code(400).send({ error: 'imageBase64 or screenshotPath required' });
|
|
1051
|
-
}
|
|
1052
|
-
const text = await (0, ocr_1.performOCR)(imageBuffer);
|
|
1053
|
-
return reply.code(200).send({ text });
|
|
1054
|
-
}
|
|
1055
|
-
catch (err) {
|
|
1056
|
-
logger_1.default.error('[API] OCR failed:', err);
|
|
1057
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
function registerAIRoutes(server) {
|
|
1062
|
-
// POST /api/ai/process
|
|
1063
|
-
server.post('/api/ai/process', async (req, reply) => {
|
|
1064
|
-
try {
|
|
1065
|
-
const body = req.body || {};
|
|
1066
|
-
if (!body.instruction) {
|
|
1067
|
-
return reply.code(400).send({ error: 'instruction is required' });
|
|
1068
|
-
}
|
|
1069
|
-
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
1070
|
-
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
1071
|
-
}
|
|
1072
|
-
// Auth gate is deferred to the provider router (Phase 6.3). When the
|
|
1073
|
-
// resolver picks cloud, it enforces sign-in via structured error; when
|
|
1074
|
-
// it picks Ollama, signed-out users with Ollama configured succeed.
|
|
1075
|
-
// The !isAuthenticated() early return is deliberately removed here.
|
|
1076
|
-
// Get image(s)
|
|
1077
|
-
const imagesBase64 = [];
|
|
1078
|
-
let captureSourceApp = null;
|
|
1079
|
-
let captureWindowTitle = null;
|
|
1080
|
-
if (body.captureId) {
|
|
1081
|
-
const capture = (0, database_1.getCapture)(body.captureId);
|
|
1082
|
-
if (!capture || !capture.screenshot_path) {
|
|
1083
|
-
return reply.code(404).send({ error: `Capture ${body.captureId} not found` });
|
|
1084
|
-
}
|
|
1085
|
-
if (fs.existsSync(capture.screenshot_path)) {
|
|
1086
|
-
const buf = fs.readFileSync(capture.screenshot_path);
|
|
1087
|
-
imagesBase64.push(await (0, image_utils_1.resizeImageForAI)(buf));
|
|
1088
|
-
captureSourceApp = capture.source_app || null;
|
|
1089
|
-
captureWindowTitle = capture.window_title || null;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
else if (body.imageBase64) {
|
|
1093
|
-
imagesBase64.push(body.imageBase64);
|
|
1094
|
-
}
|
|
1095
|
-
else if (body.screenshotPath) {
|
|
1096
|
-
if (!isValidScreenshotPath(body.screenshotPath) || !fs.existsSync(body.screenshotPath)) {
|
|
1097
|
-
return reply.code(400).send({ error: 'Invalid or inaccessible screenshotPath' });
|
|
1098
|
-
}
|
|
1099
|
-
const buf = fs.readFileSync(body.screenshotPath);
|
|
1100
|
-
imagesBase64.push(await (0, image_utils_1.resizeImageForAI)(buf));
|
|
1101
|
-
}
|
|
1102
|
-
else {
|
|
1103
|
-
// No image — capture fullscreen automatically
|
|
1104
|
-
const buffer = await (0, capture_1.captureScreen)();
|
|
1105
|
-
ensureCapturesDir(body.projectDir);
|
|
1106
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
1107
|
-
const filename = `capture-${timestamp}.png`;
|
|
1108
|
-
const capturesDir = getCapturesDir(body.projectDir);
|
|
1109
|
-
const filepath = path.join(capturesDir, filename);
|
|
1110
|
-
fs.writeFileSync(filepath, buffer);
|
|
1111
|
-
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
1112
|
-
const { width, height } = primaryDisplay.size;
|
|
1113
|
-
(0, database_1.saveCapture)({
|
|
1114
|
-
screenshotPath: filepath,
|
|
1115
|
-
regionX: 0,
|
|
1116
|
-
regionY: 0,
|
|
1117
|
-
regionW: width,
|
|
1118
|
-
regionH: height,
|
|
1119
|
-
sourceApp: 'API',
|
|
1120
|
-
windowTitle: 'Auto Capture for AI',
|
|
1121
|
-
});
|
|
1122
|
-
imagesBase64.push(await (0, image_utils_1.resizeImageForAI)(buffer));
|
|
1123
|
-
}
|
|
1124
|
-
// Parse instruction and build prompt
|
|
1125
|
-
const { instruction } = (0, instruction_parser_1.parseInstruction)(body.instruction);
|
|
1126
|
-
const systemPrompt = (0, store_1.getSetting)('systemPrompt') || '';
|
|
1127
|
-
const contexts = imagesBase64.map((imageBase64, i) => ({
|
|
1128
|
-
imageBase64,
|
|
1129
|
-
sourceApp: captureSourceApp,
|
|
1130
|
-
windowTitle: captureWindowTitle,
|
|
1131
|
-
regionIndex: i,
|
|
1132
|
-
}));
|
|
1133
|
-
const fullPrompt = (systemPrompt ? systemPrompt + '\n\n' : '') + (0, context_builder_1.buildPrompt)(instruction, contexts);
|
|
1134
|
-
// Dispatch through the provider router (Phase 6.3). For vision-bearing
|
|
1135
|
-
// requests the pre-check runs before any streaming work; errors surface
|
|
1136
|
-
// with structured remediation hints. Task is 'vision' when images
|
|
1137
|
-
// accompany the request; otherwise 'chat' — mirrors how the user
|
|
1138
|
-
// perceives the call (superbased_ai with /extract on a screenshot is
|
|
1139
|
-
// a vision call from the routing perspective).
|
|
1140
|
-
let fullResponse = '';
|
|
1141
|
-
let aiProvider = 'cloud';
|
|
1142
|
-
let aiModel;
|
|
1143
|
-
try {
|
|
1144
|
-
const { dispatchAI, DispatcherError } = await Promise.resolve().then(() => __importStar(require('./ollama/dispatcher')));
|
|
1145
|
-
const dispatch = await dispatchAI({
|
|
1146
|
-
task: imagesBase64.length > 0 ? 'vision' : 'chat',
|
|
1147
|
-
provider: body.provider,
|
|
1148
|
-
model: body.model,
|
|
1149
|
-
forceVision: body.forceVision,
|
|
1150
|
-
instruction: fullPrompt,
|
|
1151
|
-
imagesBase64,
|
|
1152
|
-
});
|
|
1153
|
-
aiProvider = dispatch.resolution.provider;
|
|
1154
|
-
aiModel = dispatch.resolution.model;
|
|
1155
|
-
for await (const chunk of dispatch.stream) {
|
|
1156
|
-
fullResponse += chunk;
|
|
1157
|
-
}
|
|
1158
|
-
void DispatcherError; // keep type in scope for catch block below
|
|
1159
|
-
}
|
|
1160
|
-
catch (err) {
|
|
1161
|
-
// Structured dispatcher error — surface code + hint in the body.
|
|
1162
|
-
if (err && typeof err === 'object' && 'code' in err) {
|
|
1163
|
-
const de = err;
|
|
1164
|
-
const httpCode = de.code === 'not_signed_in' ? 401 : 400;
|
|
1165
|
-
return reply.code(httpCode).send({
|
|
1166
|
-
error: de.message,
|
|
1167
|
-
code: de.code,
|
|
1168
|
-
hint: de.hint,
|
|
1169
|
-
provider: de.provider,
|
|
1170
|
-
});
|
|
1171
|
-
}
|
|
1172
|
-
// Non-structured (network / upstream) error — use 502 so callers can
|
|
1173
|
-
// distinguish from validation problems.
|
|
1174
|
-
return reply.code(502).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1175
|
-
}
|
|
1176
|
-
// Save AI response to capture if captureId provided
|
|
1177
|
-
if (body.captureId) {
|
|
1178
|
-
(0, database_1.updateCapture)(body.captureId, {
|
|
1179
|
-
aiResponse: fullResponse,
|
|
1180
|
-
instruction: body.instruction,
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
return reply.code(200).send({
|
|
1184
|
-
response: fullResponse,
|
|
1185
|
-
provider: aiProvider,
|
|
1186
|
-
model: aiModel,
|
|
1187
|
-
});
|
|
1188
|
-
}
|
|
1189
|
-
catch (err) {
|
|
1190
|
-
logger_1.default.error('[API] AI process failed:', err);
|
|
1191
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
// GET /api/ai/commands
|
|
1195
|
-
server.get('/api/ai/commands', async (_req, reply) => {
|
|
1196
|
-
const commands = (0, instruction_parser_1.getAvailableCommands)();
|
|
1197
|
-
return reply.code(200).send({ commands });
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
function registerGalleryRoutes(server) {
|
|
1201
|
-
// GET /api/gallery/captures
|
|
1202
|
-
server.get('/api/gallery/captures', async (req, reply) => {
|
|
1203
|
-
const query = req.query;
|
|
1204
|
-
const limit = parseInt(query.limit || '50', 10);
|
|
1205
|
-
const captures = (0, database_1.getCaptures)(limit);
|
|
1206
|
-
return reply.code(200).send({ captures, total: captures.length });
|
|
1207
|
-
});
|
|
1208
|
-
// GET /api/gallery/captures/:id
|
|
1209
|
-
server.get('/api/gallery/captures/:id', async (req, reply) => {
|
|
1210
|
-
const params = req.params;
|
|
1211
|
-
const id = parseInt(params.id, 10);
|
|
1212
|
-
if (isNaN(id)) {
|
|
1213
|
-
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
1214
|
-
}
|
|
1215
|
-
const capture = (0, database_1.getCapture)(id);
|
|
1216
|
-
if (!capture) {
|
|
1217
|
-
return reply.code(404).send({ error: 'Capture not found' });
|
|
1218
|
-
}
|
|
1219
|
-
return reply.code(200).send({ capture });
|
|
1220
|
-
});
|
|
1221
|
-
// GET /api/gallery/search
|
|
1222
|
-
server.get('/api/gallery/search', async (req, reply) => {
|
|
1223
|
-
const query = req.query;
|
|
1224
|
-
if (!query.q) {
|
|
1225
|
-
return reply.code(400).send({ error: 'q parameter required' });
|
|
1226
|
-
}
|
|
1227
|
-
const limit = parseInt(query.limit || '50', 10);
|
|
1228
|
-
const captures = (0, database_1.searchCaptures)(query.q, limit);
|
|
1229
|
-
return reply.code(200).send({ captures });
|
|
1230
|
-
});
|
|
1231
|
-
// GET /api/gallery/stats
|
|
1232
|
-
server.get('/api/gallery/stats', async (_req, reply) => {
|
|
1233
|
-
const stats = (0, database_1.getCaptureStats)();
|
|
1234
|
-
return reply.code(200).send(stats);
|
|
1235
|
-
});
|
|
1236
|
-
// PUT /api/gallery/captures/:id/tags
|
|
1237
|
-
server.put('/api/gallery/captures/:id/tags', async (req, reply) => {
|
|
1238
|
-
const params = req.params;
|
|
1239
|
-
const id = parseInt(params.id, 10);
|
|
1240
|
-
if (isNaN(id)) {
|
|
1241
|
-
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
1242
|
-
}
|
|
1243
|
-
const body = req.body || {};
|
|
1244
|
-
if (body.tags === undefined) {
|
|
1245
|
-
return reply.code(400).send({ error: 'tags field required' });
|
|
1246
|
-
}
|
|
1247
|
-
(0, database_1.updateCaptureTags)(id, body.tags);
|
|
1248
|
-
return reply.code(200).send({ success: true });
|
|
1249
|
-
});
|
|
1250
|
-
// PUT /api/gallery/captures/:id/notes
|
|
1251
|
-
server.put('/api/gallery/captures/:id/notes', async (req, reply) => {
|
|
1252
|
-
const params = req.params;
|
|
1253
|
-
const id = parseInt(params.id, 10);
|
|
1254
|
-
if (isNaN(id)) {
|
|
1255
|
-
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
1256
|
-
}
|
|
1257
|
-
const body = req.body || {};
|
|
1258
|
-
if (body.notes === undefined) {
|
|
1259
|
-
return reply.code(400).send({ error: 'notes field required' });
|
|
1260
|
-
}
|
|
1261
|
-
(0, database_1.updateCaptureNotes)(id, body.notes);
|
|
1262
|
-
return reply.code(200).send({ success: true });
|
|
1263
|
-
});
|
|
1264
|
-
}
|
|
1265
|
-
function registerSettingsRoutes(server) {
|
|
1266
|
-
// GET /api/settings
|
|
1267
|
-
server.get('/api/settings', async (_req, reply) => {
|
|
1268
|
-
const settings = (0, store_1.getAllSettings)();
|
|
1269
|
-
const safe = sanitizeSettings(settings);
|
|
1270
|
-
return reply.code(200).send({ settings: safe });
|
|
1271
|
-
});
|
|
1272
|
-
// PUT /api/settings
|
|
1273
|
-
server.put('/api/settings', async (req, reply) => {
|
|
1274
|
-
const body = req.body || {};
|
|
1275
|
-
if (!body.key) {
|
|
1276
|
-
return reply.code(400).send({ error: 'key is required' });
|
|
1277
|
-
}
|
|
1278
|
-
if (BLOCKED_SETTINGS_KEYS.includes(body.key)) {
|
|
1279
|
-
return reply.code(403).send({ error: `Setting '${body.key}' cannot be modified via API` });
|
|
1280
|
-
}
|
|
1281
|
-
(0, store_1.setSetting)(body.key, body.value);
|
|
1282
|
-
// Flush ollama detection cache when any ollama.* key changes so the next
|
|
1283
|
-
// probe sees the new enabled state / future 6.2+ host override immediately.
|
|
1284
|
-
if (typeof body.key === 'string' && body.key.startsWith('ollama.')) {
|
|
1285
|
-
try {
|
|
1286
|
-
const { flushOllamaCache } = await Promise.resolve().then(() => __importStar(require('./ollama/detector')));
|
|
1287
|
-
flushOllamaCache();
|
|
1288
|
-
}
|
|
1289
|
-
catch { /* detector unavailable; settings write still succeeded */ }
|
|
1290
|
-
}
|
|
1291
|
-
return reply.code(200).send({ success: true });
|
|
1292
|
-
});
|
|
1293
|
-
// GET /api/settings/provider
|
|
1294
|
-
server.get('/api/settings/provider', async (_req, reply) => {
|
|
1295
|
-
return reply.code(200).send({
|
|
1296
|
-
provider: 'server-managed',
|
|
1297
|
-
model: 'server-managed',
|
|
1298
|
-
hasKey: (0, auth_1.isAuthenticated)(),
|
|
1299
|
-
});
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
function registerPresetsRoutes(server) {
|
|
1303
|
-
// GET /api/presets
|
|
1304
|
-
server.get('/api/presets', async (_req, reply) => {
|
|
1305
|
-
const presets = (0, database_1.getPresets)();
|
|
1306
|
-
return reply.code(200).send({ presets });
|
|
1307
|
-
});
|
|
1308
|
-
// POST /api/presets
|
|
1309
|
-
server.post('/api/presets', async (req, reply) => {
|
|
1310
|
-
const body = req.body || {};
|
|
1311
|
-
if (!body.name || !body.instruction) {
|
|
1312
|
-
return reply.code(400).send({ error: 'name and instruction are required' });
|
|
1313
|
-
}
|
|
1314
|
-
const id = (0, database_1.createPreset)({
|
|
1315
|
-
name: body.name,
|
|
1316
|
-
instruction: body.instruction,
|
|
1317
|
-
shortcut: body.shortcut || null,
|
|
1318
|
-
});
|
|
1319
|
-
return reply.code(201).send({ id });
|
|
1320
|
-
});
|
|
1321
|
-
// PUT /api/presets/:id
|
|
1322
|
-
server.put('/api/presets/:id', async (req, reply) => {
|
|
1323
|
-
const params = req.params;
|
|
1324
|
-
const id = parseInt(params.id, 10);
|
|
1325
|
-
if (isNaN(id)) {
|
|
1326
|
-
return reply.code(400).send({ error: 'Invalid preset ID' });
|
|
1327
|
-
}
|
|
1328
|
-
const body = req.body || {};
|
|
1329
|
-
if (!body.name || !body.instruction) {
|
|
1330
|
-
return reply.code(400).send({ error: 'name and instruction are required' });
|
|
1331
|
-
}
|
|
1332
|
-
(0, database_1.updatePreset)({
|
|
1333
|
-
id,
|
|
1334
|
-
name: body.name,
|
|
1335
|
-
instruction: body.instruction,
|
|
1336
|
-
shortcut: body.shortcut || null,
|
|
1337
|
-
});
|
|
1338
|
-
return reply.code(200).send({ success: true });
|
|
1339
|
-
});
|
|
1340
|
-
// DELETE /api/presets/:id
|
|
1341
|
-
server.delete('/api/presets/:id', async (req, reply) => {
|
|
1342
|
-
const params = req.params;
|
|
1343
|
-
const id = parseInt(params.id, 10);
|
|
1344
|
-
if (isNaN(id)) {
|
|
1345
|
-
return reply.code(400).send({ error: 'Invalid preset ID' });
|
|
1346
|
-
}
|
|
1347
|
-
(0, database_1.deletePreset)(id);
|
|
1348
|
-
return reply.code(200).send({ success: true });
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
|
-
// ── Token Compression Engine Routes ──
|
|
1352
|
-
function registerCompressRoutes(server) {
|
|
1353
|
-
server.post('/api/compress', async (req, reply) => {
|
|
1354
|
-
try {
|
|
1355
|
-
const body = (req.body || {});
|
|
1356
|
-
if (!body.text) {
|
|
1357
|
-
return reply.code(400).send({ error: 'Missing required field: text' });
|
|
1358
|
-
}
|
|
1359
|
-
const { compressText } = await Promise.resolve().then(() => __importStar(require('./tce')));
|
|
1360
|
-
const settings = {};
|
|
1361
|
-
if (body.preset)
|
|
1362
|
-
settings.preset = body.preset;
|
|
1363
|
-
if (body.columns)
|
|
1364
|
-
settings.columnMode = body.columns === 'auto' ? 'auto' : Number(body.columns);
|
|
1365
|
-
if (body.theme)
|
|
1366
|
-
settings.theme = body.theme;
|
|
1367
|
-
if (body.render_style)
|
|
1368
|
-
settings.renderStyle = body.render_style;
|
|
1369
|
-
if (body.overlap_lines !== undefined)
|
|
1370
|
-
settings.overlapLines = body.overlap_lines;
|
|
1371
|
-
const result = await compressText(body.text, settings);
|
|
1372
|
-
return reply.code(200).send({
|
|
1373
|
-
pages: result.pages.map((p) => ({
|
|
1374
|
-
page_number: p.pageNumber,
|
|
1375
|
-
total_pages: p.totalPages,
|
|
1376
|
-
image_tokens: p.imageTokens,
|
|
1377
|
-
line_range: p.lineRange,
|
|
1378
|
-
data: p.buffer.toString('base64'),
|
|
1379
|
-
})),
|
|
1380
|
-
metadata: {
|
|
1381
|
-
total_image_tokens: result.metadata.totalImageTokens,
|
|
1382
|
-
estimated_text_tokens: result.metadata.estimatedTextTokens,
|
|
1383
|
-
compression_ratio: result.metadata.compressionRatio,
|
|
1384
|
-
savings_percent: result.metadata.savingsPercent,
|
|
1385
|
-
columns_used: result.metadata.columnsUsed,
|
|
1386
|
-
preset_used: result.metadata.presetUsed,
|
|
1387
|
-
resolution: result.metadata.resolution,
|
|
1388
|
-
content_type: result.metadata.contentType,
|
|
1389
|
-
language: result.metadata.language,
|
|
1390
|
-
},
|
|
1391
|
-
});
|
|
1392
|
-
}
|
|
1393
|
-
catch (err) {
|
|
1394
|
-
logger_1.default.error('[API] Compress failed:', err);
|
|
1395
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
}
|
|
1399
|
-
// ── STT Routes (Phase 4a — capability probe + model download) ──
|
|
1400
|
-
function registerSTTRoutes(s) {
|
|
1401
|
-
s.get('/api/stt/status', async (_request, reply) => {
|
|
1402
|
-
const { computeCapabilities, flushCapabilitiesCache } = await Promise.resolve().then(() => __importStar(require('./stt/capability-probe')));
|
|
1403
|
-
// Always recompute when the caller explicitly asks — status is meant
|
|
1404
|
-
// to be authoritative, not cached. Subsequent probe() calls from the
|
|
1405
|
-
// routing layer will repopulate the cache on demand.
|
|
1406
|
-
flushCapabilitiesCache();
|
|
1407
|
-
const report = computeCapabilities({ signedIn: (0, auth_1.isAuthenticated)() });
|
|
1408
|
-
return reply.code(200).send(report);
|
|
1409
|
-
});
|
|
1410
|
-
s.post('/api/stt/download-model', async (request, reply) => {
|
|
1411
|
-
const body = (request.body ?? {});
|
|
1412
|
-
const modelId = typeof body.modelId === 'string' && body.modelId ? body.modelId : '';
|
|
1413
|
-
if (!modelId) {
|
|
1414
|
-
return reply.code(400).send({ ok: false, error: 'missing_model_id', message: 'modelId is required' });
|
|
1415
|
-
}
|
|
1416
|
-
if (body.explicitConsent !== true) {
|
|
1417
|
-
return reply.code(403).send({
|
|
1418
|
-
ok: false,
|
|
1419
|
-
error: 'consent_required',
|
|
1420
|
-
modelId,
|
|
1421
|
-
message: 'explicitConsent:true is required. Downloads do not run implicitly.',
|
|
1422
|
-
consent_command: `superbased stt download ${modelId}`,
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
reply.raw.writeHead(200, {
|
|
1426
|
-
'Content-Type': 'text/event-stream',
|
|
1427
|
-
'Cache-Control': 'no-cache',
|
|
1428
|
-
'Connection': 'keep-alive',
|
|
1429
|
-
'X-Accel-Buffering': 'no',
|
|
1430
|
-
});
|
|
1431
|
-
const send = (event, data) => {
|
|
1432
|
-
try {
|
|
1433
|
-
reply.raw.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
|
|
1434
|
-
}
|
|
1435
|
-
catch {
|
|
1436
|
-
// client disconnected
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
send('connected', { modelId });
|
|
1440
|
-
const keepalive = setInterval(() => {
|
|
1441
|
-
try {
|
|
1442
|
-
reply.raw.write(':keepalive\n\n');
|
|
1443
|
-
}
|
|
1444
|
-
catch {
|
|
1445
|
-
clearInterval(keepalive);
|
|
1446
|
-
}
|
|
1447
|
-
}, 15000);
|
|
1448
|
-
try {
|
|
1449
|
-
const { ensureModel } = await Promise.resolve().then(() => __importStar(require('./stt/model-manager')));
|
|
1450
|
-
const result = await ensureModel({
|
|
1451
|
-
modelId,
|
|
1452
|
-
explicitConsent: true,
|
|
1453
|
-
onProgress: (p) => send('progress', p),
|
|
1454
|
-
});
|
|
1455
|
-
send('result', result);
|
|
1456
|
-
}
|
|
1457
|
-
catch (err) {
|
|
1458
|
-
send('result', { ok: false, error: 'io_error', modelId, message: err instanceof Error ? err.message : String(err) });
|
|
1459
|
-
}
|
|
1460
|
-
finally {
|
|
1461
|
-
clearInterval(keepalive);
|
|
1462
|
-
reply.raw.end();
|
|
1463
|
-
}
|
|
1464
|
-
return reply;
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
// ── Project-state route (Phase 5.1 — orientation) ──
|
|
1468
|
-
function registerProjectRoutes(s) {
|
|
1469
|
-
// Bundled state endpoint so the `superbased_project` MCP tool only has to
|
|
1470
|
-
// make one HTTP round-trip instead of three (captures + dictation history
|
|
1471
|
-
// + recording status). The MCP server combines this with local-process
|
|
1472
|
-
// work (cwd, git info, framework detection) to produce the final tool
|
|
1473
|
-
// response. See mcp-server/src/project-sense.ts for the local side.
|
|
1474
|
-
s.get('/api/project/server-state', async (_request, reply) => {
|
|
1475
|
-
try {
|
|
1476
|
-
const capturesRaw = (0, database_1.getCaptures)(3);
|
|
1477
|
-
const recentCaptures = capturesRaw.map((c) => ({
|
|
1478
|
-
id: c.id,
|
|
1479
|
-
timestamp: c.timestamp,
|
|
1480
|
-
filename: c.filename ?? null,
|
|
1481
|
-
windowTitle: c.window_title ?? null,
|
|
1482
|
-
}));
|
|
1483
|
-
const dictationEntries = (0, database_1.getDictationHistory)(1);
|
|
1484
|
-
const lastDictation = dictationEntries[0]
|
|
1485
|
-
? {
|
|
1486
|
-
id: dictationEntries[0].id,
|
|
1487
|
-
timestamp: dictationEntries[0].timestamp,
|
|
1488
|
-
textPreview: (dictationEntries[0].text || '').slice(0, 200),
|
|
1489
|
-
}
|
|
1490
|
-
: null;
|
|
1491
|
-
// Recording state — left null for now. The recording module doesn't
|
|
1492
|
-
// expose a direct in-process "is there an active session?" getter
|
|
1493
|
-
// that's safe to call from here without triggering module
|
|
1494
|
-
// initialization side effects. Agents can call `superbased_recording
|
|
1495
|
-
// action=status` when they specifically need it. Field kept in the
|
|
1496
|
-
// response shape so adding it back later is non-breaking.
|
|
1497
|
-
const activeRecording = null;
|
|
1498
|
-
return reply.code(200).send({
|
|
1499
|
-
recentCaptures,
|
|
1500
|
-
lastDictation,
|
|
1501
|
-
activeRecording,
|
|
1502
|
-
serverVersion: (0, config_1.getVersion)(),
|
|
1503
|
-
});
|
|
1504
|
-
}
|
|
1505
|
-
catch (err) {
|
|
1506
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1507
|
-
}
|
|
1508
|
-
});
|
|
1509
|
-
// Bundled capture + OCR + window + timestamp for `superbased_workspace_sync`.
|
|
1510
|
-
// One HTTP call where an agent would otherwise chain capture → ocr →
|
|
1511
|
-
// window_list. Runs server-side so the image never leaves the box.
|
|
1512
|
-
s.get('/api/workspace/sync', async (_request, reply) => {
|
|
1513
|
-
try {
|
|
1514
|
-
const imageBuffer = await (0, capture_1.captureScreen)();
|
|
1515
|
-
const timestamp = new Date().toISOString();
|
|
1516
|
-
const active = await (0, active_window_1.getActiveWindowInfo)();
|
|
1517
|
-
// Run OCR on the capture. performOCR returns the full extracted text
|
|
1518
|
-
// directly; truncate long results so the JSON payload stays tractable
|
|
1519
|
-
// (agents who want the full OCR can call superbased_ocr separately).
|
|
1520
|
-
let ocrText = '';
|
|
1521
|
-
let ocrTruncated = false;
|
|
1522
|
-
try {
|
|
1523
|
-
const full = await (0, ocr_1.performOCR)(imageBuffer);
|
|
1524
|
-
if (typeof full === 'string') {
|
|
1525
|
-
if (full.length > 4000) {
|
|
1526
|
-
ocrText = full.slice(0, 4000);
|
|
1527
|
-
ocrTruncated = true;
|
|
1528
|
-
}
|
|
1529
|
-
else {
|
|
1530
|
-
ocrText = full;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
}
|
|
1534
|
-
catch (err) {
|
|
1535
|
-
logger_1.default.warn('[API] workspace sync OCR failed:', err);
|
|
1536
|
-
}
|
|
1537
|
-
// workspace_sync is intentionally read-only — does not persist to the
|
|
1538
|
-
// captures DB. Agents who want a captureId for follow-up calls should
|
|
1539
|
-
// use superbased_capture separately, which is the canonical
|
|
1540
|
-
// persistence path.
|
|
1541
|
-
return reply.code(200).send({
|
|
1542
|
-
imageBase64: imageBuffer.toString('base64'),
|
|
1543
|
-
imageBytes: imageBuffer.length,
|
|
1544
|
-
mimeType: 'image/png',
|
|
1545
|
-
timestamp,
|
|
1546
|
-
activeWindow: active,
|
|
1547
|
-
ocr: {
|
|
1548
|
-
text: ocrText,
|
|
1549
|
-
truncated: ocrTruncated,
|
|
1550
|
-
charsReturned: ocrText.length,
|
|
1551
|
-
},
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
catch (err) {
|
|
1555
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1556
|
-
}
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
|
-
// ── Watcher Routes (Phase 3 — ambient event streams via SSE) ──
|
|
1560
|
-
function registerWatcherRoutes(s) {
|
|
1561
|
-
s.post('/api/watchers/subscribe', async (request, reply) => {
|
|
1562
|
-
const body = (request.body ?? {});
|
|
1563
|
-
const uri = typeof body.uri === 'string' ? body.uri : '';
|
|
1564
|
-
if (!uri) {
|
|
1565
|
-
return reply.code(400).send({ error: 'uri is required' });
|
|
1566
|
-
}
|
|
1567
|
-
if (!(0, store_1.getSetting)('watchers.enabled')) {
|
|
1568
|
-
return reply.code(403).send({ error: 'Watchers are disabled (watchers.enabled = false)' });
|
|
1569
|
-
}
|
|
1570
|
-
try {
|
|
1571
|
-
const { subscribe } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
1572
|
-
const refcount = await subscribe(uri);
|
|
1573
|
-
return reply.code(200).send({ ok: true, uri, subscribers: refcount });
|
|
1574
|
-
}
|
|
1575
|
-
catch (err) {
|
|
1576
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1577
|
-
}
|
|
1578
|
-
});
|
|
1579
|
-
s.post('/api/watchers/unsubscribe', async (request, reply) => {
|
|
1580
|
-
const body = (request.body ?? {});
|
|
1581
|
-
const uri = typeof body.uri === 'string' ? body.uri : '';
|
|
1582
|
-
if (!uri) {
|
|
1583
|
-
return reply.code(400).send({ error: 'uri is required' });
|
|
1584
|
-
}
|
|
1585
|
-
try {
|
|
1586
|
-
const { unsubscribe } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
1587
|
-
const refcount = await unsubscribe(uri);
|
|
1588
|
-
return reply.code(200).send({ ok: true, uri, subscribers: refcount });
|
|
1589
|
-
}
|
|
1590
|
-
catch (err) {
|
|
1591
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1592
|
-
}
|
|
1593
|
-
});
|
|
1594
|
-
s.get('/api/watchers/status', async (_request, reply) => {
|
|
1595
|
-
const { getStatus } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
1596
|
-
return reply.code(200).send({ watchers: getStatus() });
|
|
1597
|
-
});
|
|
1598
|
-
s.get('/api/watchers/stream', async (request, reply) => {
|
|
1599
|
-
reply.raw.writeHead(200, {
|
|
1600
|
-
'Content-Type': 'text/event-stream',
|
|
1601
|
-
'Cache-Control': 'no-cache',
|
|
1602
|
-
'Connection': 'keep-alive',
|
|
1603
|
-
'X-Accel-Buffering': 'no',
|
|
1604
|
-
});
|
|
1605
|
-
reply.raw.write('event: connected\ndata: {}\n\n');
|
|
1606
|
-
const { onEvent } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
1607
|
-
const unsubscribe = onEvent((event) => {
|
|
1608
|
-
try {
|
|
1609
|
-
reply.raw.write(`event: watcher\ndata: ${JSON.stringify(event)}\n\n`);
|
|
1610
|
-
}
|
|
1611
|
-
catch {
|
|
1612
|
-
// Client disconnected mid-write — cleanup handler below will fire.
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
const keepalive = setInterval(() => {
|
|
1616
|
-
try {
|
|
1617
|
-
reply.raw.write(':keepalive\n\n');
|
|
1618
|
-
}
|
|
1619
|
-
catch {
|
|
1620
|
-
clearInterval(keepalive);
|
|
1621
|
-
}
|
|
1622
|
-
}, 15000);
|
|
1623
|
-
request.raw.on('close', () => {
|
|
1624
|
-
clearInterval(keepalive);
|
|
1625
|
-
unsubscribe();
|
|
1626
|
-
});
|
|
1627
|
-
return reply;
|
|
1628
|
-
});
|
|
1629
|
-
}
|
|
1630
|
-
// Register watcher factories exactly once per process.
|
|
1631
|
-
let watcherFactoriesRegistered = false;
|
|
1632
|
-
async function registerWatcherFactoriesOnce() {
|
|
1633
|
-
if (watcherFactoriesRegistered)
|
|
1634
|
-
return;
|
|
1635
|
-
watcherFactoriesRegistered = true;
|
|
1636
|
-
const { registerFactory } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
1637
|
-
const { clipboardWatcherFactory } = await Promise.resolve().then(() => __importStar(require('./watchers/clipboard-watcher')));
|
|
1638
|
-
const { activeWindowWatcherFactory } = await Promise.resolve().then(() => __importStar(require('./watchers/active-window-watcher')));
|
|
1639
|
-
const { fileWatcherFactory } = await Promise.resolve().then(() => __importStar(require('./watchers/file-watcher')));
|
|
1640
|
-
const { screenRegionWatcherFactory } = await Promise.resolve().then(() => __importStar(require('./watchers/screen-region-watcher')));
|
|
1641
|
-
registerFactory(clipboardWatcherFactory);
|
|
1642
|
-
registerFactory(activeWindowWatcherFactory);
|
|
1643
|
-
registerFactory(fileWatcherFactory);
|
|
1644
|
-
registerFactory(screenRegionWatcherFactory);
|
|
1645
|
-
}
|
|
1646
|
-
// ── Recording Routes (delegate to recording module if available) ──
|
|
1647
|
-
let recordingRoutesRegistered = false;
|
|
1648
|
-
function registerRecordingRoutesOnServer() {
|
|
1649
|
-
if (!server || recordingRoutesRegistered)
|
|
1650
|
-
return;
|
|
1651
|
-
recordingRoutesRegistered = true;
|
|
1652
|
-
// Lazy-import recording modules to avoid loading them at startup
|
|
1653
|
-
const registerRoutes = async () => {
|
|
1654
|
-
try {
|
|
1655
|
-
const { getRecordingSessions, getSessionFrames } = await Promise.resolve().then(() => __importStar(require('../db/database')));
|
|
1656
|
-
const { startSession, stopCurrentSession, pauseCurrentSession, resumeCurrentSession, getCurrentSession, triggerManualCapture, } = await Promise.resolve().then(() => __importStar(require('./recording/recording-session')));
|
|
1657
|
-
const { alignSessions } = await Promise.resolve().then(() => __importStar(require('./recording/session-alignment')));
|
|
1658
|
-
const { exportSession } = await Promise.resolve().then(() => __importStar(require('./recording/session-export')));
|
|
1659
|
-
const s = server;
|
|
1660
|
-
// POST /api/recording/start
|
|
1661
|
-
s.post('/api/recording/start', async (request, reply) => {
|
|
1662
|
-
try {
|
|
1663
|
-
const body = request.body || {};
|
|
1664
|
-
const options = {
|
|
1665
|
-
name: body.name || `API Recording ${new Date().toLocaleString()}`,
|
|
1666
|
-
profile: (body.profile || 'automated_test'),
|
|
1667
|
-
scope: (body.scope || 'all'),
|
|
1668
|
-
targetProcessName: body.targetProcessName,
|
|
1669
|
-
targetWindowTitle: body.targetWindowTitle,
|
|
1670
|
-
showInGallery: body.showInGallery !== false,
|
|
1671
|
-
mode: body.mode,
|
|
1672
|
-
interval: body.interval,
|
|
1673
|
-
changeThreshold: body.changeThreshold,
|
|
1674
|
-
};
|
|
1675
|
-
// Monitor mode settings
|
|
1676
|
-
if (body.mode === 'monitor') {
|
|
1677
|
-
options.monitor = {
|
|
1678
|
-
analysisPrompt: body.analysisPrompt || 'Describe what changed on screen. Flag any errors, warnings, unexpected states, or UI issues.',
|
|
1679
|
-
analyzeEvery: body.analyzeEvery ?? 5,
|
|
1680
|
-
analyzeInterval: body.analyzeInterval ?? 30,
|
|
1681
|
-
analysisDetail: body.analysisDetail || 'low',
|
|
1682
|
-
};
|
|
1683
|
-
}
|
|
1684
|
-
const session = await startSession(options);
|
|
1685
|
-
return reply.code(200).send({ sessionId: session.id, status: 'recording', mode: session.mode });
|
|
1686
|
-
}
|
|
1687
|
-
catch (err) {
|
|
1688
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1691
|
-
// POST /api/recording/stop
|
|
1692
|
-
s.post('/api/recording/stop', async (_request, reply) => {
|
|
1693
|
-
try {
|
|
1694
|
-
const session = await stopCurrentSession();
|
|
1695
|
-
if (!session) {
|
|
1696
|
-
return reply.code(400).send({ error: 'No active recording session' });
|
|
1697
|
-
}
|
|
1698
|
-
return reply.code(200).send({
|
|
1699
|
-
sessionId: session.id,
|
|
1700
|
-
status: 'completed',
|
|
1701
|
-
frameCount: session.frameCount,
|
|
1702
|
-
duration: Date.now() - session.startedAt,
|
|
1703
|
-
});
|
|
1704
|
-
}
|
|
1705
|
-
catch (err) {
|
|
1706
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1707
|
-
}
|
|
1708
|
-
});
|
|
1709
|
-
// POST /api/recording/pause
|
|
1710
|
-
s.post('/api/recording/pause', async (_request, reply) => {
|
|
1711
|
-
try {
|
|
1712
|
-
await pauseCurrentSession();
|
|
1713
|
-
return reply.code(200).send({ success: true });
|
|
1714
|
-
}
|
|
1715
|
-
catch (err) {
|
|
1716
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1717
|
-
}
|
|
1718
|
-
});
|
|
1719
|
-
// POST /api/recording/resume
|
|
1720
|
-
s.post('/api/recording/resume', async (_request, reply) => {
|
|
1721
|
-
try {
|
|
1722
|
-
await resumeCurrentSession();
|
|
1723
|
-
return reply.code(200).send({ success: true });
|
|
1724
|
-
}
|
|
1725
|
-
catch (err) {
|
|
1726
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1727
|
-
}
|
|
1728
|
-
});
|
|
1729
|
-
// GET /api/recording/status
|
|
1730
|
-
s.get('/api/recording/status', async (_request, reply) => {
|
|
1731
|
-
const session = getCurrentSession();
|
|
1732
|
-
if (!session) {
|
|
1733
|
-
return reply.code(200).send({ status: 'idle' });
|
|
1734
|
-
}
|
|
1735
|
-
return reply.code(200).send({
|
|
1736
|
-
status: session.status === 'paused' ? 'paused' : 'recording',
|
|
1737
|
-
sessionId: session.id,
|
|
1738
|
-
frameCount: session.frameCount,
|
|
1739
|
-
duration: Date.now() - session.startedAt,
|
|
1740
|
-
mode: session.mode,
|
|
1741
|
-
});
|
|
1742
|
-
});
|
|
1743
|
-
// POST /api/recording/capture
|
|
1744
|
-
s.post('/api/recording/capture', async (_request, reply) => {
|
|
1745
|
-
const session = getCurrentSession();
|
|
1746
|
-
if (!session) {
|
|
1747
|
-
return reply.code(400).send({ error: 'No active recording session' });
|
|
1748
|
-
}
|
|
1749
|
-
triggerManualCapture();
|
|
1750
|
-
return reply.code(200).send({ success: true, message: 'Manual capture triggered' });
|
|
1751
|
-
});
|
|
1752
|
-
// GET /api/recording/analysis — get AI analysis results for a session
|
|
1753
|
-
s.get('/api/recording/analysis', async (request, reply) => {
|
|
1754
|
-
try {
|
|
1755
|
-
const query = request.query;
|
|
1756
|
-
if (!query.sessionId) {
|
|
1757
|
-
return reply.code(400).send({ error: 'sessionId query param required' });
|
|
1758
|
-
}
|
|
1759
|
-
const { getDatabase } = await Promise.resolve().then(() => __importStar(require('../db/database')));
|
|
1760
|
-
const db = getDatabase();
|
|
1761
|
-
const sinceFrame = query.since ? parseInt(query.since, 10) : 0;
|
|
1762
|
-
const rows = db.prepare(`SELECT id, frame_number, timestamp, ai_response
|
|
1763
|
-
FROM captures
|
|
1764
|
-
WHERE session_id = ? AND ai_response IS NOT NULL AND ai_response != '' AND frame_number > ?
|
|
1765
|
-
ORDER BY frame_number ASC`).all(query.sessionId, sinceFrame);
|
|
1766
|
-
const analyses = rows.map((r) => ({
|
|
1767
|
-
frameId: r.id,
|
|
1768
|
-
frameNumber: r.frame_number,
|
|
1769
|
-
timestamp: r.timestamp,
|
|
1770
|
-
analysis: r.ai_response,
|
|
1771
|
-
}));
|
|
1772
|
-
return reply.code(200).send({ sessionId: query.sessionId, analyses });
|
|
1773
|
-
}
|
|
1774
|
-
catch (err) {
|
|
1775
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1776
|
-
}
|
|
1777
|
-
});
|
|
1778
|
-
// GET /api/recording/monitor/status — monitor mode status
|
|
1779
|
-
s.get('/api/recording/monitor/status', async (_request, reply) => {
|
|
1780
|
-
const session = getCurrentSession();
|
|
1781
|
-
if (!session || session.mode !== 'monitor') {
|
|
1782
|
-
return reply.code(200).send({ status: 'inactive' });
|
|
1783
|
-
}
|
|
1784
|
-
const { getMonitorAnalyzer } = await Promise.resolve().then(() => __importStar(require('./recording/recording-session')));
|
|
1785
|
-
const analyzer = getMonitorAnalyzer();
|
|
1786
|
-
return reply.code(200).send({
|
|
1787
|
-
status: 'monitoring',
|
|
1788
|
-
sessionId: session.id,
|
|
1789
|
-
mode: session.mode,
|
|
1790
|
-
frameCount: session.frameCount,
|
|
1791
|
-
alertCount: analyzer?.getAlertCount() || 0,
|
|
1792
|
-
lastAnalysis: analyzer?.getLastAnalysis() || null,
|
|
1793
|
-
});
|
|
1794
|
-
});
|
|
1795
|
-
// GET /api/recording/monitor/stream — SSE stream of monitor alerts
|
|
1796
|
-
s.get('/api/recording/monitor/stream', async (request, reply) => {
|
|
1797
|
-
const session = getCurrentSession();
|
|
1798
|
-
if (!session || session.mode !== 'monitor') {
|
|
1799
|
-
return reply.code(400).send({ error: 'No active monitor session' });
|
|
1800
|
-
}
|
|
1801
|
-
// Set up SSE headers
|
|
1802
|
-
reply.raw.writeHead(200, {
|
|
1803
|
-
'Content-Type': 'text/event-stream',
|
|
1804
|
-
'Cache-Control': 'no-cache',
|
|
1805
|
-
'Connection': 'keep-alive',
|
|
1806
|
-
'X-Accel-Buffering': 'no',
|
|
1807
|
-
});
|
|
1808
|
-
reply.raw.write('event: connected\ndata: {"sessionId":"' + session.id + '"}\n\n');
|
|
1809
|
-
// Register alert callback
|
|
1810
|
-
const { setMonitorAlertCallback } = await Promise.resolve().then(() => __importStar(require('./recording/recording-session')));
|
|
1811
|
-
const alertHandler = (alert) => {
|
|
1812
|
-
const data = JSON.stringify(alert);
|
|
1813
|
-
reply.raw.write(`event: alert\ndata: ${data}\n\n`);
|
|
1814
|
-
};
|
|
1815
|
-
setMonitorAlertCallback(alertHandler);
|
|
1816
|
-
// Send keepalive every 15 seconds
|
|
1817
|
-
const keepalive = setInterval(() => {
|
|
1818
|
-
try {
|
|
1819
|
-
reply.raw.write(':keepalive\n\n');
|
|
1820
|
-
}
|
|
1821
|
-
catch {
|
|
1822
|
-
clearInterval(keepalive);
|
|
1823
|
-
}
|
|
1824
|
-
}, 15000);
|
|
1825
|
-
// Cleanup on client disconnect
|
|
1826
|
-
request.raw.on('close', () => {
|
|
1827
|
-
clearInterval(keepalive);
|
|
1828
|
-
setMonitorAlertCallback(() => { }); // Remove handler
|
|
1829
|
-
});
|
|
1830
|
-
// Don't send reply body — SSE uses raw stream
|
|
1831
|
-
return reply;
|
|
1832
|
-
});
|
|
1833
|
-
// GET /api/sessions
|
|
1834
|
-
s.get('/api/sessions', async (_request, reply) => {
|
|
1835
|
-
const sessions = getRecordingSessions(100);
|
|
1836
|
-
return reply.code(200).send({ sessions });
|
|
1837
|
-
});
|
|
1838
|
-
// GET /api/sessions/:id/frames
|
|
1839
|
-
s.get('/api/sessions/:id/frames', async (request, reply) => {
|
|
1840
|
-
const params = request.params;
|
|
1841
|
-
const frames = getSessionFrames(params.id);
|
|
1842
|
-
return reply.code(200).send({ sessionId: params.id, frames });
|
|
1843
|
-
});
|
|
1844
|
-
// POST /api/diff
|
|
1845
|
-
s.post('/api/diff', async (request, reply) => {
|
|
1846
|
-
try {
|
|
1847
|
-
const body = request.body;
|
|
1848
|
-
if (!body?.baselineSessionId || !body?.currentSessionId) {
|
|
1849
|
-
return reply.code(400).send({ error: 'baselineSessionId and currentSessionId required' });
|
|
1850
|
-
}
|
|
1851
|
-
const baselineFrames = getSessionFrames(body.baselineSessionId);
|
|
1852
|
-
const currentFrames = getSessionFrames(body.currentSessionId);
|
|
1853
|
-
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
1854
|
-
const baseDir = custom && fs.existsSync(custom) ? custom : path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
1855
|
-
const diffDir = path.join(baseDir, 'sessions', `diff_${body.baselineSessionId}_${body.currentSessionId}`);
|
|
1856
|
-
fs.mkdirSync(diffDir, { recursive: true });
|
|
1857
|
-
const result = await alignSessions(baselineFrames, currentFrames, diffDir);
|
|
1858
|
-
return reply.code(200).send(result);
|
|
1859
|
-
}
|
|
1860
|
-
catch (err) {
|
|
1861
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1862
|
-
}
|
|
1863
|
-
});
|
|
1864
|
-
// POST /api/export
|
|
1865
|
-
s.post('/api/export', async (request, reply) => {
|
|
1866
|
-
try {
|
|
1867
|
-
const body = request.body;
|
|
1868
|
-
if (!body?.sessionId || !body?.format) {
|
|
1869
|
-
return reply.code(400).send({ error: 'sessionId and format required' });
|
|
1870
|
-
}
|
|
1871
|
-
const custom = (0, store_1.getSetting)('screenshotFolder');
|
|
1872
|
-
const baseDir = custom && fs.existsSync(custom) ? custom : path.join((0, platform_1.getPlatform)().getDataDir(), constants_1.CAPTURES_DIR);
|
|
1873
|
-
const outputPath = body.output || path.join(baseDir, 'exports', `${body.sessionId}.${body.format}`);
|
|
1874
|
-
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
1875
|
-
const filePath = await exportSession(body.sessionId, body.format, outputPath);
|
|
1876
|
-
return reply.code(200).send({ filePath });
|
|
1877
|
-
}
|
|
1878
|
-
catch (err) {
|
|
1879
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1880
|
-
}
|
|
1881
|
-
});
|
|
1882
|
-
logger_1.default.info('[API] Recording routes registered');
|
|
1883
|
-
}
|
|
1884
|
-
catch (err) {
|
|
1885
|
-
logger_1.default.error('[API] Failed to register recording routes:', err);
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
registerRoutes().catch((err) => logger_1.default.error('[API] Recording route registration error:', err));
|
|
1889
|
-
}
|
|
1890
|
-
// ── Expanded Routes (Tier 1 + Tier 2) ──
|
|
1891
|
-
function registerExpandedRoutes(server) {
|
|
1892
|
-
// GET /api/auth/status — auth state
|
|
1893
|
-
server.get('/api/auth/status', async (_req, reply) => {
|
|
1894
|
-
const state = (0, auth_1.getAuthState)();
|
|
1895
|
-
return reply.code(200).send({
|
|
1896
|
-
authenticated: (0, auth_1.isAuthenticated)(),
|
|
1897
|
-
email: state.email || null,
|
|
1898
|
-
name: state.name || null,
|
|
1899
|
-
userId: state.userId || null,
|
|
1900
|
-
plan: state.plan || 'free',
|
|
1901
|
-
});
|
|
1902
|
-
});
|
|
1903
|
-
// GET /api/license/info — plan limits, feature gates, device
|
|
1904
|
-
server.get('/api/license/info', async (_req, reply) => {
|
|
1905
|
-
const state = (0, license_1.getLicenseState)();
|
|
1906
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1907
|
-
const checkFeature = license_1.isFeatureAllowed;
|
|
1908
|
-
return reply.code(200).send({
|
|
1909
|
-
...state,
|
|
1910
|
-
deviceId: (0, license_1.getMachineId)(),
|
|
1911
|
-
features: {
|
|
1912
|
-
ai: checkFeature('ai'),
|
|
1913
|
-
recording: checkFeature('recording'),
|
|
1914
|
-
mcp: checkFeature('mcp'),
|
|
1915
|
-
},
|
|
1916
|
-
});
|
|
1917
|
-
});
|
|
1918
|
-
// GET /api/ai/local-usage — daily AI quota
|
|
1919
|
-
server.get('/api/ai/local-usage', async (_req, reply) => {
|
|
1920
|
-
try {
|
|
1921
|
-
if (!(0, auth_1.isAuthenticated)()) {
|
|
1922
|
-
return reply.code(401).send({ error: 'Not authenticated' });
|
|
1923
|
-
}
|
|
1924
|
-
const usage = await (0, ai_client_1.getAIUsage)();
|
|
1925
|
-
return reply.code(200).send(usage);
|
|
1926
|
-
}
|
|
1927
|
-
catch (err) {
|
|
1928
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
// GET /api/gallery/captures/:id/image — capture image as base64
|
|
1932
|
-
server.get('/api/gallery/captures/:id/image', async (req, reply) => {
|
|
1933
|
-
try {
|
|
1934
|
-
const params = req.params;
|
|
1935
|
-
const query = req.query;
|
|
1936
|
-
const id = parseInt(params.id, 10);
|
|
1937
|
-
if (isNaN(id))
|
|
1938
|
-
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
1939
|
-
const capture = (0, database_1.getCapture)(id);
|
|
1940
|
-
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
1941
|
-
return reply.code(404).send({ error: 'Capture image not found' });
|
|
1942
|
-
}
|
|
1943
|
-
const rawBuf = fs.readFileSync(capture.screenshot_path);
|
|
1944
|
-
const buffer = await resizeCapture(rawBuf, query.resolution, query.maxWidth ? parseInt(query.maxWidth) : undefined, query.maxHeight ? parseInt(query.maxHeight) : undefined);
|
|
1945
|
-
return reply.code(200).send({
|
|
1946
|
-
imageBase64: buffer.toString('base64'),
|
|
1947
|
-
mimeType: 'image/png',
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
catch (err) {
|
|
1951
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
1952
|
-
}
|
|
1953
|
-
});
|
|
1954
|
-
// POST /api/capture/fullscreen-image — capture with resolution + window targeting
|
|
1955
|
-
server.post('/api/capture/fullscreen-image', async (req, reply) => {
|
|
1956
|
-
const t0 = Date.now();
|
|
1957
|
-
const timings = {};
|
|
1958
|
-
const mark = (k) => { timings[k] = Date.now() - t0; };
|
|
1959
|
-
try {
|
|
1960
|
-
const body = req.body || {};
|
|
1961
|
-
if (body.projectDir && !isValidProjectDir(body.projectDir)) {
|
|
1962
|
-
return reply.code(400).send({ error: 'Invalid projectDir' });
|
|
1963
|
-
}
|
|
1964
|
-
// ── Window targeting (hardened per agent feedback 2026-04-21) ────────
|
|
1965
|
-
//
|
|
1966
|
-
// Previously this handler did a naive case-insensitive substring
|
|
1967
|
-
// match on window titles alone. That silently picked the wrong
|
|
1968
|
-
// window when a project name appeared in an IDE's window title
|
|
1969
|
-
// (e.g. target="superbased" matched both "SuperBased" Electron app
|
|
1970
|
-
// AND "superbased [WSL] — Antigravity" IDE; the IDE won). It also
|
|
1971
|
-
// had no retry or post-activation verification, so a silently-
|
|
1972
|
-
// failed SetForegroundWindow would still produce a screenshot of
|
|
1973
|
-
// the wrong window.
|
|
1974
|
-
//
|
|
1975
|
-
// New flow:
|
|
1976
|
-
// 1. resolveWindow() — scored matcher that refuses on ambiguous
|
|
1977
|
-
// matches and returns alternatives. Same path focus_window
|
|
1978
|
-
// uses. hwnd/processName/window all supported.
|
|
1979
|
-
// 2. activateWindow() — up-to-3-attempt activation with
|
|
1980
|
-
// GetForegroundWindow verification on Windows. Surfaces
|
|
1981
|
-
// `verified:boolean` + `postForeground:hwnd` in the diagnostic.
|
|
1982
|
-
// 3. If !verified, we STILL take the screenshot (so the agent
|
|
1983
|
-
// gets something) but the diagnostic includes broughtToFront:
|
|
1984
|
-
// false so the caller knows the result can't be trusted.
|
|
1985
|
-
// 4. restoreWindow() on the previous foreground token.
|
|
1986
|
-
let windowInfo = null;
|
|
1987
|
-
let buffer = null;
|
|
1988
|
-
let diagnostic = null;
|
|
1989
|
-
let matchedWindow = null;
|
|
1990
|
-
let alternativesOut;
|
|
1991
|
-
const wantWindowTargeting = !!(body.window || body.processName || body.hwnd);
|
|
1992
|
-
if (wantWindowTargeting) {
|
|
1993
|
-
const { resolveWindow } = await Promise.resolve().then(() => __importStar(require('./window-resolver')));
|
|
1994
|
-
const matchResult = await resolveWindow({
|
|
1995
|
-
window: body.window,
|
|
1996
|
-
processName: body.processName,
|
|
1997
|
-
hwnd: body.hwnd,
|
|
1998
|
-
});
|
|
1999
|
-
mark('resolveMs');
|
|
2000
|
-
if (!matchResult.ok || !matchResult.best) {
|
|
2001
|
-
return reply.code(matchResult.reason === 'ambiguous' ? 409 : 404).send({
|
|
2002
|
-
ok: false,
|
|
2003
|
-
error: matchResult.error,
|
|
2004
|
-
reason: matchResult.reason,
|
|
2005
|
-
alternatives: matchResult.alternatives?.map((c) => ({
|
|
2006
|
-
title: c.name, processName: c.processName, hwnd: c.hwnd, score: c.score, scoreReason: c.scoreReason,
|
|
2007
|
-
})),
|
|
2008
|
-
hint: matchResult.reason === 'ambiguous'
|
|
2009
|
-
? 'Multiple windows matched. Disambiguate with `processName` + `window` combined, or pass `hwnd` directly.'
|
|
2010
|
-
: matchResult.reason === 'no_match'
|
|
2011
|
-
? 'No matching window. Call superbased_window_list to see what is open.'
|
|
2012
|
-
: undefined,
|
|
2013
|
-
});
|
|
2014
|
-
}
|
|
2015
|
-
const match = matchResult.best;
|
|
2016
|
-
windowInfo = { appName: match.name, windowTitle: match.name };
|
|
2017
|
-
matchedWindow = {
|
|
2018
|
-
title: match.name,
|
|
2019
|
-
processName: match.processName,
|
|
2020
|
-
hwnd: match.hwnd,
|
|
2021
|
-
score: match.score,
|
|
2022
|
-
scoreReason: match.scoreReason,
|
|
2023
|
-
};
|
|
2024
|
-
if (matchResult.alternatives && matchResult.alternatives.length > 0) {
|
|
2025
|
-
alternativesOut = matchResult.alternatives.map((c) => ({
|
|
2026
|
-
title: c.name, processName: c.processName, hwnd: c.hwnd, score: c.score, scoreReason: c.scoreReason,
|
|
2027
|
-
}));
|
|
2028
|
-
}
|
|
2029
|
-
const { withActivatedWindow, captureWindowBackgroundWindows, } = await Promise.resolve().then(() => __importStar(require('./window-activate')));
|
|
2030
|
-
// ─── Fast path: background capture via PrintWindow ────────────
|
|
2031
|
-
//
|
|
2032
|
-
// When the caller requests background:true AND we're on Windows
|
|
2033
|
-
// AND we have a concrete hwnd, skip activation entirely and use
|
|
2034
|
-
// PrintWindow(PW_RENDERFULLCONTENT) to grab the window's pixels
|
|
2035
|
-
// directly. No focus change, no restore overhead, and ~5x faster
|
|
2036
|
-
// than the activation path (no 3× retry + verify sleeps). Falls
|
|
2037
|
-
// through to the activate path if the bitmap comes back empty
|
|
2038
|
-
// (GPU-composited surfaces — some games, fullscreen video).
|
|
2039
|
-
let backgroundMode = false;
|
|
2040
|
-
if (body.background && process.platform === 'win32' && match.hwnd) {
|
|
2041
|
-
const bg = await captureWindowBackgroundWindows(match.hwnd);
|
|
2042
|
-
mark('captureMs');
|
|
2043
|
-
if (bg) {
|
|
2044
|
-
buffer = fs.readFileSync(bg.path);
|
|
2045
|
-
try {
|
|
2046
|
-
fs.unlinkSync(bg.path);
|
|
2047
|
-
}
|
|
2048
|
-
catch { /* cleanup */ }
|
|
2049
|
-
backgroundMode = true;
|
|
2050
|
-
diagnostic = {
|
|
2051
|
-
broughtToFront: true, // target was never foregrounded — it didn't need to be
|
|
2052
|
-
foregroundAfterActivate: undefined,
|
|
2053
|
-
activationAttempts: 0,
|
|
2054
|
-
activationError: undefined,
|
|
2055
|
-
};
|
|
2056
|
-
}
|
|
2057
|
-
// else: fall through to activate path with a diagnostic note
|
|
2058
|
-
}
|
|
2059
|
-
if (!backgroundMode) {
|
|
2060
|
-
// Delegate the snapshot-activate-paint-capture-restore cycle to
|
|
2061
|
-
// withActivatedWindow. Paint delay is 150ms (Electron repaint
|
|
2062
|
-
// window); agents that need more for GPU-heavy targets can
|
|
2063
|
-
// request a second capture.
|
|
2064
|
-
const wrap = await withActivatedWindow(match, async () => {
|
|
2065
|
-
const tCap = Date.now();
|
|
2066
|
-
const buf = await (0, capture_1.captureScreen)();
|
|
2067
|
-
return { buffer: buf, captureMs: Date.now() - tCap };
|
|
2068
|
-
}, { paintDelayMs: 150 });
|
|
2069
|
-
buffer = wrap.result.buffer;
|
|
2070
|
-
if (wrap.timings.snapshotMs !== undefined)
|
|
2071
|
-
timings.snapshotMs = (timings.resolveMs ?? 0) + wrap.timings.snapshotMs;
|
|
2072
|
-
if (wrap.timings.activateMs !== undefined)
|
|
2073
|
-
timings.activateMs = (timings.snapshotMs ?? 0) + wrap.timings.activateMs;
|
|
2074
|
-
if (wrap.timings.paintMs !== undefined)
|
|
2075
|
-
timings.paintMs = (timings.activateMs ?? 0) + wrap.timings.paintMs;
|
|
2076
|
-
timings.captureMs = (timings.paintMs ?? timings.activateMs ?? timings.snapshotMs ?? timings.resolveMs ?? 0) + wrap.result.captureMs;
|
|
2077
|
-
if (wrap.timings.restoreMs !== undefined)
|
|
2078
|
-
timings.restoreMs = (timings.captureMs ?? 0) + wrap.timings.restoreMs;
|
|
2079
|
-
diagnostic = {
|
|
2080
|
-
broughtToFront: wrap.diag.verified === true
|
|
2081
|
-
|| (process.platform !== 'win32' && wrap.diag.ok === true),
|
|
2082
|
-
foregroundAfterActivate: wrap.diag.postForeground,
|
|
2083
|
-
activationAttempts: wrap.diag.attempted,
|
|
2084
|
-
activationError: wrap.diag.error,
|
|
2085
|
-
};
|
|
2086
|
-
if (!wrap.restore.skipped) {
|
|
2087
|
-
diagnostic.restoredFocus = wrap.restore.restored;
|
|
2088
|
-
diagnostic.restoreAttempts = wrap.restore.attempts;
|
|
2089
|
-
diagnostic.foregroundAfterRestore = wrap.restore.finalForeground;
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
diagnostic.backgroundMode = backgroundMode;
|
|
2093
|
-
}
|
|
2094
|
-
if (!buffer) {
|
|
2095
|
-
buffer = await (0, capture_1.captureScreen)();
|
|
2096
|
-
mark('captureMs');
|
|
2097
|
-
}
|
|
2098
|
-
// Auto-redact if enabled
|
|
2099
|
-
const redactSecrets = !!(0, store_1.getSetting)('autoRedactSecrets');
|
|
2100
|
-
const redactPII = !!(0, store_1.getSetting)('autoRedactPII');
|
|
2101
|
-
if (redactSecrets || redactPII) {
|
|
2102
|
-
const result = await (0, redact_1.autoRedact)(buffer, { secrets: redactSecrets, pii: redactPII });
|
|
2103
|
-
buffer = result.buffer;
|
|
2104
|
-
}
|
|
2105
|
-
// Resize for token efficiency
|
|
2106
|
-
buffer = await resizeCapture(buffer, body.resolution, body.maxWidth, body.maxHeight);
|
|
2107
|
-
// Save to gallery
|
|
2108
|
-
ensureCapturesDir(body.projectDir);
|
|
2109
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
2110
|
-
const filename = `capture-${timestamp}.png`;
|
|
2111
|
-
const capturesDir = getCapturesDir(body.projectDir);
|
|
2112
|
-
const filepath = path.join(capturesDir, filename);
|
|
2113
|
-
fs.writeFileSync(filepath, buffer);
|
|
2114
|
-
const primaryDisplay = (electronScreen?.getPrimaryDisplay() || { size: (0, platform_1.getPlatform)().getScreenSize() });
|
|
2115
|
-
const { width, height } = primaryDisplay.size;
|
|
2116
|
-
const captureId = (0, database_1.saveCapture)({
|
|
2117
|
-
screenshotPath: filepath, regionX: 0, regionY: 0,
|
|
2118
|
-
regionW: width, regionH: height,
|
|
2119
|
-
sourceApp: windowInfo?.appName || 'API',
|
|
2120
|
-
windowTitle: windowInfo?.windowTitle || 'Fullscreen Capture',
|
|
2121
|
-
});
|
|
2122
|
-
mark('totalMs');
|
|
2123
|
-
return reply.code(200).send({
|
|
2124
|
-
captureId, width, height,
|
|
2125
|
-
imageBase64: buffer.toString('base64'),
|
|
2126
|
-
mimeType: 'image/png',
|
|
2127
|
-
windowInfo,
|
|
2128
|
-
// Per-call diagnostic — lets the MCP caller detect silent
|
|
2129
|
-
// foregrounding failures (broughtToFront:false) instead of
|
|
2130
|
-
// inferring from pixels. Present only when window targeting
|
|
2131
|
-
// was requested. `timings` is keyed by step; keys present only
|
|
2132
|
-
// when that step ran (e.g. no `restoreMs` for background mode).
|
|
2133
|
-
matchedWindow: matchedWindow ?? undefined,
|
|
2134
|
-
alternatives: alternativesOut,
|
|
2135
|
-
diagnostic: diagnostic ?? undefined,
|
|
2136
|
-
timings: Object.keys(timings).length > 0 ? timings : undefined,
|
|
2137
|
-
});
|
|
2138
|
-
}
|
|
2139
|
-
catch (err) {
|
|
2140
|
-
logger_1.default.error('[API] Fullscreen-image capture failed:', err);
|
|
2141
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
// POST /api/redact — auto-redact secrets/PII
|
|
2145
|
-
server.post('/api/redact', async (req, reply) => {
|
|
2146
|
-
try {
|
|
2147
|
-
const body = req.body || {};
|
|
2148
|
-
let imageBuffer;
|
|
2149
|
-
if (body.captureId) {
|
|
2150
|
-
const capture = (0, database_1.getCapture)(body.captureId);
|
|
2151
|
-
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
2152
|
-
return reply.code(404).send({ error: 'Capture not found' });
|
|
2153
|
-
}
|
|
2154
|
-
imageBuffer = fs.readFileSync(capture.screenshot_path);
|
|
2155
|
-
}
|
|
2156
|
-
else if (body.imageBase64) {
|
|
2157
|
-
imageBuffer = Buffer.from(body.imageBase64, 'base64');
|
|
2158
|
-
}
|
|
2159
|
-
else if (body.screenshotPath) {
|
|
2160
|
-
if (!isValidScreenshotPath(body.screenshotPath) || !fs.existsSync(body.screenshotPath)) {
|
|
2161
|
-
return reply.code(400).send({ error: 'Invalid or inaccessible screenshotPath' });
|
|
2162
|
-
}
|
|
2163
|
-
imageBuffer = fs.readFileSync(body.screenshotPath);
|
|
2164
|
-
}
|
|
2165
|
-
else {
|
|
2166
|
-
return reply.code(400).send({ error: 'captureId, imageBase64, or screenshotPath required' });
|
|
2167
|
-
}
|
|
2168
|
-
const result = await (0, redact_1.autoRedact)(imageBuffer, {
|
|
2169
|
-
secrets: body.secrets !== false,
|
|
2170
|
-
pii: body.pii ?? false,
|
|
2171
|
-
});
|
|
2172
|
-
return reply.code(200).send({
|
|
2173
|
-
imageBase64: result.buffer.toString('base64'),
|
|
2174
|
-
regionsFound: result.regionsFound,
|
|
2175
|
-
regions: result.regions,
|
|
2176
|
-
mimeType: 'image/png',
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
catch (err) {
|
|
2180
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2181
|
-
}
|
|
2182
|
-
});
|
|
2183
|
-
// POST /api/transcribe — audio transcription. Engine-routed (Phase 4b).
|
|
2184
|
-
// Route through stt/router so the `engine` parameter picks cloud / sherpa /
|
|
2185
|
-
// native, with `auto` resolving to the best available engine given the
|
|
2186
|
-
// current auth + model state. Structured engine errors are returned as
|
|
2187
|
-
// HTTP 200 with { ok: false, error, engine, ...remediation } bodies so
|
|
2188
|
-
// agents can branch on the error code rather than an HTTP status.
|
|
2189
|
-
server.post('/api/transcribe', async (req, reply) => {
|
|
2190
|
-
try {
|
|
2191
|
-
const body = req.body || {};
|
|
2192
|
-
let audioBase64 = body.audioBase64;
|
|
2193
|
-
if (!audioBase64 && body.audioPath && fs.existsSync(body.audioPath)) {
|
|
2194
|
-
audioBase64 = fs.readFileSync(body.audioPath).toString('base64');
|
|
2195
|
-
}
|
|
2196
|
-
if (!audioBase64) {
|
|
2197
|
-
return reply.code(400).send({ error: 'audioBase64 or audioPath required' });
|
|
2198
|
-
}
|
|
2199
|
-
const { route } = await Promise.resolve().then(() => __importStar(require('./stt/router')));
|
|
2200
|
-
const engineRequested = body.engine ?? 'auto';
|
|
2201
|
-
const result = await route({
|
|
2202
|
-
engine: engineRequested,
|
|
2203
|
-
audioBase64,
|
|
2204
|
-
language: body.language,
|
|
2205
|
-
source: 'api',
|
|
2206
|
-
});
|
|
2207
|
-
if (result.ok === false) {
|
|
2208
|
-
return reply.code(200).send(result);
|
|
2209
|
-
}
|
|
2210
|
-
return reply.code(200).send({ text: result.text, engine: result.engine, latencyMs: result.latencyMs });
|
|
2211
|
-
}
|
|
2212
|
-
catch (err) {
|
|
2213
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2214
|
-
}
|
|
2215
|
-
});
|
|
2216
|
-
// GET /api/windows — list visible windows
|
|
2217
|
-
server.get('/api/windows', async (_req, reply) => {
|
|
2218
|
-
try {
|
|
2219
|
-
const sources = await (0, platform_1.getPlatform)().listWindows();
|
|
2220
|
-
const active = await (0, active_window_1.getActiveWindowInfo)();
|
|
2221
|
-
return reply.code(200).send({
|
|
2222
|
-
windows: sources.map((s) => ({
|
|
2223
|
-
id: s.id,
|
|
2224
|
-
name: s.name,
|
|
2225
|
-
hwnd: s.hwnd,
|
|
2226
|
-
minimized: s.minimized,
|
|
2227
|
-
processName: s.processName,
|
|
2228
|
-
isActive: active.windowTitle ? s.name === active.windowTitle : false,
|
|
2229
|
-
})),
|
|
2230
|
-
activeWindow: active,
|
|
2231
|
-
});
|
|
2232
|
-
}
|
|
2233
|
-
catch (err) {
|
|
2234
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2235
|
-
}
|
|
2236
|
-
});
|
|
2237
|
-
// GET /api/dictation/history — past transcriptions
|
|
2238
|
-
server.get('/api/dictation/history', async (req, reply) => {
|
|
2239
|
-
try {
|
|
2240
|
-
const query = req.query;
|
|
2241
|
-
const limit = parseInt(query.limit || '50', 10);
|
|
2242
|
-
const entries = (0, database_1.getDictationHistory)(limit);
|
|
2243
|
-
return reply.code(200).send({ entries });
|
|
2244
|
-
}
|
|
2245
|
-
catch (err) {
|
|
2246
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2247
|
-
}
|
|
2248
|
-
});
|
|
2249
|
-
// GET /api/analytics/summary — local usage analytics
|
|
2250
|
-
server.get('/api/analytics/summary', async (_req, reply) => {
|
|
2251
|
-
try {
|
|
2252
|
-
const summary = (0, database_1.getAnalyticsSummary)();
|
|
2253
|
-
return reply.code(200).send({ summary });
|
|
2254
|
-
}
|
|
2255
|
-
catch (err) {
|
|
2256
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2257
|
-
}
|
|
2258
|
-
});
|
|
2259
|
-
// GET /api/analytics/trend — time series for an event type
|
|
2260
|
-
server.get('/api/analytics/trend', async (req, reply) => {
|
|
2261
|
-
try {
|
|
2262
|
-
const query = req.query;
|
|
2263
|
-
if (!query.eventType)
|
|
2264
|
-
return reply.code(400).send({ error: 'eventType required' });
|
|
2265
|
-
const count = parseInt(query.count || '30', 10);
|
|
2266
|
-
let data;
|
|
2267
|
-
switch (query.granularity) {
|
|
2268
|
-
case 'hourly':
|
|
2269
|
-
data = (0, database_1.getHourlyTrend)(query.eventType, count);
|
|
2270
|
-
break;
|
|
2271
|
-
default:
|
|
2272
|
-
data = (0, database_1.getDailyTrend)(query.eventType, count);
|
|
2273
|
-
break;
|
|
2274
|
-
}
|
|
2275
|
-
return reply.code(200).send({ trend: data });
|
|
2276
|
-
}
|
|
2277
|
-
catch (err) {
|
|
2278
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2279
|
-
}
|
|
2280
|
-
});
|
|
2281
|
-
// POST /api/baseline — set/get/list workflow baselines
|
|
2282
|
-
server.post('/api/baseline', async (req, reply) => {
|
|
2283
|
-
try {
|
|
2284
|
-
const body = req.body || { action: '' };
|
|
2285
|
-
switch (body.action) {
|
|
2286
|
-
case 'set':
|
|
2287
|
-
if (!body.workflowName || !body.sessionId)
|
|
2288
|
-
return reply.code(400).send({ error: 'workflowName and sessionId required' });
|
|
2289
|
-
(0, database_1.setBaseline)(body.workflowName, body.sessionId);
|
|
2290
|
-
return reply.code(200).send({ success: true });
|
|
2291
|
-
case 'get':
|
|
2292
|
-
if (!body.workflowName)
|
|
2293
|
-
return reply.code(400).send({ error: 'workflowName required' });
|
|
2294
|
-
return reply.code(200).send({ baseline: (0, database_1.getCurrentBaseline)(body.workflowName) });
|
|
2295
|
-
case 'history':
|
|
2296
|
-
if (!body.workflowName)
|
|
2297
|
-
return reply.code(400).send({ error: 'workflowName required' });
|
|
2298
|
-
return reply.code(200).send({ history: (0, database_1.getBaselineHistory)(body.workflowName) });
|
|
2299
|
-
default:
|
|
2300
|
-
return reply.code(400).send({ error: 'action must be set, get, or history' });
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
catch (err) {
|
|
2304
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2305
|
-
}
|
|
2306
|
-
});
|
|
2307
|
-
// POST /api/clipboard — read/write clipboard
|
|
2308
|
-
server.post('/api/clipboard', async (req, reply) => {
|
|
2309
|
-
try {
|
|
2310
|
-
const body = req.body || { action: '' };
|
|
2311
|
-
switch (body.action) {
|
|
2312
|
-
case 'read':
|
|
2313
|
-
return reply.code(200).send({ text: (0, platform_1.getPlatform)().getClipboardText() });
|
|
2314
|
-
case 'write':
|
|
2315
|
-
if (body.text === undefined)
|
|
2316
|
-
return reply.code(400).send({ error: 'text required' });
|
|
2317
|
-
(0, platform_1.getPlatform)().setClipboardText(body.text);
|
|
2318
|
-
return reply.code(200).send({ success: true });
|
|
2319
|
-
case 'readImage': {
|
|
2320
|
-
const imgBuf = (0, platform_1.getPlatform)().getClipboardImage();
|
|
2321
|
-
if (!imgBuf)
|
|
2322
|
-
return reply.code(200).send({ imageBase64: null });
|
|
2323
|
-
return reply.code(200).send({ imageBase64: imgBuf.toString('base64'), mimeType: 'image/png' });
|
|
2324
|
-
}
|
|
2325
|
-
default:
|
|
2326
|
-
return reply.code(400).send({ error: 'action must be read, write, or readImage' });
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
catch (err) {
|
|
2330
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2331
|
-
}
|
|
2332
|
-
});
|
|
2333
|
-
// POST /api/dictate — accept audio, transcribe, return text. Engine-routed
|
|
2334
|
-
// (Phase 4b). Post-processing (filler removal, dedup) is engine-agnostic
|
|
2335
|
-
// and runs on the engine's raw transcript before returning.
|
|
2336
|
-
server.post('/api/dictate', async (req, reply) => {
|
|
2337
|
-
try {
|
|
2338
|
-
const body = req.body || {};
|
|
2339
|
-
let audioBase64 = body.audioBase64;
|
|
2340
|
-
if (!audioBase64 && body.audioPath && fs.existsSync(body.audioPath)) {
|
|
2341
|
-
audioBase64 = fs.readFileSync(body.audioPath).toString('base64');
|
|
2342
|
-
}
|
|
2343
|
-
if (!audioBase64) {
|
|
2344
|
-
return reply.code(400).send({ error: 'audioBase64 or audioPath required' });
|
|
2345
|
-
}
|
|
2346
|
-
const { route } = await Promise.resolve().then(() => __importStar(require('./stt/router')));
|
|
2347
|
-
const engineRequested = body.engine ?? 'auto';
|
|
2348
|
-
const result = await route({
|
|
2349
|
-
engine: engineRequested,
|
|
2350
|
-
audioBase64,
|
|
2351
|
-
language: body.language,
|
|
2352
|
-
source: 'dictation',
|
|
2353
|
-
});
|
|
2354
|
-
if (result.ok === false) {
|
|
2355
|
-
return reply.code(200).send(result);
|
|
2356
|
-
}
|
|
2357
|
-
const rawText = result.text;
|
|
2358
|
-
let finalText = rawText;
|
|
2359
|
-
if (body.cleanup !== false) {
|
|
2360
|
-
try {
|
|
2361
|
-
const { removeFillerWords, deduplicateConsecutiveWords } = await Promise.resolve().then(() => __importStar(require('./dictation')));
|
|
2362
|
-
finalText = deduplicateConsecutiveWords(removeFillerWords(rawText));
|
|
2363
|
-
}
|
|
2364
|
-
catch {
|
|
2365
|
-
// Dictation module may not be available — return raw text
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
return reply.code(200).send({ text: finalText, rawText, engine: result.engine, latencyMs: result.latencyMs });
|
|
2369
|
-
}
|
|
2370
|
-
catch (err) {
|
|
2371
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2372
|
-
}
|
|
2373
|
-
});
|
|
2374
|
-
// POST /api/dictate/mic — record from microphone, transcribe, return text.
|
|
2375
|
-
// Engine-routed (Phase 4b). Records via ffmpeg-static to an in-memory WAV,
|
|
2376
|
-
// then hands off to the router for engine selection.
|
|
2377
|
-
server.post('/api/dictate/mic', async (req, reply) => {
|
|
2378
|
-
try {
|
|
2379
|
-
const body = req.body || {};
|
|
2380
|
-
const duration = body.duration || 10;
|
|
2381
|
-
// Mic capture — pipes audio to memory (no temp file I/O)
|
|
2382
|
-
let audioBase64;
|
|
2383
|
-
try {
|
|
2384
|
-
const { recordForDuration, isMicAvailable, getMicBackend } = await Promise.resolve().then(() => __importStar(require('../../headless/mic-capture')));
|
|
2385
|
-
if (!isMicAvailable()) {
|
|
2386
|
-
return reply.code(400).send({
|
|
2387
|
-
error: 'Live mic requires ffmpeg (bundled automatically). If this persists, install: winget install ffmpeg (Windows), brew install ffmpeg (macOS).',
|
|
2388
|
-
});
|
|
2389
|
-
}
|
|
2390
|
-
logger_1.default.info(`[API] Mic recording via ${getMicBackend()}, duration=${duration}s`);
|
|
2391
|
-
const audioBuffer = await recordForDuration(duration);
|
|
2392
|
-
audioBase64 = audioBuffer.toString('base64');
|
|
2393
|
-
}
|
|
2394
|
-
catch (err) {
|
|
2395
|
-
return reply.code(400).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2396
|
-
}
|
|
2397
|
-
const { route } = await Promise.resolve().then(() => __importStar(require('./stt/router')));
|
|
2398
|
-
const engineRequested = body.engine ?? 'auto';
|
|
2399
|
-
const result = await route({
|
|
2400
|
-
engine: engineRequested,
|
|
2401
|
-
audioBase64,
|
|
2402
|
-
language: body.language,
|
|
2403
|
-
source: 'dictation-mic',
|
|
2404
|
-
});
|
|
2405
|
-
if (result.ok === false) {
|
|
2406
|
-
return reply.code(200).send(result);
|
|
2407
|
-
}
|
|
2408
|
-
const rawText = result.text;
|
|
2409
|
-
let finalText = rawText;
|
|
2410
|
-
if (body.cleanup !== false) {
|
|
2411
|
-
try {
|
|
2412
|
-
const { removeFillerWords, deduplicateConsecutiveWords } = await Promise.resolve().then(() => __importStar(require('./dictation')));
|
|
2413
|
-
finalText = deduplicateConsecutiveWords(removeFillerWords(rawText));
|
|
2414
|
-
}
|
|
2415
|
-
catch { /* fallback to raw */ }
|
|
2416
|
-
}
|
|
2417
|
-
return reply.code(200).send({ text: finalText, rawText, source: 'mic', duration, engine: result.engine, latencyMs: result.latencyMs });
|
|
2418
|
-
}
|
|
2419
|
-
catch (err) {
|
|
2420
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2421
|
-
}
|
|
2422
|
-
});
|
|
2423
|
-
// POST /api/capture/:id/annotate — add annotations to a capture
|
|
2424
|
-
server.post('/api/capture/:id/annotate', async (req, reply) => {
|
|
2425
|
-
try {
|
|
2426
|
-
const params = req.params;
|
|
2427
|
-
const id = parseInt(params.id, 10);
|
|
2428
|
-
if (isNaN(id))
|
|
2429
|
-
return reply.code(400).send({ error: 'Invalid capture ID' });
|
|
2430
|
-
const capture = (0, database_1.getCapture)(id);
|
|
2431
|
-
if (!capture?.screenshot_path || !fs.existsSync(capture.screenshot_path)) {
|
|
2432
|
-
return reply.code(404).send({ error: 'Capture not found' });
|
|
2433
|
-
}
|
|
2434
|
-
const body = req.body || { annotations: [] };
|
|
2435
|
-
if (!body.annotations?.length) {
|
|
2436
|
-
return reply.code(400).send({ error: 'annotations array required' });
|
|
2437
|
-
}
|
|
2438
|
-
const sharp = require('sharp');
|
|
2439
|
-
let image = sharp(capture.screenshot_path);
|
|
2440
|
-
const meta = await image.metadata();
|
|
2441
|
-
const imgW = meta.width || 1920;
|
|
2442
|
-
const imgH = meta.height || 1080;
|
|
2443
|
-
// Build SVG overlay for non-blur annotations
|
|
2444
|
-
const svgParts = [];
|
|
2445
|
-
const blurRegions = [];
|
|
2446
|
-
for (const a of body.annotations) {
|
|
2447
|
-
const color = a.color || '#ff0000';
|
|
2448
|
-
if (a.type === 'rectangle') {
|
|
2449
|
-
svgParts.push(`<rect x="${a.x}" y="${a.y}" width="${a.width || 100}" height="${a.height || 100}" fill="none" stroke="${color}" stroke-width="3"/>`);
|
|
2450
|
-
}
|
|
2451
|
-
else if (a.type === 'highlight') {
|
|
2452
|
-
svgParts.push(`<rect x="${a.x}" y="${a.y}" width="${a.width || 100}" height="${a.height || 100}" fill="${color}" fill-opacity="0.3"/>`);
|
|
2453
|
-
}
|
|
2454
|
-
else if (a.type === 'text') {
|
|
2455
|
-
const fs2 = a.fontSize || 24;
|
|
2456
|
-
svgParts.push(`<text x="${a.x}" y="${a.y}" font-size="${fs2}" fill="${color}" font-family="Arial, sans-serif">${escapeXml(a.text || '')}</text>`);
|
|
2457
|
-
}
|
|
2458
|
-
else if (a.type === 'arrow' && a.toX !== undefined && a.toY !== undefined) {
|
|
2459
|
-
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>`);
|
|
2460
|
-
svgParts.push(`<line x1="${a.x}" y1="${a.y}" x2="${a.toX}" y2="${a.toY}" stroke="${color}" stroke-width="2" marker-end="url(#ah)"/>`);
|
|
2461
|
-
}
|
|
2462
|
-
else if (a.type === 'blur') {
|
|
2463
|
-
blurRegions.push({ x: a.x, y: a.y, width: a.width || 100, height: a.height || 100 });
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
// Apply blur regions first
|
|
2467
|
-
let baseBuffer = await image.png().toBuffer();
|
|
2468
|
-
for (const region of blurRegions) {
|
|
2469
|
-
const extracted = await sharp(baseBuffer).extract({
|
|
2470
|
-
left: Math.max(0, Math.round(region.x)),
|
|
2471
|
-
top: Math.max(0, Math.round(region.y)),
|
|
2472
|
-
width: Math.min(Math.round(region.width), imgW - Math.round(region.x)),
|
|
2473
|
-
height: Math.min(Math.round(region.height), imgH - Math.round(region.y)),
|
|
2474
|
-
}).blur(15).toBuffer();
|
|
2475
|
-
baseBuffer = await sharp(baseBuffer).composite([{
|
|
2476
|
-
input: extracted,
|
|
2477
|
-
left: Math.max(0, Math.round(region.x)),
|
|
2478
|
-
top: Math.max(0, Math.round(region.y)),
|
|
2479
|
-
}]).png().toBuffer();
|
|
2480
|
-
}
|
|
2481
|
-
// Apply SVG overlay
|
|
2482
|
-
if (svgParts.length > 0) {
|
|
2483
|
-
const svg = `<svg width="${imgW}" height="${imgH}" xmlns="http://www.w3.org/2000/svg">${svgParts.join('')}</svg>`;
|
|
2484
|
-
baseBuffer = await sharp(baseBuffer).composite([{ input: Buffer.from(svg), top: 0, left: 0 }]).png().toBuffer();
|
|
2485
|
-
}
|
|
2486
|
-
// Optionally save over the original
|
|
2487
|
-
if (body.save) {
|
|
2488
|
-
fs.writeFileSync(capture.screenshot_path, baseBuffer);
|
|
2489
|
-
}
|
|
2490
|
-
return reply.code(200).send({
|
|
2491
|
-
imageBase64: baseBuffer.toString('base64'),
|
|
2492
|
-
mimeType: 'image/png',
|
|
2493
|
-
annotationsApplied: body.annotations.length,
|
|
2494
|
-
saved: !!body.save,
|
|
2495
|
-
});
|
|
2496
|
-
}
|
|
2497
|
-
catch (err) {
|
|
2498
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2499
|
-
}
|
|
2500
|
-
});
|
|
2501
|
-
// POST /api/recording/describe-frames — AI description of recording frames
|
|
2502
|
-
server.post('/api/recording/describe-frames', async (req, reply) => {
|
|
2503
|
-
try {
|
|
2504
|
-
const { getSessionFrames: getFrames } = await Promise.resolve().then(() => __importStar(require('../db/database')));
|
|
2505
|
-
const body = req.body || { sessionId: '' };
|
|
2506
|
-
if (!body.sessionId)
|
|
2507
|
-
return reply.code(400).send({ error: 'sessionId required' });
|
|
2508
|
-
const frames = getFrames(body.sessionId);
|
|
2509
|
-
if (!frames.length)
|
|
2510
|
-
return reply.code(404).send({ error: 'No frames found' });
|
|
2511
|
-
const limit = body.limit || 20;
|
|
2512
|
-
const selectedFrames = frames.slice(0, limit);
|
|
2513
|
-
const descriptions = [];
|
|
2514
|
-
const { dispatchAI } = await Promise.resolve().then(() => __importStar(require('./ollama/dispatcher')));
|
|
2515
|
-
let providerUsed = 'cloud';
|
|
2516
|
-
let modelUsed;
|
|
2517
|
-
try {
|
|
2518
|
-
for (const frame of selectedFrames) {
|
|
2519
|
-
if (!fs.existsSync(frame.screenshot_path))
|
|
2520
|
-
continue;
|
|
2521
|
-
const buf = fs.readFileSync(frame.screenshot_path);
|
|
2522
|
-
const imageBase64 = await (0, image_utils_1.resizeImageForAI)(buf);
|
|
2523
|
-
let description = '';
|
|
2524
|
-
const dispatch = await dispatchAI({
|
|
2525
|
-
task: 'vision',
|
|
2526
|
-
provider: body.provider,
|
|
2527
|
-
model: body.model,
|
|
2528
|
-
forceVision: body.forceVision,
|
|
2529
|
-
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.`,
|
|
2530
|
-
imagesBase64: [imageBase64],
|
|
2531
|
-
});
|
|
2532
|
-
providerUsed = dispatch.resolution.provider;
|
|
2533
|
-
modelUsed = dispatch.resolution.model;
|
|
2534
|
-
for await (const chunk of dispatch.stream) {
|
|
2535
|
-
description += chunk;
|
|
2536
|
-
}
|
|
2537
|
-
descriptions.push({ frameNumber: frame.frame_number, description });
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
catch (err) {
|
|
2541
|
-
if (err && typeof err === 'object' && 'code' in err) {
|
|
2542
|
-
const de = err;
|
|
2543
|
-
const httpCode = de.code === 'not_signed_in' ? 401 : 400;
|
|
2544
|
-
return reply.code(httpCode).send({ error: de.message, code: de.code, hint: de.hint, provider: de.provider });
|
|
2545
|
-
}
|
|
2546
|
-
return reply.code(502).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2547
|
-
}
|
|
2548
|
-
return reply.code(200).send({
|
|
2549
|
-
sessionId: body.sessionId,
|
|
2550
|
-
descriptions,
|
|
2551
|
-
provider: providerUsed,
|
|
2552
|
-
model: modelUsed,
|
|
2553
|
-
});
|
|
2554
|
-
}
|
|
2555
|
-
catch (err) {
|
|
2556
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2557
|
-
}
|
|
2558
|
-
});
|
|
2559
|
-
// POST /api/recording/narrate — generate prose summary of a session
|
|
2560
|
-
server.post('/api/recording/narrate', async (req, reply) => {
|
|
2561
|
-
try {
|
|
2562
|
-
const body = req.body || { sessionId: '' };
|
|
2563
|
-
if (!body.sessionId)
|
|
2564
|
-
return reply.code(400).send({ error: 'sessionId required' });
|
|
2565
|
-
// If descriptions not provided, generate them first
|
|
2566
|
-
const descriptions = body.descriptions;
|
|
2567
|
-
if (!descriptions) {
|
|
2568
|
-
return reply.code(400).send({ error: 'descriptions array required (use /api/recording/describe-frames first)' });
|
|
2569
|
-
}
|
|
2570
|
-
const frameList = descriptions.map((d) => `Frame ${d.frameNumber}: ${d.description}`).join('\n');
|
|
2571
|
-
let narration = '';
|
|
2572
|
-
let providerUsed = 'cloud';
|
|
2573
|
-
let modelUsed;
|
|
2574
|
-
try {
|
|
2575
|
-
const { dispatchAI } = await Promise.resolve().then(() => __importStar(require('./ollama/dispatcher')));
|
|
2576
|
-
const dispatch = await dispatchAI({
|
|
2577
|
-
task: 'chat',
|
|
2578
|
-
provider: body.provider,
|
|
2579
|
-
model: body.model,
|
|
2580
|
-
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}`,
|
|
2581
|
-
imagesBase64: [],
|
|
2582
|
-
});
|
|
2583
|
-
providerUsed = dispatch.resolution.provider;
|
|
2584
|
-
modelUsed = dispatch.resolution.model;
|
|
2585
|
-
for await (const chunk of dispatch.stream) {
|
|
2586
|
-
narration += chunk;
|
|
2587
|
-
}
|
|
2588
|
-
}
|
|
2589
|
-
catch (err) {
|
|
2590
|
-
if (err && typeof err === 'object' && 'code' in err) {
|
|
2591
|
-
const de = err;
|
|
2592
|
-
const httpCode = de.code === 'not_signed_in' ? 401 : 400;
|
|
2593
|
-
return reply.code(httpCode).send({ error: de.message, code: de.code, hint: de.hint, provider: de.provider });
|
|
2594
|
-
}
|
|
2595
|
-
return reply.code(502).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2596
|
-
}
|
|
2597
|
-
return reply.code(200).send({
|
|
2598
|
-
sessionId: body.sessionId,
|
|
2599
|
-
narration,
|
|
2600
|
-
provider: providerUsed,
|
|
2601
|
-
model: modelUsed,
|
|
2602
|
-
});
|
|
2603
|
-
}
|
|
2604
|
-
catch (err) {
|
|
2605
|
-
return reply.code(500).send({ error: err instanceof Error ? err.message : String(err) });
|
|
2606
|
-
}
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2609
|
-
function escapeXml(s) {
|
|
2610
|
-
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
2611
|
-
}
|
|
2612
|
-
// ── MCP-over-HTTP Routes ──
|
|
2613
|
-
function registerMcpHttpRoutes(server) {
|
|
2614
|
-
let mcpHandler = null;
|
|
2615
|
-
function getHandler() {
|
|
2616
|
-
if (!mcpHandler) {
|
|
2617
|
-
try {
|
|
2618
|
-
// Try multiple paths — the MCP server module location varies between
|
|
2619
|
-
// desktop (electron-builder), headless dist, and npm global install
|
|
2620
|
-
const tryPaths = [
|
|
2621
|
-
path.join(__dirname, '..', '..', 'mcp-server', 'dist', 'index.js'), // from electron/modules/ → mcp-server/dist/
|
|
2622
|
-
path.join(__dirname, '..', '..', '..', 'mcp-server', 'dist', 'index.js'), // from dist/electron/modules/ → mcp-server/dist/
|
|
2623
|
-
];
|
|
2624
|
-
let mod = null;
|
|
2625
|
-
for (const p of tryPaths) {
|
|
2626
|
-
try {
|
|
2627
|
-
if (fs.existsSync(p)) {
|
|
2628
|
-
mod = require(p);
|
|
2629
|
-
break;
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
catch { /* try next */ }
|
|
2633
|
-
}
|
|
2634
|
-
if (mod?.createMcpHttpHandler) {
|
|
2635
|
-
mcpHandler = mod.createMcpHttpHandler(currentPort);
|
|
2636
|
-
}
|
|
2637
|
-
else {
|
|
2638
|
-
logger_1.default.warn('[API] MCP HTTP handler module not found');
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
catch (err) {
|
|
2642
|
-
logger_1.default.error('[API] Failed to load MCP HTTP handler:', err);
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
return mcpHandler;
|
|
2646
|
-
}
|
|
2647
|
-
server.post('/mcp', async (request, reply) => {
|
|
2648
|
-
const handler = getHandler();
|
|
2649
|
-
if (!handler) {
|
|
2650
|
-
return reply.code(503).send({ error: 'MCP HTTP handler not available' });
|
|
2651
|
-
}
|
|
2652
|
-
// Hand off to StreamableHTTPServerTransport with raw Node.js req/res
|
|
2653
|
-
await handler.handlePost(request.raw, reply.raw, request.body);
|
|
2654
|
-
// Tell Fastify we've handled the response ourselves
|
|
2655
|
-
reply.hijack();
|
|
2656
|
-
});
|
|
2657
|
-
server.get('/mcp', async (request, reply) => {
|
|
2658
|
-
const handler = getHandler();
|
|
2659
|
-
if (!handler) {
|
|
2660
|
-
return reply.code(503).send({ error: 'MCP HTTP handler not available' });
|
|
2661
|
-
}
|
|
2662
|
-
await handler.handleGet(request.raw, reply.raw);
|
|
2663
|
-
reply.hijack();
|
|
2664
|
-
});
|
|
2665
|
-
server.delete('/mcp', async (request, reply) => {
|
|
2666
|
-
const handler = getHandler();
|
|
2667
|
-
if (!handler) {
|
|
2668
|
-
return reply.code(503).send({ error: 'MCP HTTP handler not available' });
|
|
2669
|
-
}
|
|
2670
|
-
await handler.handleDelete(request.raw, reply.raw);
|
|
2671
|
-
reply.hijack();
|
|
2672
|
-
});
|
|
2673
|
-
logger_1.default.info('[API] MCP HTTP endpoint registered at /mcp');
|
|
2674
|
-
}
|
|
2675
|
-
// ── Server Lifecycle ──
|
|
2676
|
-
// Port resolution priority: explicit arg > SUPERBASED_API_PORT env > default.
|
|
2677
|
-
// The default 47592 is the canonical port that the desktop app, the MCP
|
|
2678
|
-
// stdio bridge, and headless serve all converge on.
|
|
2679
|
-
let currentPort = API_PORT;
|
|
2680
|
-
function getApiPort() {
|
|
2681
|
-
return currentPort;
|
|
2682
|
-
}
|
|
2683
|
-
async function startApiServer(opts) {
|
|
2684
|
-
if (server)
|
|
2685
|
-
return;
|
|
2686
|
-
startTime = Date.now();
|
|
2687
|
-
authToken = generateAuthToken();
|
|
2688
|
-
currentPort = opts?.port ?? (Number(process.env.SUPERBASED_API_PORT) || API_PORT);
|
|
2689
|
-
server = (0, fastify_1.default)({ logger: false, bodyLimit: 50 * 1024 * 1024 }); // 50MB body limit for images
|
|
2690
|
-
// Register all route groups
|
|
2691
|
-
registerHealthRoutes(server);
|
|
2692
|
-
registerCaptureRoutes(server);
|
|
2693
|
-
registerAIRoutes(server);
|
|
2694
|
-
registerGalleryRoutes(server);
|
|
2695
|
-
registerSettingsRoutes(server);
|
|
2696
|
-
registerPresetsRoutes(server);
|
|
2697
|
-
// GUI automation routes (Phase 2a)
|
|
2698
|
-
registerAutomationRoutes(server);
|
|
2699
|
-
// Watcher routes + factories (Phase 3)
|
|
2700
|
-
await registerWatcherFactoriesOnce();
|
|
2701
|
-
registerWatcherRoutes(server);
|
|
2702
|
-
// Token Compression Engine route
|
|
2703
|
-
registerCompressRoutes(server);
|
|
2704
|
-
// Local STT routes (Phase 4a — capability probe + model download)
|
|
2705
|
-
registerSTTRoutes(server);
|
|
2706
|
-
// Ollama detection routes (Phase 6.1 — detection only)
|
|
2707
|
-
registerOllamaRoutes(server);
|
|
2708
|
-
// Accessibility tree routes (Phase 8.1 — macOS AX / Windows UIA)
|
|
2709
|
-
registerAccessibilityRoutes(server);
|
|
2710
|
-
// Project-orientation + workspace-sync routes (Phase 5.1)
|
|
2711
|
-
registerProjectRoutes(server);
|
|
2712
|
-
// Expanded routes (auth, license, AI usage, redact, transcribe, windows, etc.)
|
|
2713
|
-
registerExpandedRoutes(server);
|
|
2714
|
-
// Recording routes are registered separately when the recording module is enabled
|
|
2715
|
-
// They can also be registered immediately if recording is already enabled
|
|
2716
|
-
if ((0, store_1.getSetting)('recordingFeatureEnabled')) {
|
|
2717
|
-
registerRecordingRoutesOnServer();
|
|
2718
|
-
}
|
|
2719
|
-
// MCP-over-HTTP endpoint — allows URL-based MCP clients (OpenAI Codex, etc.)
|
|
2720
|
-
// to connect at http://127.0.0.1:47592/mcp instead of requiring stdio transport
|
|
2721
|
-
registerMcpHttpRoutes(server);
|
|
2722
|
-
try {
|
|
2723
|
-
await server.listen({ port: currentPort, host: API_HOST });
|
|
2724
|
-
logger_1.default.info(`[API] HTTP API listening on http://${API_HOST}:${currentPort}`);
|
|
2725
|
-
// Fire-and-forget Ollama detection probe. On positive detection, logs one
|
|
2726
|
-
// line listing models; on absence, silent. Never blocks startup.
|
|
2727
|
-
Promise.resolve().then(() => __importStar(require('./ollama/detector'))).then(({ logStartupDetection }) => logStartupDetection())
|
|
2728
|
-
.catch(() => { });
|
|
2729
|
-
}
|
|
2730
|
-
catch (err) {
|
|
2731
|
-
logger_1.default.error('[API] Failed to start HTTP API:', err);
|
|
2732
|
-
server = null;
|
|
2733
|
-
}
|
|
2734
|
-
}
|
|
2735
|
-
async function stopApiServer() {
|
|
2736
|
-
if (server) {
|
|
2737
|
-
try {
|
|
2738
|
-
const { shutdown } = await Promise.resolve().then(() => __importStar(require('./watchers/registry')));
|
|
2739
|
-
await shutdown();
|
|
2740
|
-
}
|
|
2741
|
-
catch (err) {
|
|
2742
|
-
logger_1.default.warn('[API] error shutting down watchers:', err);
|
|
2743
|
-
}
|
|
2744
|
-
await server.close();
|
|
2745
|
-
server = null;
|
|
2746
|
-
recordingRoutesRegistered = false;
|
|
2747
|
-
logger_1.default.info('[API] HTTP API stopped');
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
function getApiAuthToken() {
|
|
2751
|
-
return authToken;
|
|
2752
|
-
}
|
|
2753
|
-
function getApiServer() {
|
|
2754
|
-
return server;
|
|
2755
|
-
}
|
|
2756
|
-
function isApiServerRunning() {
|
|
2757
|
-
return server !== null;
|
|
2758
|
-
}
|