@tmhs/screencast-mcp 0.39.0 → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -17
- package/assets/icon.png +0 -0
- package/assets/ui/player.html +47 -302
- package/assets/ui/player.js +402 -0
- package/dist/context.js +0 -5
- package/dist/index.js +17 -21
- package/dist/prompts.js +18 -8
- package/dist/resources.js +2 -14
- package/dist/server.js +49 -11
- package/dist/tools/addMarker.js +89 -0
- package/dist/tools/assembleHighlights.js +12 -7
- package/dist/tools/backdrop.js +89 -0
- package/dist/tools/bugReport.js +266 -0
- package/dist/tools/burnSubtitles.js +12 -6
- package/dist/tools/callout.js +32 -16
- package/dist/tools/chapters.js +156 -0
- package/dist/tools/clip.js +12 -9
- package/dist/tools/compress.js +10 -5
- package/dist/tools/concat.js +16 -15
- package/dist/tools/contactSheet.js +39 -33
- package/dist/tools/convert.js +12 -6
- package/dist/tools/crop.js +12 -7
- package/dist/tools/cutIdle.js +15 -9
- package/dist/tools/denoise.js +12 -6
- package/dist/tools/doctor.js +133 -0
- package/dist/tools/exportGif.js +14 -10
- package/dist/tools/exportPreset.js +11 -8
- package/dist/tools/extractAudio.js +10 -8
- package/dist/tools/findText.js +52 -98
- package/dist/tools/getMediaInfo.js +17 -3
- package/dist/tools/getSession.js +15 -3
- package/dist/tools/keystrokeOverlay.js +131 -0
- package/dist/tools/listAudioDevices.js +14 -7
- package/dist/tools/listSessions.js +13 -3
- package/dist/tools/listTargets.js +76 -0
- package/dist/tools/musicBed.js +14 -10
- package/dist/tools/normalizeAudio.js +12 -8
- package/dist/tools/overlay.js +16 -12
- package/dist/tools/pipeline.js +86 -25
- package/dist/tools/readEvents.js +21 -12
- package/dist/tools/redactRegion.js +19 -17
- package/dist/tools/reframe.js +9 -5
- package/dist/tools/reviewRecording.js +75 -22
- package/dist/tools/sampleFrames.js +33 -40
- package/dist/tools/saveReplay.js +90 -0
- package/dist/tools/scale.js +9 -3
- package/dist/tools/screenDiff.js +23 -17
- package/dist/tools/screenshot.js +21 -17
- package/dist/tools/speed.js +15 -4
- package/dist/tools/startRecording.js +96 -59
- package/dist/tools/stopRecording.js +35 -10
- package/dist/tools/titleCard.js +19 -11
- package/dist/tools/transcribe.js +13 -7
- package/dist/tools/trim.js +11 -10
- package/dist/tools/waitForChange.js +37 -22
- package/dist/tools/xfadeTransition.js +12 -8
- package/dist/tools/zoom.js +26 -29
- package/dist/utils/anim.js +1 -21
- package/dist/utils/animExport.js +5 -10
- package/dist/utils/audio.js +4 -33
- package/dist/utils/audioDevices.js +1 -48
- package/dist/utils/backdrop.js +151 -0
- package/dist/utils/bugReport.js +246 -0
- package/dist/utils/callout.js +1 -19
- package/dist/utils/calloutAssets.js +21 -11
- package/dist/utils/capabilities.js +95 -0
- package/dist/utils/captions.js +9 -26
- package/dist/utils/chapters.js +222 -0
- package/dist/utils/consent.js +29 -0
- package/dist/utils/diff.js +0 -46
- package/dist/utils/errors.js +5 -13
- package/dist/utils/events.js +21 -77
- package/dist/utils/expr.js +11 -0
- package/dist/utils/ffmpeg.js +119 -48
- package/dist/utils/fontCoverage.js +177 -0
- package/dist/utils/fonts.js +139 -23
- package/dist/utils/idle.js +12 -24
- package/dist/utils/images.js +0 -17
- package/dist/utils/jobs.js +42 -41
- package/dist/utils/keystrokes.js +170 -0
- package/dist/utils/lifecycle.js +11 -31
- package/dist/utils/logging.js +75 -0
- package/dist/utils/media.js +16 -124
- package/dist/utils/monitors.js +7 -43
- package/dist/utils/ocr.js +53 -71
- package/dist/utils/ocrScan.js +77 -0
- package/dist/utils/paths.js +68 -31
- package/dist/utils/pipeline.js +39 -25
- package/dist/utils/player.js +50 -27
- package/dist/utils/produce.js +6 -66
- package/dist/utils/replay.js +278 -0
- package/dist/utils/resolveTarget.js +0 -19
- package/dist/utils/retention.js +1 -15
- package/dist/utils/roots.js +42 -0
- package/dist/utils/sessions.js +195 -160
- package/dist/utils/sheet.js +0 -19
- package/dist/utils/still.js +0 -15
- package/dist/utils/targetList.js +63 -0
- package/dist/utils/targets.js +5 -70
- package/dist/utils/toolSpec.js +25 -0
- package/dist/utils/toolsets.js +122 -0
- package/dist/utils/validate.js +0 -22
- package/dist/utils/wgc.js +0 -46
- package/dist/utils/windows.js +5 -50
- package/dist/utils/zoom.js +55 -85
- package/dist/wgcRecorder.js +1 -30
- package/package.json +7 -3
- package/dist/context.d.ts +0 -9
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts +0 -10
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js.map +0 -1
- package/dist/resources.d.ts +0 -3
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/assembleHighlights.d.ts +0 -3
- package/dist/tools/assembleHighlights.d.ts.map +0 -1
- package/dist/tools/assembleHighlights.js.map +0 -1
- package/dist/tools/burnSubtitles.d.ts +0 -3
- package/dist/tools/burnSubtitles.d.ts.map +0 -1
- package/dist/tools/burnSubtitles.js.map +0 -1
- package/dist/tools/callout.d.ts +0 -37
- package/dist/tools/callout.d.ts.map +0 -1
- package/dist/tools/callout.js.map +0 -1
- package/dist/tools/clip.d.ts +0 -3
- package/dist/tools/clip.d.ts.map +0 -1
- package/dist/tools/clip.js.map +0 -1
- package/dist/tools/compress.d.ts +0 -3
- package/dist/tools/compress.d.ts.map +0 -1
- package/dist/tools/compress.js.map +0 -1
- package/dist/tools/concat.d.ts +0 -3
- package/dist/tools/concat.d.ts.map +0 -1
- package/dist/tools/concat.js.map +0 -1
- package/dist/tools/contactSheet.d.ts +0 -3
- package/dist/tools/contactSheet.d.ts.map +0 -1
- package/dist/tools/contactSheet.js.map +0 -1
- package/dist/tools/convert.d.ts +0 -3
- package/dist/tools/convert.d.ts.map +0 -1
- package/dist/tools/convert.js.map +0 -1
- package/dist/tools/crop.d.ts +0 -3
- package/dist/tools/crop.d.ts.map +0 -1
- package/dist/tools/crop.js.map +0 -1
- package/dist/tools/cutIdle.d.ts +0 -3
- package/dist/tools/cutIdle.d.ts.map +0 -1
- package/dist/tools/cutIdle.js.map +0 -1
- package/dist/tools/denoise.d.ts +0 -3
- package/dist/tools/denoise.d.ts.map +0 -1
- package/dist/tools/denoise.js.map +0 -1
- package/dist/tools/exportGif.d.ts +0 -3
- package/dist/tools/exportGif.d.ts.map +0 -1
- package/dist/tools/exportGif.js.map +0 -1
- package/dist/tools/exportPreset.d.ts +0 -3
- package/dist/tools/exportPreset.d.ts.map +0 -1
- package/dist/tools/exportPreset.js.map +0 -1
- package/dist/tools/extractAudio.d.ts +0 -3
- package/dist/tools/extractAudio.d.ts.map +0 -1
- package/dist/tools/extractAudio.js.map +0 -1
- package/dist/tools/findText.d.ts +0 -6
- package/dist/tools/findText.d.ts.map +0 -1
- package/dist/tools/findText.js.map +0 -1
- package/dist/tools/getMediaInfo.d.ts +0 -3
- package/dist/tools/getMediaInfo.d.ts.map +0 -1
- package/dist/tools/getMediaInfo.js.map +0 -1
- package/dist/tools/getSession.d.ts +0 -3
- package/dist/tools/getSession.d.ts.map +0 -1
- package/dist/tools/getSession.js.map +0 -1
- package/dist/tools/listAudioDevices.d.ts +0 -3
- package/dist/tools/listAudioDevices.d.ts.map +0 -1
- package/dist/tools/listAudioDevices.js.map +0 -1
- package/dist/tools/listSessions.d.ts +0 -3
- package/dist/tools/listSessions.d.ts.map +0 -1
- package/dist/tools/listSessions.js.map +0 -1
- package/dist/tools/musicBed.d.ts +0 -3
- package/dist/tools/musicBed.d.ts.map +0 -1
- package/dist/tools/musicBed.js.map +0 -1
- package/dist/tools/normalizeAudio.d.ts +0 -3
- package/dist/tools/normalizeAudio.d.ts.map +0 -1
- package/dist/tools/normalizeAudio.js.map +0 -1
- package/dist/tools/overlay.d.ts +0 -3
- package/dist/tools/overlay.d.ts.map +0 -1
- package/dist/tools/overlay.js.map +0 -1
- package/dist/tools/pipeline.d.ts +0 -3
- package/dist/tools/pipeline.d.ts.map +0 -1
- package/dist/tools/pipeline.js.map +0 -1
- package/dist/tools/readEvents.d.ts +0 -6
- package/dist/tools/readEvents.d.ts.map +0 -1
- package/dist/tools/readEvents.js.map +0 -1
- package/dist/tools/redactRegion.d.ts +0 -13
- package/dist/tools/redactRegion.d.ts.map +0 -1
- package/dist/tools/redactRegion.js.map +0 -1
- package/dist/tools/reframe.d.ts +0 -3
- package/dist/tools/reframe.d.ts.map +0 -1
- package/dist/tools/reframe.js.map +0 -1
- package/dist/tools/reviewRecording.d.ts +0 -5
- package/dist/tools/reviewRecording.d.ts.map +0 -1
- package/dist/tools/reviewRecording.js.map +0 -1
- package/dist/tools/sampleFrames.d.ts +0 -3
- package/dist/tools/sampleFrames.d.ts.map +0 -1
- package/dist/tools/sampleFrames.js.map +0 -1
- package/dist/tools/scale.d.ts +0 -3
- package/dist/tools/scale.d.ts.map +0 -1
- package/dist/tools/scale.js.map +0 -1
- package/dist/tools/screenDiff.d.ts +0 -3
- package/dist/tools/screenDiff.d.ts.map +0 -1
- package/dist/tools/screenDiff.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -3
- package/dist/tools/screenshot.d.ts.map +0 -1
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/speed.d.ts +0 -3
- package/dist/tools/speed.d.ts.map +0 -1
- package/dist/tools/speed.js.map +0 -1
- package/dist/tools/startRecording.d.ts +0 -3
- package/dist/tools/startRecording.d.ts.map +0 -1
- package/dist/tools/startRecording.js.map +0 -1
- package/dist/tools/stopRecording.d.ts +0 -3
- package/dist/tools/stopRecording.d.ts.map +0 -1
- package/dist/tools/stopRecording.js.map +0 -1
- package/dist/tools/titleCard.d.ts +0 -3
- package/dist/tools/titleCard.d.ts.map +0 -1
- package/dist/tools/titleCard.js.map +0 -1
- package/dist/tools/transcribe.d.ts +0 -3
- package/dist/tools/transcribe.d.ts.map +0 -1
- package/dist/tools/transcribe.js.map +0 -1
- package/dist/tools/trim.d.ts +0 -3
- package/dist/tools/trim.d.ts.map +0 -1
- package/dist/tools/trim.js.map +0 -1
- package/dist/tools/waitForChange.d.ts +0 -3
- package/dist/tools/waitForChange.d.ts.map +0 -1
- package/dist/tools/waitForChange.js.map +0 -1
- package/dist/tools/xfadeTransition.d.ts +0 -3
- package/dist/tools/xfadeTransition.d.ts.map +0 -1
- package/dist/tools/xfadeTransition.js.map +0 -1
- package/dist/tools/zoom.d.ts +0 -15
- package/dist/tools/zoom.d.ts.map +0 -1
- package/dist/tools/zoom.js.map +0 -1
- package/dist/utils/anim.d.ts +0 -33
- package/dist/utils/anim.d.ts.map +0 -1
- package/dist/utils/anim.js.map +0 -1
- package/dist/utils/animExport.d.ts +0 -27
- package/dist/utils/animExport.d.ts.map +0 -1
- package/dist/utils/animExport.js.map +0 -1
- package/dist/utils/audio.d.ts +0 -49
- package/dist/utils/audio.d.ts.map +0 -1
- package/dist/utils/audio.js.map +0 -1
- package/dist/utils/audioDevices.d.ts +0 -33
- package/dist/utils/audioDevices.d.ts.map +0 -1
- package/dist/utils/audioDevices.js.map +0 -1
- package/dist/utils/callout.d.ts +0 -72
- package/dist/utils/callout.d.ts.map +0 -1
- package/dist/utils/callout.js.map +0 -1
- package/dist/utils/calloutAssets.d.ts +0 -3
- package/dist/utils/calloutAssets.d.ts.map +0 -1
- package/dist/utils/calloutAssets.js.map +0 -1
- package/dist/utils/captions.d.ts +0 -26
- package/dist/utils/captions.d.ts.map +0 -1
- package/dist/utils/captions.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -112
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/errors.d.ts +0 -33
- package/dist/utils/errors.d.ts.map +0 -1
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/events.d.ts +0 -143
- package/dist/utils/events.d.ts.map +0 -1
- package/dist/utils/events.js.map +0 -1
- package/dist/utils/ffmpeg.d.ts +0 -50
- package/dist/utils/ffmpeg.d.ts.map +0 -1
- package/dist/utils/ffmpeg.js.map +0 -1
- package/dist/utils/fonts.d.ts +0 -17
- package/dist/utils/fonts.d.ts.map +0 -1
- package/dist/utils/fonts.js.map +0 -1
- package/dist/utils/idle.d.ts +0 -23
- package/dist/utils/idle.d.ts.map +0 -1
- package/dist/utils/idle.js.map +0 -1
- package/dist/utils/images.d.ts +0 -21
- package/dist/utils/images.d.ts.map +0 -1
- package/dist/utils/images.js.map +0 -1
- package/dist/utils/jobs.d.ts +0 -44
- package/dist/utils/jobs.d.ts.map +0 -1
- package/dist/utils/jobs.js.map +0 -1
- package/dist/utils/lifecycle.d.ts +0 -29
- package/dist/utils/lifecycle.d.ts.map +0 -1
- package/dist/utils/lifecycle.js.map +0 -1
- package/dist/utils/media.d.ts +0 -272
- package/dist/utils/media.d.ts.map +0 -1
- package/dist/utils/media.js.map +0 -1
- package/dist/utils/monitors.d.ts +0 -47
- package/dist/utils/monitors.d.ts.map +0 -1
- package/dist/utils/monitors.js.map +0 -1
- package/dist/utils/ocr.d.ts +0 -50
- package/dist/utils/ocr.d.ts.map +0 -1
- package/dist/utils/ocr.js.map +0 -1
- package/dist/utils/paths.d.ts +0 -28
- package/dist/utils/paths.d.ts.map +0 -1
- package/dist/utils/paths.js.map +0 -1
- package/dist/utils/pipeline.d.ts +0 -69
- package/dist/utils/pipeline.d.ts.map +0 -1
- package/dist/utils/pipeline.js.map +0 -1
- package/dist/utils/player.d.ts +0 -30
- package/dist/utils/player.d.ts.map +0 -1
- package/dist/utils/player.js.map +0 -1
- package/dist/utils/produce.d.ts +0 -126
- package/dist/utils/produce.d.ts.map +0 -1
- package/dist/utils/produce.js.map +0 -1
- package/dist/utils/resolveTarget.d.ts +0 -32
- package/dist/utils/resolveTarget.d.ts.map +0 -1
- package/dist/utils/resolveTarget.js.map +0 -1
- package/dist/utils/retention.d.ts +0 -10
- package/dist/utils/retention.d.ts.map +0 -1
- package/dist/utils/retention.js.map +0 -1
- package/dist/utils/sessions.d.ts +0 -154
- package/dist/utils/sessions.d.ts.map +0 -1
- package/dist/utils/sessions.js.map +0 -1
- package/dist/utils/sheet.d.ts +0 -26
- package/dist/utils/sheet.d.ts.map +0 -1
- package/dist/utils/sheet.js.map +0 -1
- package/dist/utils/still.d.ts +0 -7
- package/dist/utils/still.d.ts.map +0 -1
- package/dist/utils/still.js.map +0 -1
- package/dist/utils/targets.d.ts +0 -113
- package/dist/utils/targets.d.ts.map +0 -1
- package/dist/utils/targets.js.map +0 -1
- package/dist/utils/validate.d.ts +0 -15
- package/dist/utils/validate.d.ts.map +0 -1
- package/dist/utils/validate.js.map +0 -1
- package/dist/utils/wgc.d.ts +0 -46
- package/dist/utils/wgc.d.ts.map +0 -1
- package/dist/utils/wgc.js.map +0 -1
- package/dist/utils/windows.d.ts +0 -94
- package/dist/utils/windows.d.ts.map +0 -1
- package/dist/utils/windows.js.map +0 -1
- package/dist/utils/zoom.d.ts +0 -95
- package/dist/utils/zoom.d.ts.map +0 -1
- package/dist/utils/zoom.js.map +0 -1
- package/dist/wgcRecorder.d.ts +0 -2
- package/dist/wgcRecorder.d.ts.map +0 -1
- package/dist/wgcRecorder.js.map +0 -1
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
5
|
+
import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
5
6
|
import { requireFfmpeg, probeMedia, runFfmpegBuffer } from "../utils/ffmpeg.js";
|
|
6
7
|
import { jobTimeoutMs } from "../utils/jobs.js";
|
|
7
|
-
import {
|
|
8
|
+
import { tempPath } from "../utils/paths.js";
|
|
9
|
+
import { buildPlayerFramesArgs, clientSupportsApps, parsePlayerFrameLog, pickPlayerFrames, playerFramePlan, splitJpegs, DEFAULT_PLAYER_FRAMES, DEFAULT_PLAYER_WIDTH, MAX_PLAYER_FRAMES, MCP_APP_MIME, PLAYER_TOOL_META, PLAYER_URI, } from "../utils/player.js";
|
|
8
10
|
import { getStore } from "../context.js";
|
|
9
|
-
|
|
11
|
+
import { markersOrChapters, readMarkers } from "../utils/chapters.js";
|
|
12
|
+
const uiAsset = (name) => readFileSync(fileURLToPath(new URL(`../../assets/ui/${name}`, import.meta.url)), "utf8");
|
|
10
13
|
export function playerHtml() {
|
|
11
|
-
|
|
14
|
+
const js = uiAsset("player.js");
|
|
15
|
+
if (/<\/script/i.test(js))
|
|
16
|
+
throw new ScreencastError("player.js must not contain a closing script tag.");
|
|
17
|
+
return uiAsset("player.html").replace('<script src="player.js"></script>', () => `<script>\n${js}</script>`);
|
|
12
18
|
}
|
|
13
19
|
function resolveInput(args) {
|
|
14
20
|
if (args.sessionId) {
|
|
@@ -23,8 +29,10 @@ function resolveInput(args) {
|
|
|
23
29
|
return args.input;
|
|
24
30
|
throw new ScreencastError("Pass input or sessionId.");
|
|
25
31
|
}
|
|
32
|
+
function markersField(markers) {
|
|
33
|
+
return markers && markers.length > 0 ? { markers: markers.map(({ t, label }) => ({ t, label })) } : {};
|
|
34
|
+
}
|
|
26
35
|
export function register(server) {
|
|
27
|
-
// The player page itself, for hosts that support MCP Apps.
|
|
28
36
|
server.registerResource("review-player", PLAYER_URI, {
|
|
29
37
|
title: "Recording review player",
|
|
30
38
|
description: "Interactive player: scrub, trim, and draw redaction boxes on a recording.",
|
|
@@ -33,14 +41,22 @@ export function register(server) {
|
|
|
33
41
|
contents: [{ uri: PLAYER_URI, mimeType: MCP_APP_MIME, text: playerHtml(), _meta: { ui: { prefersBorder: true } } }],
|
|
34
42
|
}));
|
|
35
43
|
server.registerTool("review_recording", {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"video's details; use contact_sheet or sample_frames to look at it.",
|
|
44
|
+
title: "Review Recording",
|
|
45
|
+
description: "Open a recording for a person to review: in MCP Apps clients an inline player to scrub, trim, " +
|
|
46
|
+
"and redact, then export; elsewhere just the video's details.",
|
|
40
47
|
inputSchema: {
|
|
41
48
|
input: z.string().optional().describe("Path to the video."),
|
|
42
49
|
sessionId: z.string().optional().describe("Or the session id of a stopped recording."),
|
|
43
50
|
},
|
|
51
|
+
outputSchema: looseOutput({
|
|
52
|
+
input: z.string(),
|
|
53
|
+
durationSec: z.number().nullable(),
|
|
54
|
+
width: z.number().nullable(),
|
|
55
|
+
height: z.number().nullable(),
|
|
56
|
+
fps: z.number().nullable(),
|
|
57
|
+
hasAudio: z.boolean(),
|
|
58
|
+
}),
|
|
59
|
+
annotations: READ_ONLY,
|
|
44
60
|
_meta: PLAYER_TOOL_META,
|
|
45
61
|
}, async (args) => {
|
|
46
62
|
try {
|
|
@@ -56,6 +72,7 @@ export function register(server) {
|
|
|
56
72
|
height: info.height,
|
|
57
73
|
fps: info.fps,
|
|
58
74
|
hasAudio: info.audioCodec !== null,
|
|
75
|
+
...markersField(args.sessionId ? getStore().get(args.sessionId)?.markers ?? readMarkers(input) : readMarkers(input)),
|
|
59
76
|
note: "Clients with MCP Apps show an inline review player for this result. Without it, " +
|
|
60
77
|
"look with contact_sheet or sample_frames, then trim and redact with pipeline.",
|
|
61
78
|
});
|
|
@@ -64,27 +81,54 @@ export function register(server) {
|
|
|
64
81
|
return errorResponse(error);
|
|
65
82
|
}
|
|
66
83
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
description: "Preview frames for the review player: JPEGs
|
|
70
|
-
"Used by the inline player; agents should use
|
|
84
|
+
const playerFrames = server.registerTool("player_frames", {
|
|
85
|
+
title: "Player Frames",
|
|
86
|
+
description: "Preview frames for the review player: JPEGs on an even grid over the video plus frames at " +
|
|
87
|
+
"scene changes, with their real times. Used by the inline player; agents should use " +
|
|
88
|
+
"sample_frames or contact_sheet instead.",
|
|
71
89
|
inputSchema: {
|
|
72
90
|
input: z.string().min(1).describe("Path to the video."),
|
|
73
|
-
maxFrames: z.number().int().min(1).max(MAX_PLAYER_FRAMES).optional().describe(`
|
|
91
|
+
maxFrames: z.number().int().min(1).max(MAX_PLAYER_FRAMES).optional().describe(`Frames on the even grid (default ${DEFAULT_PLAYER_FRAMES}); scene-change frames come on top, up to as many again.`),
|
|
74
92
|
width: z.number().int().min(64).max(1280).optional().describe(`Frame width (default ${DEFAULT_PLAYER_WIDTH}).`),
|
|
75
93
|
},
|
|
94
|
+
annotations: READ_ONLY,
|
|
76
95
|
_meta: { ui: { visibility: ["app"] } },
|
|
77
|
-
}, async (args) => {
|
|
96
|
+
}, async (args, extra) => {
|
|
78
97
|
try {
|
|
79
98
|
requireFfmpeg();
|
|
80
99
|
if (!existsSync(args.input))
|
|
81
100
|
throw new ScreencastError(`Input file not found: ${args.input}`);
|
|
82
101
|
const info = await probeMedia(args.input);
|
|
83
102
|
const durationSec = info.durationSec ?? 0;
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
103
|
+
const plan = playerFramePlan(durationSec, args.maxFrames ?? DEFAULT_PLAYER_FRAMES);
|
|
104
|
+
const log = tempPath(".txt");
|
|
105
|
+
let jpegs;
|
|
106
|
+
let frames;
|
|
107
|
+
try {
|
|
108
|
+
const raw = await runFfmpegBuffer(buildPlayerFramesArgs(args.input, plan, args.width ?? DEFAULT_PLAYER_WIDTH, log), jobTimeoutMs(durationSec), { signal: extra.signal });
|
|
109
|
+
jpegs = splitJpegs(raw);
|
|
110
|
+
frames = parsePlayerFrameLog(existsSync(log) ? readFileSync(log, "utf8") : "").slice(0, jpegs.length);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
rmSync(log, { force: true });
|
|
114
|
+
}
|
|
115
|
+
const [firstFrame] = frames;
|
|
116
|
+
if (!firstFrame)
|
|
117
|
+
throw new ScreencastError("ffmpeg returned no preview frames.");
|
|
118
|
+
const keep = pickPlayerFrames(frames, plan.count).flatMap((i) => {
|
|
119
|
+
const frame = frames[i];
|
|
120
|
+
const jpeg = jpegs[i];
|
|
121
|
+
return frame && jpeg ? [{ frame, jpeg }] : [];
|
|
122
|
+
});
|
|
123
|
+
const t0 = firstFrame.timeSec;
|
|
124
|
+
let markers = [];
|
|
125
|
+
try {
|
|
126
|
+
markers = (await markersOrChapters(args.input, extra.signal)).markers.map(({ t, label }) => ({ t, label }));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
}
|
|
130
|
+
const frameTimes = keep.map(({ frame }) => Math.round((frame.timeSec - t0) * 1000) / 1000);
|
|
131
|
+
const sceneFrames = keep.flatMap(({ frame }, k) => (frame.scene ? [k] : []));
|
|
88
132
|
return {
|
|
89
133
|
content: [
|
|
90
134
|
{
|
|
@@ -95,10 +139,13 @@ export function register(server) {
|
|
|
95
139
|
width: info.width,
|
|
96
140
|
height: info.height,
|
|
97
141
|
hasAudio: info.audioCodec !== null,
|
|
98
|
-
frameTimes
|
|
142
|
+
frameTimes,
|
|
143
|
+
intervalSec: plan.intervalSec,
|
|
144
|
+
sceneFrames,
|
|
145
|
+
markers,
|
|
99
146
|
}),
|
|
100
147
|
},
|
|
101
|
-
...
|
|
148
|
+
...keep.map(({ jpeg }) => ({ type: "image", data: jpeg.toString("base64"), mimeType: "image/jpeg" })),
|
|
102
149
|
],
|
|
103
150
|
};
|
|
104
151
|
}
|
|
@@ -106,5 +153,11 @@ export function register(server) {
|
|
|
106
153
|
return errorResponse(error);
|
|
107
154
|
}
|
|
108
155
|
});
|
|
156
|
+
playerFrames.disable();
|
|
157
|
+
const previous = server.server.oninitialized;
|
|
158
|
+
server.server.oninitialized = () => {
|
|
159
|
+
previous?.();
|
|
160
|
+
if (clientSupportsApps(server.server.getClientCapabilities()))
|
|
161
|
+
playerFrames.enable();
|
|
162
|
+
};
|
|
109
163
|
}
|
|
110
|
-
//# sourceMappingURL=reviewRecording.js.map
|
|
@@ -2,77 +2,81 @@ import { z } from "zod";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { mkdirSync, readdirSync, existsSync, rmSync } from "node:fs";
|
|
4
4
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
5
|
+
import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
5
6
|
import { requireFfmpeg, runFfmpeg, runCapture, probeMedia } from "../utils/ffmpeg.js";
|
|
6
7
|
import { jobTimeoutMs } from "../utils/jobs.js";
|
|
7
8
|
import { buildSampleByFpsArgs, buildSampleAtTimestampArgs, planFpsSampling, buildSceneScanArgs, parseSceneScan, pickSceneFrames, DEFAULT_SCENE_THRESHOLD, DEFAULT_MAX_FRAMES, MAX_FRAMES_CEILING, } from "../utils/media.js";
|
|
8
|
-
import { subdir, stamp, rand, sequencePattern } from "../utils/paths.js";
|
|
9
|
+
import { subdir, stamp, rand, sequencePattern, resolveOutputDir } from "../utils/paths.js";
|
|
9
10
|
import { encodeInlineImages, clampInlineCount, DEFAULT_MAX_IMAGE_WIDTH, DEFAULT_MAX_INLINE_IMAGES, MAX_INLINE_IMAGES, } from "../utils/images.js";
|
|
10
11
|
const inputSchema = {
|
|
11
12
|
input: z.string().min(1).describe("Path to the source video file."),
|
|
12
13
|
mode: z
|
|
13
14
|
.enum(["fps", "timestamps", "scenes"])
|
|
14
15
|
.optional()
|
|
15
|
-
.describe("
|
|
16
|
-
"
|
|
17
|
-
"usually the cheapest way to review a recording. Defaults to 'fps' or " +
|
|
18
|
-
"'timestamps' depending on which of those is given."),
|
|
16
|
+
.describe("scenes: only frames where the screen changed (strongest first), usually the cheapest review. " +
|
|
17
|
+
"Default: fps or timestamps, whichever is given."),
|
|
19
18
|
fps: z
|
|
20
19
|
.number()
|
|
21
20
|
.positive()
|
|
22
21
|
.optional()
|
|
23
|
-
.describe("
|
|
22
|
+
.describe("Frames per second (mode fps)."),
|
|
24
23
|
timestamps: z
|
|
25
24
|
.array(z.number().nonnegative())
|
|
26
25
|
.optional()
|
|
27
|
-
.describe("
|
|
26
|
+
.describe("Seconds to grab a frame at (mode timestamps)."),
|
|
28
27
|
sceneThreshold: z
|
|
29
28
|
.number()
|
|
30
29
|
.gt(0)
|
|
31
30
|
.lt(1)
|
|
32
31
|
.optional()
|
|
33
|
-
.describe(`Mode
|
|
34
|
-
"raise it to keep only big changes)."),
|
|
32
|
+
.describe(`Mode scenes: change needed to count, 0-1 (default ${DEFAULT_SCENE_THRESHOLD}).`),
|
|
35
33
|
dedupe: z
|
|
36
34
|
.boolean()
|
|
37
35
|
.optional()
|
|
38
|
-
.describe("Mode
|
|
36
|
+
.describe("Mode fps: drop near-duplicate frames (default false)."),
|
|
39
37
|
outputDir: z
|
|
40
38
|
.string()
|
|
41
39
|
.optional()
|
|
42
|
-
.describe("Optional folder for the frames. Defaults to SCREENCAST_HOME/frames/<id>."),
|
|
40
|
+
.describe("Optional folder for the frames (a relative path resolves under SCREENCAST_HOME/frames). Defaults to SCREENCAST_HOME/frames/<id>."),
|
|
43
41
|
maxFrames: z
|
|
44
42
|
.number()
|
|
45
43
|
.int()
|
|
46
44
|
.min(1)
|
|
47
45
|
.max(MAX_FRAMES_CEILING)
|
|
48
46
|
.optional()
|
|
49
|
-
.describe(`
|
|
50
|
-
"In fps mode a rate that would exceed it is lowered so the frames still span the whole video."),
|
|
47
|
+
.describe(`Frame cap (default ${DEFAULT_MAX_FRAMES}); fps is lowered to fit while still spanning the video.`),
|
|
51
48
|
returnImages: z
|
|
52
49
|
.boolean()
|
|
53
50
|
.optional()
|
|
54
|
-
.describe("
|
|
55
|
-
"(default true). Only the first maxInlineImages frames are embedded."),
|
|
51
|
+
.describe("Return the first maxInlineImages frames inline (default true)."),
|
|
56
52
|
maxInlineImages: z
|
|
57
53
|
.number()
|
|
58
54
|
.int()
|
|
59
55
|
.min(0)
|
|
60
56
|
.max(MAX_INLINE_IMAGES)
|
|
61
57
|
.optional()
|
|
62
|
-
.describe(`
|
|
63
|
-
"Every frame is still written to disk and listed by path."),
|
|
58
|
+
.describe(`Frames to embed inline (default ${DEFAULT_MAX_INLINE_IMAGES}); all are listed by path.`),
|
|
64
59
|
maxImageWidth: z
|
|
65
60
|
.number()
|
|
66
61
|
.int()
|
|
67
62
|
.min(16)
|
|
68
63
|
.optional()
|
|
69
|
-
.describe(`
|
|
64
|
+
.describe(`Max inline image width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
|
|
70
65
|
};
|
|
71
66
|
export function register(server) {
|
|
72
|
-
server.
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
67
|
+
server.registerTool("sample_frames", {
|
|
68
|
+
title: "Sample Frames",
|
|
69
|
+
description: "Sample PNG frames from a video (by fps, timestamps, or scene changes) and return the first " +
|
|
70
|
+
"few inline so the model can see what happened.",
|
|
71
|
+
inputSchema,
|
|
72
|
+
outputSchema: looseOutput({
|
|
73
|
+
frameDir: z.string(),
|
|
74
|
+
frameCount: z.number().int(),
|
|
75
|
+
frames: z.array(z.string()),
|
|
76
|
+
mode: z.string(),
|
|
77
|
+
}),
|
|
78
|
+
annotations: READ_ONLY,
|
|
79
|
+
}, async (args, extra) => {
|
|
76
80
|
try {
|
|
77
81
|
requireFfmpeg();
|
|
78
82
|
if (!existsSync(args.input)) {
|
|
@@ -93,34 +97,28 @@ export function register(server) {
|
|
|
93
97
|
throw new ScreencastError(`${args.timestamps.length} timestamps exceeds maxFrames (${maxFrames}). ` +
|
|
94
98
|
`Pass fewer timestamps, or raise maxFrames (up to ${MAX_FRAMES_CEILING}).`);
|
|
95
99
|
}
|
|
96
|
-
// Size an fps request against the video's length before writing
|
|
97
|
-
// anything, so a high rate on a long recording cannot fill the disk (#80).
|
|
98
100
|
const durationSec = mode === "timestamps" ? null : (await probeMedia(args.input)).durationSec;
|
|
99
101
|
const plan = mode === "fps" ? planFpsSampling(durationSec, args.fps, maxFrames) : null;
|
|
100
|
-
// Scenes (#114): a cheap low-res pass finds where the screen changed;
|
|
101
|
-
// the chosen moments are then grabbed at full size like timestamps.
|
|
102
102
|
let scenes = null;
|
|
103
103
|
let sceneTimes = [];
|
|
104
104
|
if (mode === "scenes") {
|
|
105
105
|
const { ffmpeg } = requireFfmpeg();
|
|
106
|
-
const scan = await runCapture(ffmpeg, buildSceneScanArgs(args.input, args.sceneThreshold ?? DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec));
|
|
106
|
+
const scan = await runCapture(ffmpeg, buildSceneScanArgs(args.input, args.sceneThreshold ?? DEFAULT_SCENE_THRESHOLD), jobTimeoutMs(durationSec), { signal: extra.signal });
|
|
107
107
|
if (scan.code !== 0) {
|
|
108
108
|
throw new ScreencastError(`Scene scan failed (exit ${scan.code}): ${scan.stderr.trim().slice(-400)}`);
|
|
109
109
|
}
|
|
110
110
|
scenes = parseSceneScan(scan.stdout);
|
|
111
111
|
sceneTimes = pickSceneFrames(scenes, maxFrames);
|
|
112
112
|
}
|
|
113
|
-
const dir = args.outputDir ?? join(subdir("frames"), `sample-${stamp()}-${rand()}`);
|
|
113
|
+
const dir = resolveOutputDir(args.outputDir, subdir("frames")) ?? join(subdir("frames"), `sample-${stamp()}-${rand()}`);
|
|
114
114
|
mkdirSync(dir, { recursive: true });
|
|
115
115
|
let frames = [];
|
|
116
116
|
const skipped = [];
|
|
117
117
|
if (plan) {
|
|
118
118
|
const isPng = (f) => f.endsWith(".png");
|
|
119
|
-
// Snapshot any pre-existing PNGs so a reused outputDir does not
|
|
120
|
-
// contaminate the result; return only the frames this run wrote.
|
|
121
119
|
const before = new Set(readdirSync(dir).filter(isPng));
|
|
122
120
|
const pattern = sequencePattern(dir, "frame_%05d.png");
|
|
123
|
-
await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, pattern, maxFrames, args.dedupe === true),
|
|
121
|
+
await runFfmpeg(buildSampleByFpsArgs(args.input, plan.fps, pattern, maxFrames, args.dedupe === true), jobTimeoutMs(durationSec), { signal: extra.signal });
|
|
124
122
|
frames = readdirSync(dir)
|
|
125
123
|
.filter(isPng)
|
|
126
124
|
.filter((f) => !before.has(f))
|
|
@@ -129,18 +127,14 @@ export function register(server) {
|
|
|
129
127
|
}
|
|
130
128
|
else {
|
|
131
129
|
const ts = mode === "scenes" ? sceneTimes : args.timestamps;
|
|
132
|
-
for (
|
|
133
|
-
const out = join(dir, `frame_${String(i).padStart(3, "0")}_${
|
|
134
|
-
// Clear any stale file at this path (reused outputDir) so existence
|
|
135
|
-
// after the run reflects only what this invocation wrote.
|
|
130
|
+
for (const [i, t] of ts.entries()) {
|
|
131
|
+
const out = join(dir, `frame_${String(i).padStart(3, "0")}_${t}s.png`);
|
|
136
132
|
rmSync(out, { force: true });
|
|
137
|
-
await runFfmpeg(buildSampleAtTimestampArgs(args.input,
|
|
138
|
-
// A timestamp past the end of the video makes ffmpeg exit 0 without
|
|
139
|
-
// writing a file. Report only frames that actually exist (#35).
|
|
133
|
+
await runFfmpeg(buildSampleAtTimestampArgs(args.input, t, out), 60_000, { signal: extra.signal });
|
|
140
134
|
if (existsSync(out))
|
|
141
135
|
frames.push(out);
|
|
142
136
|
else
|
|
143
|
-
skipped.push(
|
|
137
|
+
skipped.push(t);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
140
|
const inline = args.returnImages === false
|
|
@@ -200,4 +194,3 @@ export function register(server) {
|
|
|
200
194
|
}
|
|
201
195
|
});
|
|
202
196
|
}
|
|
203
|
-
//# sourceMappingURL=sampleFrames.js.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
3
|
+
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
4
|
+
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
|
+
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
6
|
+
import { eventPaths, prepareEventPaths } from "../utils/events.js";
|
|
7
|
+
import { logMessage } from "../utils/logging.js";
|
|
8
|
+
import { MAX_REPLAY_SEC, replayDiskBytes, saveReplay } from "../utils/replay.js";
|
|
9
|
+
import { getStore } from "../context.js";
|
|
10
|
+
const inputSchema = {
|
|
11
|
+
sessionId: z.string().min(1).describe("Session id of a replay buffer."),
|
|
12
|
+
lastSec: z
|
|
13
|
+
.number()
|
|
14
|
+
.positive()
|
|
15
|
+
.max(MAX_REPLAY_SEC)
|
|
16
|
+
.optional()
|
|
17
|
+
.describe("Seconds back from now (default and max: the buffer length)."),
|
|
18
|
+
output: z.string().optional().describe("Output .mp4 path (default under SCREENCAST_HOME/recordings)."),
|
|
19
|
+
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
20
|
+
reencode: z
|
|
21
|
+
.boolean()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("Frame-exact re-encode. Default: instant stream copy that may hide up to 2 s of earlier frames."),
|
|
24
|
+
};
|
|
25
|
+
export function register(server) {
|
|
26
|
+
server.registerTool("save_replay", {
|
|
27
|
+
title: "Save Replay",
|
|
28
|
+
description: "Save the last N seconds of a replay buffer (start_recording replayBufferSec) to an mp4; the buffer keeps running.",
|
|
29
|
+
inputSchema,
|
|
30
|
+
outputSchema: looseOutput({
|
|
31
|
+
sessionId: z.string(),
|
|
32
|
+
outputPath: z.string(),
|
|
33
|
+
durationSec: z.number(),
|
|
34
|
+
}),
|
|
35
|
+
annotations: WRITES_FILE,
|
|
36
|
+
}, async (args, extra) => {
|
|
37
|
+
try {
|
|
38
|
+
const record = getStore().get(args.sessionId);
|
|
39
|
+
if (!record)
|
|
40
|
+
throw new ScreencastError(`No session with id "${args.sessionId}".`);
|
|
41
|
+
if (!record.replay) {
|
|
42
|
+
throw new ScreencastError(`Session "${args.sessionId}" is not a replay buffer.`, "Start one with start_recording { replayBufferSec: 60 }; for an ordinary recording use stop_recording and trim.");
|
|
43
|
+
}
|
|
44
|
+
const { ffmpeg, ffprobe } = requireFfmpeg();
|
|
45
|
+
const buf = record.replay;
|
|
46
|
+
const lastSec = Math.min(args.lastSec ?? buf.bufferSec, buf.bufferSec);
|
|
47
|
+
const output = resolveOutput(args.output, subdir("recordings"), `replay-${stamp()}-${rand()}.mp4`, args.overwrite);
|
|
48
|
+
if (buf.events)
|
|
49
|
+
prepareEventPaths(eventPaths(output), args.overwrite);
|
|
50
|
+
const started = Date.now();
|
|
51
|
+
const result = await saveReplay(buf, {
|
|
52
|
+
ffmpeg,
|
|
53
|
+
ffprobe,
|
|
54
|
+
lastSec,
|
|
55
|
+
output,
|
|
56
|
+
reencode: args.reencode,
|
|
57
|
+
quality: record.quality,
|
|
58
|
+
live: record.status === "recording",
|
|
59
|
+
signal: extra.signal,
|
|
60
|
+
});
|
|
61
|
+
const elapsedMs = Date.now() - started;
|
|
62
|
+
logMessage("info", `Saved ${result.durationSec}s of replay ${record.id} to ${output}.`, {
|
|
63
|
+
sessionId: record.id,
|
|
64
|
+
outputPath: output,
|
|
65
|
+
durationSec: result.durationSec,
|
|
66
|
+
});
|
|
67
|
+
const short = result.durationSec + 0.25 < lastSec;
|
|
68
|
+
return okResponse({
|
|
69
|
+
sessionId: record.id,
|
|
70
|
+
...result,
|
|
71
|
+
requestedSec: args.lastSec ?? null,
|
|
72
|
+
bufferSec: buf.bufferSec,
|
|
73
|
+
bufferRunning: record.status === "recording",
|
|
74
|
+
bufferDiskBytes: replayDiskBytes(buf),
|
|
75
|
+
elapsedMs,
|
|
76
|
+
note: (args.lastSec !== undefined && args.lastSec > buf.bufferSec
|
|
77
|
+
? `Capped at the buffer length (${buf.bufferSec}s). `
|
|
78
|
+
: "") +
|
|
79
|
+
(short ? "The buffer held less footage than requested (it started recently). " : "") +
|
|
80
|
+
(result.includesLive ? "" : "The clip ends at the last completed segment, up to 2 s before now. ") +
|
|
81
|
+
(record.status === "recording"
|
|
82
|
+
? "The buffer keeps running; stop_recording discards it unless save: true."
|
|
83
|
+
: "This buffer is no longer recording; stop_recording discards it."),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
return errorResponse(error);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
package/dist/tools/scale.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
+
import { OUTPUT_PATH, WRITES_FILE } from "../utils/toolSpec.js";
|
|
4
5
|
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
5
6
|
import { runEditJob, probeDuration } from "../utils/jobs.js";
|
|
6
7
|
import { buildScaleArgs, editOutputExt, assertEditContainer } from "../utils/media.js";
|
|
@@ -13,8 +14,14 @@ const inputSchema = {
|
|
|
13
14
|
overwrite: z.boolean().optional().describe("Allow replacing an existing file at the output path (default false)."),
|
|
14
15
|
};
|
|
15
16
|
export function register(server) {
|
|
16
|
-
server.
|
|
17
|
-
"
|
|
17
|
+
server.registerTool("scale", {
|
|
18
|
+
title: "Scale Video",
|
|
19
|
+
description: "Resize a video to a target width and/or height and re-encode. Provide one " +
|
|
20
|
+
"side to keep the aspect ratio, or both to set an exact size.",
|
|
21
|
+
inputSchema,
|
|
22
|
+
outputSchema: OUTPUT_PATH,
|
|
23
|
+
annotations: WRITES_FILE,
|
|
24
|
+
}, async (args, extra) => {
|
|
18
25
|
try {
|
|
19
26
|
requireFfmpeg();
|
|
20
27
|
if (!existsSync(args.input)) {
|
|
@@ -35,4 +42,3 @@ export function register(server) {
|
|
|
35
42
|
}
|
|
36
43
|
});
|
|
37
44
|
}
|
|
38
|
-
//# sourceMappingURL=scale.js.map
|
package/dist/tools/screenDiff.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { existsSync, rmSync } from "node:fs";
|
|
3
3
|
import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
|
|
4
|
+
import { READ_ONLY, looseOutput } from "../utils/toolSpec.js";
|
|
4
5
|
import { requireFfmpeg, runCapture, runFfmpeg, runFfmpegBuffer, probeMedia } from "../utils/ffmpeg.js";
|
|
5
6
|
import { detectionSize, diffFrames, buildRawFrameArgs, buildSsimArgs, buildHighlightArgs, parseSsim, DEFAULT_PIXEL_THRESHOLD, } from "../utils/diff.js";
|
|
6
7
|
import { stamp, rand } from "../utils/paths.js";
|
|
@@ -8,25 +9,34 @@ import { tmpdir } from "node:os";
|
|
|
8
9
|
import { join } from "node:path";
|
|
9
10
|
import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
|
|
10
11
|
const inputSchema = {
|
|
11
|
-
a: z.string().min(1).describe("
|
|
12
|
-
b: z.string().min(1).describe("
|
|
12
|
+
a: z.string().min(1).describe("Before image (or video: first frame)."),
|
|
13
|
+
b: z.string().min(1).describe("After image (or video); scaled to a's size."),
|
|
13
14
|
pixelThreshold: z
|
|
14
15
|
.number()
|
|
15
16
|
.min(0)
|
|
16
17
|
.max(255)
|
|
17
18
|
.optional()
|
|
18
|
-
.describe(`
|
|
19
|
-
`(default ${DEFAULT_PIXEL_THRESHOLD}: catches a changed label or a toast).`),
|
|
19
|
+
.describe(`Mean 0-255 difference for a ~32x32 cell to count as changed (default ${DEFAULT_PIXEL_THRESHOLD}).`),
|
|
20
20
|
returnImage: z
|
|
21
21
|
.boolean()
|
|
22
22
|
.optional()
|
|
23
|
-
.describe("
|
|
23
|
+
.describe("Return b inline with changes outlined (default true)."),
|
|
24
24
|
};
|
|
25
25
|
export function register(server) {
|
|
26
|
-
server.
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
26
|
+
server.registerTool("screen_diff", {
|
|
27
|
+
title: "Screen Diff",
|
|
28
|
+
description: "Compare two screenshots or frames: SSIM score, changed share, and changed boxes in b's " +
|
|
29
|
+
"pixels, to check a UI change happened only where expected.",
|
|
30
|
+
inputSchema,
|
|
31
|
+
outputSchema: looseOutput({
|
|
32
|
+
identical: z.boolean(),
|
|
33
|
+
ssim: z.number().nullable(),
|
|
34
|
+
meanDiff: z.number(),
|
|
35
|
+
changedFraction: z.number(),
|
|
36
|
+
regions: z.array(z.unknown()),
|
|
37
|
+
}),
|
|
38
|
+
annotations: READ_ONLY,
|
|
39
|
+
}, async (args, extra) => {
|
|
30
40
|
try {
|
|
31
41
|
requireFfmpeg();
|
|
32
42
|
for (const f of [args.a, args.b]) {
|
|
@@ -38,12 +48,10 @@ export function register(server) {
|
|
|
38
48
|
throw new ScreencastError(`Could not read the size of ${args.a}.`);
|
|
39
49
|
const size = detectionSize(ia.width, ia.height);
|
|
40
50
|
const [ra, rb, ssimRun] = await Promise.all([
|
|
41
|
-
runFfmpegBuffer(buildRawFrameArgs(args.a, size)),
|
|
42
|
-
runFfmpegBuffer(buildRawFrameArgs(args.b, size)),
|
|
43
|
-
runCapture(requireFfmpeg().ffmpeg, buildSsimArgs(args.a, args.b, size), 30_000),
|
|
51
|
+
runFfmpegBuffer(buildRawFrameArgs(args.a, size), 30_000, { signal: extra.signal }),
|
|
52
|
+
runFfmpegBuffer(buildRawFrameArgs(args.b, size), 30_000, { signal: extra.signal }),
|
|
53
|
+
runCapture(requireFfmpeg().ffmpeg, buildSsimArgs(args.a, args.b, size), 30_000, { signal: extra.signal }),
|
|
44
54
|
]);
|
|
45
|
-
// Map boxes onto b's own pixels so they can be drawn on (and clicked in)
|
|
46
|
-
// b, per axis: b was stretched to a's aspect ratio (#211).
|
|
47
55
|
const diff = diffFrames(ra, rb, size.width, size.height, {
|
|
48
56
|
scaleX: (ib.width ?? ia.width) / size.width,
|
|
49
57
|
scaleY: (ib.height ?? ia.height) / size.height,
|
|
@@ -51,10 +59,9 @@ export function register(server) {
|
|
|
51
59
|
});
|
|
52
60
|
const images = [];
|
|
53
61
|
if (args.returnImage !== false) {
|
|
54
|
-
// Only returned inline, so it is not left on disk (#209).
|
|
55
62
|
const highlighted = join(tmpdir(), `screencast-diff-${stamp()}-${rand()}.png`);
|
|
56
63
|
try {
|
|
57
|
-
await runFfmpeg(buildHighlightArgs(args.b, diff.regions, highlighted), 30_000);
|
|
64
|
+
await runFfmpeg(buildHighlightArgs(args.b, diff.regions, highlighted), 30_000, { signal: extra.signal });
|
|
58
65
|
images.push(...(await encodeInlineImages([highlighted], DEFAULT_MAX_IMAGE_WIDTH, 1)).images);
|
|
59
66
|
}
|
|
60
67
|
finally {
|
|
@@ -77,4 +84,3 @@ export function register(server) {
|
|
|
77
84
|
}
|
|
78
85
|
});
|
|
79
86
|
}
|
|
80
|
-
//# sourceMappingURL=screenDiff.js.map
|
package/dist/tools/screenshot.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { errorResponse, okResponse } from "../utils/errors.js";
|
|
3
|
+
import { WRITES_FILE, looseOutput } from "../utils/toolSpec.js";
|
|
3
4
|
import { requireFfmpeg } from "../utils/ffmpeg.js";
|
|
4
5
|
import { captureStill } from "../utils/still.js";
|
|
5
6
|
import { resolveCaptureTarget } from "../utils/resolveTarget.js";
|
|
6
7
|
import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
|
|
7
8
|
import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
|
|
8
9
|
import { windowMatchReport } from "../utils/windows.js";
|
|
10
|
+
import { confirmCapture, describeTarget } from "../utils/consent.js";
|
|
9
11
|
const inputSchema = {
|
|
10
12
|
target: z
|
|
11
13
|
.string()
|
|
12
|
-
.describe("
|
|
13
|
-
"
|
|
14
|
-
"window occupies as currently displayed - it must be visible, on top, " +
|
|
15
|
-
"and not minimized (case-insensitive exact title, else substring; " +
|
|
16
|
-
"topmost match wins)."),
|
|
14
|
+
.describe("full | monitor:<i> (0 = primary) | window:<title> (or window:exe=<app.exe> / window:hwnd=<n>) | " +
|
|
15
|
+
"region:<x>,<y>,<w>,<h>. Titles match exactly, else as a substring; topmost wins."),
|
|
17
16
|
exactTitle: z
|
|
18
17
|
.boolean()
|
|
19
18
|
.optional()
|
|
20
|
-
.describe("
|
|
21
|
-
"title (case-insensitive); never fall back to a substring match. Default false."),
|
|
19
|
+
.describe("window: targets match the whole title only, never a substring (default false)."),
|
|
22
20
|
backend: z
|
|
23
21
|
.enum(["gdigrab", "wgc"])
|
|
24
22
|
.optional()
|
|
25
|
-
.describe("gdigrab (default, ~0.2 s)
|
|
26
|
-
"only, FFmpeg 8+) captures the window's own surface through Windows Graphics Capture, " +
|
|
27
|
-
"even when other windows cover it; slower (~1-2 s)."),
|
|
23
|
+
.describe("gdigrab (default, ~0.2 s): what is visible. wgc (window:, FFmpeg 8+, ~1-2 s): the window even if covered."),
|
|
28
24
|
output: z
|
|
29
25
|
.string()
|
|
30
26
|
.optional()
|
|
@@ -33,25 +29,34 @@ const inputSchema = {
|
|
|
33
29
|
returnImage: z
|
|
34
30
|
.boolean()
|
|
35
31
|
.optional()
|
|
36
|
-
.describe("
|
|
37
|
-
"(default true). The PNG on disk is always full resolution."),
|
|
32
|
+
.describe("Return the image inline (default true; the PNG on disk stays full size)."),
|
|
38
33
|
maxImageWidth: z
|
|
39
34
|
.number()
|
|
40
35
|
.int()
|
|
41
36
|
.min(16)
|
|
42
37
|
.optional()
|
|
43
|
-
.describe(`
|
|
38
|
+
.describe(`Max inline image width (default ${DEFAULT_MAX_IMAGE_WIDTH}).`),
|
|
44
39
|
};
|
|
45
40
|
export function register(server) {
|
|
46
|
-
server.
|
|
47
|
-
|
|
48
|
-
"
|
|
41
|
+
server.registerTool("screenshot", {
|
|
42
|
+
title: "Take Screenshot",
|
|
43
|
+
description: "Capture one PNG of the screen, a monitor, a window, or a region, returned inline and by path.",
|
|
44
|
+
inputSchema,
|
|
45
|
+
outputSchema: looseOutput({
|
|
46
|
+
outputPath: z.string(),
|
|
47
|
+
target: z.string(),
|
|
48
|
+
backend: z.string(),
|
|
49
|
+
inlineImages: z.number().int(),
|
|
50
|
+
}),
|
|
51
|
+
annotations: WRITES_FILE,
|
|
52
|
+
}, async (args, extra) => {
|
|
49
53
|
try {
|
|
50
54
|
requireFfmpeg();
|
|
51
55
|
const resolved = await resolveCaptureTarget(args.target, { exactTitle: args.exactTitle, backend: args.backend });
|
|
52
56
|
const { window } = resolved;
|
|
53
57
|
const output = resolveOutput(args.output, subdir("screenshots"), `shot-${stamp()}-${rand()}.png`, args.overwrite);
|
|
54
58
|
const backend = args.backend ?? "gdigrab";
|
|
59
|
+
await confirmCapture(server, `Take a screenshot of ${describeTarget(args.target, window)}, saved to ${output}?`, extra.signal);
|
|
55
60
|
await captureStill(resolved, output, backend);
|
|
56
61
|
const images = args.returnImage === false
|
|
57
62
|
? []
|
|
@@ -69,4 +74,3 @@ export function register(server) {
|
|
|
69
74
|
}
|
|
70
75
|
});
|
|
71
76
|
}
|
|
72
|
-
//# sourceMappingURL=screenshot.js.map
|