dp-worker 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chrome-extension/omni-flow/manifest.json +1 -1
- package/dist/chrome-extension/omni-flow/popup.html +1 -1
- package/dist/chrome-extension/omni-flow/popup.js +33 -8
- package/dist/render/ffmpeg-compose.d.ts +25 -0
- package/dist/render/ffmpeg-compose.js +141 -0
- package/dist/render/ffmpeg-compose.js.map +1 -0
- package/dist/render/ffmpeg-merge.d.ts +5 -0
- package/dist/render/ffmpeg-merge.js +61 -0
- package/dist/render/ffmpeg-merge.js.map +1 -0
- package/dist/render/font.d.ts +1 -0
- package/dist/render/font.js +61 -0
- package/dist/render/font.js.map +1 -0
- package/dist/render/image-gen.d.ts +11 -0
- package/dist/render/image-gen.js +42 -0
- package/dist/render/image-gen.js.map +1 -0
- package/dist/render/render-frontend.d.ts +46 -0
- package/dist/render/render-frontend.js +156 -0
- package/dist/render/render-frontend.js.map +1 -0
- package/dist/render/render-runner.d.ts +30 -0
- package/dist/render/render-runner.js +115 -0
- package/dist/render/render-runner.js.map +1 -0
- package/dist/render/tts.d.ts +15 -0
- package/dist/render/tts.js +35 -0
- package/dist/render/tts.js.map +1 -0
- package/node_modules/dp-shared/dist/configs-contracts.d.ts +33 -0
- package/node_modules/dp-shared/dist/configs-contracts.d.ts.map +1 -1
- package/node_modules/dp-shared/dist/configs-contracts.js +27 -0
- package/node_modules/dp-shared/dist/configs-contracts.js.map +1 -1
- package/node_modules/dp-shared/dist/ws-protocol.d.ts +2 -2
- package/node_modules/dp-shared/src/configs-contracts.ts +31 -0
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<div class="logo-area">
|
|
16
16
|
<img src="icon.png" alt="OmniFlow Logo" class="logo-img">
|
|
17
17
|
<span class="logo-text">OmniFlow</span>
|
|
18
|
-
<span class="extension-version" id="extensionVersion">1.
|
|
18
|
+
<span class="extension-version" id="extensionVersion">0.1.10</span>
|
|
19
19
|
</div>
|
|
20
20
|
<div class="header-actions">
|
|
21
21
|
<!-- Open in Standalone Window Button -->
|
|
@@ -346,38 +346,63 @@ function handleTimezoneDetection() {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
function detectTimezoneChain(ip) {
|
|
349
|
+
// Providers ordered by accuracy + reliability. City-level, https, CORS-friendly
|
|
350
|
+
// sources go first; api.ip.sb is demoted because it falls back to a country
|
|
351
|
+
// centroid (any US IP -> America/Chicago) when it lacks city data, and
|
|
352
|
+
// freeipapi is frequently blocked by Cloudflare. ip-api.com is http-only
|
|
353
|
+
// (mixed-content from the extension page) so it stays last as a best effort.
|
|
349
354
|
const apiUrls = [
|
|
355
|
+
ip ? `https://ipinfo.io/${ip}/json` : 'https://ipinfo.io/json',
|
|
356
|
+
ip ? `https://ipwho.is/${ip}` : 'https://ipwho.is/',
|
|
357
|
+
ip ? `https://ipapi.co/${ip}/json/` : 'https://ipapi.co/json/',
|
|
350
358
|
ip ? `https://freeipapi.com/api/json/${ip}` : 'https://freeipapi.com/api/json',
|
|
351
359
|
ip ? `https://api.ip.sb/geoip/${ip}` : 'https://api.ip.sb/geoip',
|
|
352
|
-
ip ? `https://ipapi.co/${ip}/json/` : 'https://ipapi.co/json/',
|
|
353
|
-
ip ? `https://ipinfo.io/${ip}/json` : 'https://ipinfo.io/json',
|
|
354
360
|
ip ? `http://ip-api.com/json/${ip}` : 'http://ip-api.com/json/'
|
|
355
361
|
];
|
|
356
362
|
|
|
363
|
+
// Normalize the timezone field across provider shapes.
|
|
364
|
+
const getTz = (d) => {
|
|
365
|
+
if (!d) return '';
|
|
366
|
+
if (typeof d.timezone === 'string') return d.timezone; // ipinfo / ipapi.co / ip.sb / ip-api
|
|
367
|
+
if (d.timezone && d.timezone.id) return d.timezone.id; // ipwho.is -> { id, ... }
|
|
368
|
+
return d.timeZone || ''; // freeipapi
|
|
369
|
+
};
|
|
370
|
+
// A real city name means the provider resolved past country level. Its absence
|
|
371
|
+
// signals a country-centroid fallback (e.g. ip.sb -> Chicago for any US IP).
|
|
372
|
+
const getCity = (d) => (d && (d.city || d.cityName || '')) || '';
|
|
373
|
+
// Some providers return an error payload with HTTP 200 (ipapi.co rate-limit,
|
|
374
|
+
// ip-api status:"fail", ipwho.is success:false) — don't trust those.
|
|
375
|
+
const isError = (d) => !d || d.error === true || d.status === 'fail' || d.success === false;
|
|
376
|
+
|
|
357
377
|
return new Promise((resolve, reject) => {
|
|
358
378
|
let index = 0;
|
|
379
|
+
let weak = ''; // a timezone with no city — kept only as a last resort
|
|
359
380
|
|
|
360
381
|
function tryNextApi() {
|
|
361
382
|
if (index >= apiUrls.length) {
|
|
383
|
+
if (weak) { resolve(weak); return; }
|
|
362
384
|
reject(new Error("All fallback GeoIP services failed."));
|
|
363
385
|
return;
|
|
364
386
|
}
|
|
365
387
|
|
|
366
|
-
const url = apiUrls[index];
|
|
388
|
+
const url = apiUrls[index++];
|
|
367
389
|
fetch(url)
|
|
368
390
|
.then(res => {
|
|
369
391
|
if (!res.ok) throw new Error(`HTTP Error ${res.status}`);
|
|
370
392
|
return res.json();
|
|
371
393
|
})
|
|
372
394
|
.then(data => {
|
|
373
|
-
if (data
|
|
374
|
-
|
|
395
|
+
if (isError(data)) throw new Error("Provider error payload");
|
|
396
|
+
const tz = getTz(data);
|
|
397
|
+
if (!tz) throw new Error("No timezone key in JSON");
|
|
398
|
+
if (getCity(data)) {
|
|
399
|
+
resolve(tz); // city-level result — trust it immediately
|
|
375
400
|
} else {
|
|
376
|
-
|
|
401
|
+
if (!weak) weak = tz; // stash, but keep looking for a better source
|
|
402
|
+
throw new Error("No city — weak result, continue");
|
|
377
403
|
}
|
|
378
404
|
})
|
|
379
|
-
.catch(
|
|
380
|
-
index++;
|
|
405
|
+
.catch(() => {
|
|
381
406
|
tryNextApi();
|
|
382
407
|
});
|
|
383
408
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface SubtitleStyleInput {
|
|
2
|
+
color?: string;
|
|
3
|
+
fontSizeRatio?: number;
|
|
4
|
+
stroke?: boolean;
|
|
5
|
+
background?: boolean;
|
|
6
|
+
position?: "bottom" | "center" | "top";
|
|
7
|
+
}
|
|
8
|
+
export interface ComposeShotInput {
|
|
9
|
+
/** A footage clip (e.g. stock mp4) to scale/crop. */
|
|
10
|
+
video?: string;
|
|
11
|
+
/** A still image to animate (Ken Burns) or show static. Used when no video. */
|
|
12
|
+
image?: string;
|
|
13
|
+
motion?: "none" | "kenburns";
|
|
14
|
+
audio?: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
subtitleStyle?: SubtitleStyleInput;
|
|
17
|
+
fontFile?: string | null;
|
|
18
|
+
fade?: boolean;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
/** Planned shot duration (ms); drives Ken Burns length + fade-out timing. */
|
|
22
|
+
durationMs?: number;
|
|
23
|
+
out: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function composeShot(input: ComposeShotInput): Promise<void>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import ffmpeg from "fluent-ffmpeg";
|
|
3
|
+
import ffmpegStatic from "ffmpeg-static";
|
|
4
|
+
/**
|
|
5
|
+
* Compose one storyboard shot into a WxH MP4: footage/clip scaled to fill the
|
|
6
|
+
* frame, the TTS narration as the audio track, and (when a font is available)
|
|
7
|
+
* the narration burned in as a styled subtitle. Optional fade-in/out gives an
|
|
8
|
+
* inter-shot transition without cross-clip probing. All shots use identical
|
|
9
|
+
* encode settings so the final concat-merge can stream-copy.
|
|
10
|
+
*
|
|
11
|
+
* Shot length follows the narration: we probe the TTS audio duration and bound
|
|
12
|
+
* the output with `-t` (NOT `-shortest` — that drops the audio track entirely
|
|
13
|
+
* when paired with a lavfi/looped video source in ffmpeg-static).
|
|
14
|
+
*/
|
|
15
|
+
const FFMPEG_BIN = ffmpegStatic || "ffmpeg";
|
|
16
|
+
if (ffmpegStatic)
|
|
17
|
+
ffmpeg.setFfmpegPath(FFMPEG_BIN);
|
|
18
|
+
/** Probe a media file's duration (ms) by parsing `ffmpeg -i` stderr. Null if unknown. */
|
|
19
|
+
function probeDurationMs(file) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const p = spawn(FFMPEG_BIN, ["-i", file], { stdio: ["ignore", "ignore", "pipe"] });
|
|
22
|
+
let err = "";
|
|
23
|
+
p.stderr.on("data", (d) => (err += d.toString()));
|
|
24
|
+
p.on("error", () => resolve(null));
|
|
25
|
+
p.on("close", () => {
|
|
26
|
+
const m = err.match(/Duration:\s*(\d+):(\d+):(\d+(?:\.\d+)?)/);
|
|
27
|
+
if (!m)
|
|
28
|
+
return resolve(null);
|
|
29
|
+
resolve(Math.round((Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3])) * 1000));
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Escape text for ffmpeg drawtext (colon, backslash, quote, percent, newline). */
|
|
34
|
+
function escapeDrawtext(s) {
|
|
35
|
+
return s
|
|
36
|
+
.replace(/\\/g, "\\\\")
|
|
37
|
+
.replace(/:/g, "\\:")
|
|
38
|
+
.replace(/'/g, "’")
|
|
39
|
+
.replace(/%/g, "\\%")
|
|
40
|
+
.replace(/\n/g, "\\n");
|
|
41
|
+
}
|
|
42
|
+
/** Word/char wrap so long narration doesn't run off-frame (CJK has no spaces → char wrap). */
|
|
43
|
+
function wrap(text, perLine = 20) {
|
|
44
|
+
const t = text.trim();
|
|
45
|
+
const hasSpaces = /\s/.test(t);
|
|
46
|
+
const lines = [];
|
|
47
|
+
if (hasSpaces) {
|
|
48
|
+
let cur = "";
|
|
49
|
+
for (const w of t.split(/\s+/)) {
|
|
50
|
+
if ((cur + " " + w).trim().length > perLine) {
|
|
51
|
+
if (cur)
|
|
52
|
+
lines.push(cur);
|
|
53
|
+
cur = w;
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
cur = (cur + " " + w).trim();
|
|
57
|
+
}
|
|
58
|
+
if (cur)
|
|
59
|
+
lines.push(cur);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
for (let i = 0; i < t.length; i += perLine)
|
|
63
|
+
lines.push(t.slice(i, i + perLine));
|
|
64
|
+
}
|
|
65
|
+
return lines.slice(0, 4).join("\n");
|
|
66
|
+
}
|
|
67
|
+
export async function composeShot(input) {
|
|
68
|
+
const { width: W, height: H } = input;
|
|
69
|
+
// Shot length follows the narration audio (so it's never cut off). Fall back
|
|
70
|
+
// to the planned duration when there's no audio to probe.
|
|
71
|
+
let durMs = input.durationMs ?? 4000;
|
|
72
|
+
if (input.audio) {
|
|
73
|
+
const probed = await probeDurationMs(input.audio);
|
|
74
|
+
if (probed && probed > 500)
|
|
75
|
+
durMs = probed;
|
|
76
|
+
}
|
|
77
|
+
const durSec = Math.max(1, durMs / 1000);
|
|
78
|
+
const frames = Math.round(durSec * 30);
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const cmd = ffmpeg();
|
|
81
|
+
if (input.video) {
|
|
82
|
+
cmd.input(input.video).inputOptions(["-stream_loop", "-1"]); // loop footage to cover narration
|
|
83
|
+
}
|
|
84
|
+
else if (input.image) {
|
|
85
|
+
cmd.input(input.image).inputOptions(["-loop", "1"]);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// No footage/image → a dark "text-card" background (free, no provider).
|
|
89
|
+
cmd.input(`color=c=0x0f172a:s=${W}x${H}`).inputFormat("lavfi");
|
|
90
|
+
}
|
|
91
|
+
if (input.audio)
|
|
92
|
+
cmd.input(input.audio);
|
|
93
|
+
// Build the base video filter depending on source type.
|
|
94
|
+
let baseFilter;
|
|
95
|
+
if (input.image && input.motion === "kenburns") {
|
|
96
|
+
// Scale way up so zoompan has resolution headroom (avoids jitter), then
|
|
97
|
+
// slow zoom-in centered. d = total output frames.
|
|
98
|
+
baseFilter =
|
|
99
|
+
`[0:v]scale=8000:-1,zoompan=z='min(zoom+0.0012,1.4)':d=${frames}:` +
|
|
100
|
+
`x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':s=${W}x${H}:fps=30,setsar=1[vbg]`;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
baseFilter = `[0:v]scale=${W}:${H}:force_original_aspect_ratio=increase,crop=${W}:${H},setsar=1[vbg]`;
|
|
104
|
+
}
|
|
105
|
+
const filters = [baseFilter];
|
|
106
|
+
let last = "[vbg]";
|
|
107
|
+
if (input.subtitle && input.fontFile) {
|
|
108
|
+
const st = input.subtitleStyle ?? {};
|
|
109
|
+
const text = escapeDrawtext(wrap(input.subtitle));
|
|
110
|
+
const fontSize = Math.round(H * (st.fontSizeRatio ?? 1 / 22));
|
|
111
|
+
const color = st.color ?? "white";
|
|
112
|
+
const pos = st.position ?? "bottom";
|
|
113
|
+
const y = pos === "center" ? "(h-text_h)/2" : pos === "top" ? `${Math.round(H / 12)}` : `h-text_h-${Math.round(H / 10)}`;
|
|
114
|
+
const box = st.background === false ? "" : ":box=1:boxcolor=black@0.5:boxborderw=16";
|
|
115
|
+
const border = st.stroke === false ? "" : ":borderw=3:bordercolor=black@0.9";
|
|
116
|
+
filters.push(`${last}drawtext=fontfile='${input.fontFile}':text='${text}':` +
|
|
117
|
+
`fontcolor=${color}:fontsize=${fontSize}:line_spacing=8:` +
|
|
118
|
+
`x=(w-text_w)/2:y=${y}${box}${border}[vt]`);
|
|
119
|
+
last = "[vt]";
|
|
120
|
+
}
|
|
121
|
+
if (input.fade) {
|
|
122
|
+
const fadeD = 0.3;
|
|
123
|
+
const outStart = Math.max(0, durSec - fadeD);
|
|
124
|
+
filters.push(`${last}fade=t=in:st=0:d=${fadeD},fade=t=out:st=${outStart.toFixed(2)}:d=${fadeD}[vf]`);
|
|
125
|
+
last = "[vf]";
|
|
126
|
+
}
|
|
127
|
+
cmd.complexFilter(filters);
|
|
128
|
+
// Bound the whole output with -t (NOT -shortest — it drops audio with a
|
|
129
|
+
// looped/lavfi video source). All sources loop, so -t defines shot length.
|
|
130
|
+
const outputOptions = ["-map", last];
|
|
131
|
+
if (input.audio)
|
|
132
|
+
outputOptions.push("-map", "1:a", "-c:a", "aac", "-b:a", "192k");
|
|
133
|
+
outputOptions.push("-t", durSec.toFixed(2), "-c:v", "libx264", "-pix_fmt", "yuv420p", "-r", "30", "-preset", "veryfast", "-movflags", "+faststart");
|
|
134
|
+
cmd
|
|
135
|
+
.outputOptions(outputOptions)
|
|
136
|
+
.on("error", (err) => reject(new Error(`ffmpeg compose failed: ${err.message}`)))
|
|
137
|
+
.on("end", () => resolve())
|
|
138
|
+
.save(input.out);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=ffmpeg-compose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg-compose.js","sourceRoot":"","sources":["../../src/render/ffmpeg-compose.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC;;;;;;;;;;GAUG;AAEH,MAAM,UAAU,GAAI,YAAkC,IAAI,QAAQ,CAAC;AACnE,IAAI,YAAY;IAAE,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AAEnD,yFAAyF;AACzF,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QACnF,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC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|
|
|
1
|
+
import { unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import ffmpeg from "fluent-ffmpeg";
|
|
4
|
+
import ffmpegStatic from "ffmpeg-static";
|
|
5
|
+
/**
|
|
6
|
+
* Concatenate the ordered per-shot clips into the final video, then (optionally)
|
|
7
|
+
* mix background music under the narration. Concat is a stream-copy demuxer pass
|
|
8
|
+
* (all shots share encode settings → fast, lossless); BGM is a second pass that
|
|
9
|
+
* re-encodes audio only (video copied). Adapted from huobao-drama's ffmpeg-merge.
|
|
10
|
+
*/
|
|
11
|
+
if (ffmpegStatic)
|
|
12
|
+
ffmpeg.setFfmpegPath(ffmpegStatic);
|
|
13
|
+
function concat(clipPaths, out) {
|
|
14
|
+
return (async () => {
|
|
15
|
+
const listPath = `${out}.concat.txt`;
|
|
16
|
+
const listBody = clipPaths.map((p) => `file '${p.replace(/'/g, "'\\''")}'`).join("\n");
|
|
17
|
+
await writeFile(listPath, listBody, "utf-8");
|
|
18
|
+
await new Promise((resolve, reject) => {
|
|
19
|
+
ffmpeg()
|
|
20
|
+
.input(listPath)
|
|
21
|
+
.inputOptions(["-f", "concat", "-safe", "0"])
|
|
22
|
+
.outputOptions(["-c", "copy", "-movflags", "+faststart"])
|
|
23
|
+
.on("error", (err) => reject(new Error(`ffmpeg concat failed: ${err.message}`)))
|
|
24
|
+
.on("end", () => resolve())
|
|
25
|
+
.save(out);
|
|
26
|
+
});
|
|
27
|
+
})();
|
|
28
|
+
}
|
|
29
|
+
/** Mix bgm under the existing audio of `video`, looping bgm and ending with video. */
|
|
30
|
+
function mixBgm(video, bgm, volume, out) {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
ffmpeg()
|
|
33
|
+
.input(video)
|
|
34
|
+
.input(bgm)
|
|
35
|
+
.inputOptions(["-stream_loop", "-1"]) // applies to the most recent input (bgm) → loop to cover video
|
|
36
|
+
.complexFilter([
|
|
37
|
+
`[1:a]volume=${volume}[bg]`,
|
|
38
|
+
`[0:a][bg]amix=inputs=2:duration=first:dropout_transition=2[a]`,
|
|
39
|
+
])
|
|
40
|
+
.outputOptions(["-map", "0:v", "-map", "[a]", "-c:v", "copy", "-c:a", "aac", "-b:a", "192k", "-shortest", "-movflags", "+faststart"])
|
|
41
|
+
.on("error", (err) => reject(new Error(`ffmpeg bgm mix failed: ${err.message}`)))
|
|
42
|
+
.on("end", () => resolve())
|
|
43
|
+
.save(out);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export async function mergeClips(clipPaths, out, opts = {}) {
|
|
47
|
+
if (!opts.bgm) {
|
|
48
|
+
await concat(clipPaths, out);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// Concat to a temp, then mix BGM into the final output.
|
|
52
|
+
const tmp = path.join(path.dirname(out), `concat-${Date.now()}.mp4`);
|
|
53
|
+
await concat(clipPaths, tmp);
|
|
54
|
+
try {
|
|
55
|
+
await mixBgm(tmp, opts.bgm, opts.bgmVolume ?? 0.2, out);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
await unlink(tmp).catch(() => undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=ffmpeg-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ffmpeg-merge.js","sourceRoot":"","sources":["../../src/render/ffmpeg-merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,YAAY,MAAM,eAAe,CAAC;AAEzC;;;;;GAKG;AAEH,IAAI,YAAY;IAAE,MAAM,CAAC,aAAa,CAAC,YAAiC,CAAC,CAAC;AAO1E,SAAS,MAAM,CAAC,SAAmB,EAAE,GAAW;IAC9C,OAAO,CAAC,KAAK,IAAI,EAAE;QACjB,MA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,0 +1,61 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a drawtext-usable font for burned subtitles. Order:
|
|
6
|
+
* 1. DP_RENDER_FONT_PATH (explicit override)
|
|
7
|
+
* 2. A system font from the candidate list (incl. macOS CJK fonts — the
|
|
8
|
+
* production hosts are Macs, so PingFang/STHeiti give reliable Chinese).
|
|
9
|
+
* 3. Download DP_RENDER_FONT_URL into <workspace>/fonts (cached) — for Linux
|
|
10
|
+
* hosts without a bundled CJK font.
|
|
11
|
+
* 4. null → caller skips subtitle burning (render still succeeds).
|
|
12
|
+
*/
|
|
13
|
+
const CANDIDATES = [
|
|
14
|
+
process.env.DP_RENDER_FONT_PATH,
|
|
15
|
+
// macOS (CJK-capable)
|
|
16
|
+
"/System/Library/Fonts/PingFang.ttc",
|
|
17
|
+
"/System/Library/Fonts/STHeiti Medium.ttc",
|
|
18
|
+
"/System/Library/Fonts/Hiragino Sans GB.ttc",
|
|
19
|
+
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
|
|
20
|
+
"/System/Library/Fonts/Supplemental/Arial.ttf",
|
|
21
|
+
"/Library/Fonts/Arial Unicode.ttf",
|
|
22
|
+
// Linux
|
|
23
|
+
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
|
24
|
+
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
|
|
25
|
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
26
|
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
|
27
|
+
].filter((p) => Boolean(p));
|
|
28
|
+
let cached;
|
|
29
|
+
export async function ensureFont(workspace) {
|
|
30
|
+
if (cached !== undefined)
|
|
31
|
+
return cached;
|
|
32
|
+
for (const c of CANDIDATES) {
|
|
33
|
+
if (existsSync(c)) {
|
|
34
|
+
cached = c;
|
|
35
|
+
return c;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const url = process.env.DP_RENDER_FONT_URL;
|
|
39
|
+
if (url) {
|
|
40
|
+
try {
|
|
41
|
+
const dir = path.join(workspace, "fonts");
|
|
42
|
+
await mkdir(dir, { recursive: true });
|
|
43
|
+
const dest = path.join(dir, url.toLowerCase().endsWith(".otf") ? "subtitle.otf" : "subtitle.ttf");
|
|
44
|
+
if (!existsSync(dest)) {
|
|
45
|
+
const res = await fetch(url);
|
|
46
|
+
if (res.ok)
|
|
47
|
+
await writeFile(dest, new Uint8Array(await res.arrayBuffer()));
|
|
48
|
+
}
|
|
49
|
+
if (existsSync(dest)) {
|
|
50
|
+
cached = dest;
|
|
51
|
+
return dest;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
/* fall through */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
cached = null;
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=font.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"font.js","sourceRoot":"","sources":["../../src/render/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;GAQG;AAEH,MAAM,UAAU,GAAG;IACjB,OAAO,CAAC,GAAG,CAAC,mBAAmB;IAC/B,sBAAsB;IACtB,oCAAoC;IACpC,0CAA0C;IAC1C,4CAA4C;IAC5C,sDAAsD;IACtD,8CAA8C;IAC9C,kCAAkC;IAClC,QAAQ;IACR,wDAAwD;IACxD,wDAAwD;IACxD,iDAAiD;IACjD,iEAAiE;CAClE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,C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OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-to-image on the worker, using the worker's OWN bootstrap llm_profile
|
|
3
|
+
* image config (OpenAI-compatible /v1/images/generations). No key travels over
|
|
4
|
+
* the wire — the worker already has its profile's image key from bootstrap.
|
|
5
|
+
*/
|
|
6
|
+
export interface WorkerImageConfig {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
apiKey: string;
|
|
9
|
+
model: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function generateImage(cfg: WorkerImageConfig, prompt: string, size: string, dest: string): Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
function ver(base) {
|
|
3
|
+
const b = base.replace(/\/+$/, "");
|
|
4
|
+
return b.endsWith("/v1") ? b : `${b}/v1`;
|
|
5
|
+
}
|
|
6
|
+
/** Map "WxH" to the nearest size the OpenAI image model accepts. */
|
|
7
|
+
function mapSize(model, size) {
|
|
8
|
+
const [w, h] = (size ?? "1024x1024").split("x").map(Number);
|
|
9
|
+
const aspect = w && h ? w / h : 1;
|
|
10
|
+
const isDalle3 = /dall-?e-?3/i.test(model);
|
|
11
|
+
if (aspect < 0.83)
|
|
12
|
+
return isDalle3 ? "1024x1792" : "1024x1536"; // portrait
|
|
13
|
+
if (aspect > 1.2)
|
|
14
|
+
return isDalle3 ? "1792x1024" : "1536x1024"; // landscape
|
|
15
|
+
return "1024x1024";
|
|
16
|
+
}
|
|
17
|
+
export async function generateImage(cfg, prompt, size, dest) {
|
|
18
|
+
const res = await fetch(`${ver(cfg.baseUrl)}/images/generations`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { Authorization: `Bearer ${cfg.apiKey}`, "Content-Type": "application/json" },
|
|
21
|
+
body: JSON.stringify({ model: cfg.model, prompt, size: mapSize(cfg.model, size), n: 1 }),
|
|
22
|
+
});
|
|
23
|
+
if (!res.ok) {
|
|
24
|
+
throw new Error(`image gen HTTP ${res.status}: ${(await res.text().catch(() => "")).slice(0, 300)}`);
|
|
25
|
+
}
|
|
26
|
+
const json = (await res.json());
|
|
27
|
+
const url = json.data?.[0]?.url;
|
|
28
|
+
const b64 = json.data?.[0]?.b64_json;
|
|
29
|
+
if (url) {
|
|
30
|
+
const img = await fetch(url);
|
|
31
|
+
if (!img.ok)
|
|
32
|
+
throw new Error(`image download HTTP ${img.status}`);
|
|
33
|
+
await writeFile(dest, new Uint8Array(await img.arrayBuffer()));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (b64) {
|
|
37
|
+
await writeFile(dest, Buffer.from(b64, "base64"));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throw new Error("image gen returned no url/b64");
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=image-gen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-gen.js","sourceRoot":"","sources":["../../src/render/image-gen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAc7C,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;AAC3C,CAAC;AAED,oEAAoE;AACpE,SAAS,OAAO,CAAC,KAAa,EAAE,IAAa;IAC3C,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,C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,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;IACpD,MAAM,GAAG,GAAuB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;IACzD,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAClE,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAC/D,OAAO;IACT,CAAC;IACD,IAAI,GAAG,EAAE,CAAC;QACR,MAAM,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;QAClD,OAAO;IACT,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CenterClient } from "../center/center-client.js";
|
|
2
|
+
import { type WorkerLlmConfig } from "./render-runner.js";
|
|
3
|
+
/**
|
|
4
|
+
* Render-worker analogue of CenterFrontend. A render worker (--render) has no
|
|
5
|
+
* Agent/Chrome: it connects to center with the SAME CenterClient + bootstrap,
|
|
6
|
+
* advertises itself via `hello`, and handles `task_dispatch` envelopes whose
|
|
7
|
+
* `kind` is "render" by running ffmpeg (download inputs → compose/merge →
|
|
8
|
+
* upload to R2) and reporting a structured `task_event { finished, result }`.
|
|
9
|
+
*
|
|
10
|
+
* It imports nothing from src/agent, src/browser, or src/llm — render is fully
|
|
11
|
+
* isolated from the shared agent core (SYNC.md safe).
|
|
12
|
+
*/
|
|
13
|
+
export interface RenderFrontendOpts {
|
|
14
|
+
client: CenterClient;
|
|
15
|
+
workerId: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
/** Scratch dir for ffmpeg temp files. */
|
|
18
|
+
workspace: string;
|
|
19
|
+
/** The worker's own llm_profile (image gen + profile TTS). */
|
|
20
|
+
llm?: WorkerLlmConfig;
|
|
21
|
+
logger?: {
|
|
22
|
+
info: (m: string) => void;
|
|
23
|
+
warn: (m: string) => void;
|
|
24
|
+
error: (m: string) => void;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export declare class RenderFrontend {
|
|
28
|
+
private readonly client;
|
|
29
|
+
private readonly workerId;
|
|
30
|
+
private readonly version;
|
|
31
|
+
private readonly workspace;
|
|
32
|
+
private readonly llm?;
|
|
33
|
+
private readonly logger;
|
|
34
|
+
private inFlight;
|
|
35
|
+
private heartbeatTimer;
|
|
36
|
+
private detachers;
|
|
37
|
+
private currentStatus;
|
|
38
|
+
constructor(opts: RenderFrontendOpts);
|
|
39
|
+
start(): Promise<void>;
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
private sendHello;
|
|
42
|
+
private handleIncoming;
|
|
43
|
+
private handleDispatch;
|
|
44
|
+
private emitEvent;
|
|
45
|
+
private sendStatus;
|
|
46
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { runRender } from "./render-runner.js";
|
|
2
|
+
export class RenderFrontend {
|
|
3
|
+
client;
|
|
4
|
+
workerId;
|
|
5
|
+
version;
|
|
6
|
+
workspace;
|
|
7
|
+
llm;
|
|
8
|
+
logger;
|
|
9
|
+
inFlight = null;
|
|
10
|
+
heartbeatTimer = null;
|
|
11
|
+
detachers = [];
|
|
12
|
+
currentStatus = "idle";
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
this.client = opts.client;
|
|
15
|
+
this.workerId = opts.workerId;
|
|
16
|
+
this.version = opts.version ?? "unknown";
|
|
17
|
+
this.workspace = opts.workspace;
|
|
18
|
+
this.llm = opts.llm;
|
|
19
|
+
this.logger = opts.logger ?? {
|
|
20
|
+
info: (m) => console.log(m),
|
|
21
|
+
warn: (m) => console.warn(m),
|
|
22
|
+
error: (m) => console.error(m),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async start() {
|
|
26
|
+
const onMessage = (msg) => {
|
|
27
|
+
this.handleIncoming(msg).catch((err) => this.logger.error(`RenderFrontend handler crashed for ${msg.type}: ${err instanceof Error ? err.message : err}`));
|
|
28
|
+
};
|
|
29
|
+
this.client.on("message", onMessage);
|
|
30
|
+
this.detachers.push(() => this.client.off("message", onMessage));
|
|
31
|
+
const onOpen = () => {
|
|
32
|
+
this.sendHello().catch((err) => this.logger.warn(`RenderFrontend hello failed: ${err instanceof Error ? err.message : err}`));
|
|
33
|
+
};
|
|
34
|
+
this.client.on("open", onOpen);
|
|
35
|
+
this.detachers.push(() => this.client.off("open", onOpen));
|
|
36
|
+
this.heartbeatTimer = setInterval(() => {
|
|
37
|
+
this.client.send({ type: "worker_heartbeat", payload: {} }).catch((err) => this.logger.warn(`[RenderFrontend] heartbeat failed: ${err instanceof Error ? err.message : err}`));
|
|
38
|
+
}, 30_000);
|
|
39
|
+
}
|
|
40
|
+
async stop() {
|
|
41
|
+
if (this.heartbeatTimer) {
|
|
42
|
+
clearInterval(this.heartbeatTimer);
|
|
43
|
+
this.heartbeatTimer = null;
|
|
44
|
+
}
|
|
45
|
+
for (const d of this.detachers)
|
|
46
|
+
d();
|
|
47
|
+
this.detachers = [];
|
|
48
|
+
if (this.inFlight) {
|
|
49
|
+
this.inFlight.controller.abort();
|
|
50
|
+
this.inFlight = null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async sendHello() {
|
|
54
|
+
const extras = this.client.getExtras();
|
|
55
|
+
await this.client.send({
|
|
56
|
+
type: "hello",
|
|
57
|
+
payload: {
|
|
58
|
+
worker_id: this.workerId,
|
|
59
|
+
version: this.version,
|
|
60
|
+
config_etag: extras?.configEtag ?? "unknown",
|
|
61
|
+
current_status: this.currentStatus,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async handleIncoming(msg) {
|
|
66
|
+
switch (msg.type) {
|
|
67
|
+
case "task_dispatch":
|
|
68
|
+
await this.handleDispatch(msg.payload);
|
|
69
|
+
return;
|
|
70
|
+
case "cancel_task": {
|
|
71
|
+
const p = msg.payload;
|
|
72
|
+
if (this.inFlight?.taskRunId === p.task_run_id) {
|
|
73
|
+
this.inFlight.controller.abort();
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
case "ping_request": {
|
|
78
|
+
const p = msg.payload;
|
|
79
|
+
await this.client.send({
|
|
80
|
+
type: "pong",
|
|
81
|
+
payload: { ref_id: p.ref_id, status: this.currentStatus },
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
default:
|
|
86
|
+
// Render workers ignore chat/config messages.
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async handleDispatch(payload) {
|
|
91
|
+
if (payload.kind !== "render" || !payload.render) {
|
|
92
|
+
this.logger.warn(`[RenderFrontend] ignoring non-render dispatch ${payload.task_run_id}`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (this.inFlight) {
|
|
96
|
+
this.logger.warn(`[RenderFrontend] busy; rejecting ${payload.task_run_id}`);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
this.inFlight = { taskRunId: payload.task_run_id, controller };
|
|
101
|
+
this.currentStatus = "busy";
|
|
102
|
+
await this.emitEvent({ task_run_id: payload.task_run_id, event: "dispatched_ack" });
|
|
103
|
+
await this.emitEvent({ task_run_id: payload.task_run_id, event: "started", status: "running" });
|
|
104
|
+
await this.sendStatus("busy", payload.task_run_id);
|
|
105
|
+
try {
|
|
106
|
+
const result = await runRender(payload.render, {
|
|
107
|
+
workspace: this.workspace,
|
|
108
|
+
llm: this.llm,
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
logger: this.logger,
|
|
111
|
+
});
|
|
112
|
+
await this.emitEvent({
|
|
113
|
+
task_run_id: payload.task_run_id,
|
|
114
|
+
event: "finished",
|
|
115
|
+
status: "success",
|
|
116
|
+
result,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
121
|
+
this.logger.error(`[RenderFrontend] render ${payload.task_run_id} failed: ${message}`);
|
|
122
|
+
await this.emitEvent({
|
|
123
|
+
task_run_id: payload.task_run_id,
|
|
124
|
+
event: "finished",
|
|
125
|
+
status: "failed",
|
|
126
|
+
error: message,
|
|
127
|
+
result: { error: message },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
this.inFlight = null;
|
|
132
|
+
this.currentStatus = "idle";
|
|
133
|
+
await this.sendStatus("idle", null);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async emitEvent(payload) {
|
|
137
|
+
try {
|
|
138
|
+
await this.client.send({ type: "task_event", payload });
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
this.logger.warn(`[RenderFrontend] task_event send failed: ${err instanceof Error ? err.message : err}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async sendStatus(status, taskId) {
|
|
145
|
+
try {
|
|
146
|
+
await this.client.send({
|
|
147
|
+
type: "status_change",
|
|
148
|
+
payload: { status, ...(taskId ? { current_task_id: taskId } : {}) },
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
this.logger.warn(`[RenderFrontend] status_change failed: ${err instanceof Error ? err.message : err}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=render-frontend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-frontend.js","sourceRoot":"","sources":["../../src/render/render-frontend.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS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1D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4CAA4C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,MAAqB,EAAE,MAAqB;QACnE,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACrB,IAAI,EAAE,eAAe;gBACrB,OAAO,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;aACpE,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RenderResultPayload, RenderSpecPayload } from "dp-shared";
|
|
2
|
+
/**
|
|
3
|
+
* Execute one worker task:
|
|
4
|
+
* - produce_shot: GENERATE the visual (worker's profile image key, or a
|
|
5
|
+
* pre-resolved stock URL) + voice (profile TTS / free edge-tts), then ffmpeg
|
|
6
|
+
* compose (Ken Burns for stills) → upload. All on the worker's machine.
|
|
7
|
+
* - merge: concat the shot clips (+ optional BGM) → upload.
|
|
8
|
+
* Returns the structured RenderResult the center persists to task_runs.result_json.
|
|
9
|
+
*/
|
|
10
|
+
/** The worker's own bootstrap llm_profile — used for image gen + profile TTS. */
|
|
11
|
+
export interface WorkerLlmConfig {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
apiKey: string;
|
|
14
|
+
model: string;
|
|
15
|
+
imageGeneration?: {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
model: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface RunRenderOpts {
|
|
21
|
+
workspace: string;
|
|
22
|
+
llm?: WorkerLlmConfig;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
logger?: {
|
|
25
|
+
info: (m: string) => void;
|
|
26
|
+
warn: (m: string) => void;
|
|
27
|
+
error: (m: string) => void;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export declare function runRender(spec: RenderSpecPayload, opts: RunRenderOpts): Promise<RenderResultPayload>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { pipeline } from "node:stream/promises";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { composeShot } from "./ffmpeg-compose.js";
|
|
8
|
+
import { mergeClips } from "./ffmpeg-merge.js";
|
|
9
|
+
import { ensureFont } from "./font.js";
|
|
10
|
+
import { generateImage } from "./image-gen.js";
|
|
11
|
+
import { synthesize } from "./tts.js";
|
|
12
|
+
function extFor(role) {
|
|
13
|
+
return role === "audio" || role === "bgm" ? "mp3" : role === "image" ? "png" : "mp4";
|
|
14
|
+
}
|
|
15
|
+
async function download(url, dest, signal) {
|
|
16
|
+
const res = await fetch(url, { signal });
|
|
17
|
+
if (!res.ok || !res.body) {
|
|
18
|
+
throw new Error(`download failed ${res.status} for ${url.slice(0, 80)}`);
|
|
19
|
+
}
|
|
20
|
+
await pipeline(Readable.fromWeb(res.body), createWriteStream(dest));
|
|
21
|
+
}
|
|
22
|
+
async function uploadPut(url, file, signal) {
|
|
23
|
+
const body = await readFile(file);
|
|
24
|
+
const res = await fetch(url, {
|
|
25
|
+
method: "PUT",
|
|
26
|
+
body,
|
|
27
|
+
headers: { "content-type": "video/mp4" },
|
|
28
|
+
signal,
|
|
29
|
+
});
|
|
30
|
+
if (!res.ok) {
|
|
31
|
+
throw new Error(`upload PUT failed ${res.status}: ${await res.text().catch(() => "")}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function runRender(spec, opts) {
|
|
35
|
+
const log = opts.logger ?? console;
|
|
36
|
+
const base = path.join(opts.workspace, "render");
|
|
37
|
+
const tmp = await mkdtemp(path.join(base.startsWith(os.tmpdir()) ? base : os.tmpdir(), "dp-render-"));
|
|
38
|
+
try {
|
|
39
|
+
const outPath = path.join(tmp, "out.mp4");
|
|
40
|
+
const width = spec.params?.width ?? 1080;
|
|
41
|
+
const height = spec.params?.height ?? 1920;
|
|
42
|
+
if (spec.render_kind === "produce_shot") {
|
|
43
|
+
await producShot(spec, opts, tmp, outPath, width, height);
|
|
44
|
+
}
|
|
45
|
+
else if (spec.render_kind === "merge") {
|
|
46
|
+
const clips = [];
|
|
47
|
+
let bgm;
|
|
48
|
+
for (let i = 0; i < spec.inputs.length; i++) {
|
|
49
|
+
const inp = spec.inputs[i];
|
|
50
|
+
const dest = path.join(tmp, `${inp.role}-${i}.${extFor(inp.role)}`);
|
|
51
|
+
await download(inp.get_url, dest, opts.signal);
|
|
52
|
+
if (inp.role === "bgm")
|
|
53
|
+
bgm = dest;
|
|
54
|
+
else
|
|
55
|
+
clips.push(dest);
|
|
56
|
+
}
|
|
57
|
+
if (clips.length === 0)
|
|
58
|
+
throw new Error("merge: no input clips");
|
|
59
|
+
await mergeClips(clips, outPath, { bgm, bgmVolume: spec.params?.bgm_volume });
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error(`unsupported render_kind: ${spec.render_kind}`);
|
|
63
|
+
}
|
|
64
|
+
await uploadPut(spec.output_put_url, outPath, opts.signal);
|
|
65
|
+
log.info(`[render] ${spec.render_kind} → ${spec.output_r2_key}`);
|
|
66
|
+
return { output_r2_key: spec.output_r2_key, duration_ms: spec.params?.duration_ms, width, height };
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await rm(tmp, { recursive: true, force: true }).catch(() => undefined);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** produce_shot: generate visual + voice on the worker, then compose. */
|
|
73
|
+
async function producShot(spec, opts, tmp, outPath, width, height) {
|
|
74
|
+
// 1) Visual: stock URL (center-sourced) → footage; image_prompt → generate.
|
|
75
|
+
let videoPath;
|
|
76
|
+
let imagePath;
|
|
77
|
+
const visual = spec.visual;
|
|
78
|
+
if (visual?.kind === "url" && visual.url) {
|
|
79
|
+
videoPath = path.join(tmp, "footage.mp4");
|
|
80
|
+
await download(visual.url, videoPath, opts.signal);
|
|
81
|
+
}
|
|
82
|
+
else if (visual?.kind === "image_prompt") {
|
|
83
|
+
if (!opts.llm?.imageGeneration) {
|
|
84
|
+
throw new Error("this worker's llm_profile has no image generation configured (set image_model/image_api_key)");
|
|
85
|
+
}
|
|
86
|
+
imagePath = path.join(tmp, "image.png");
|
|
87
|
+
await generateImage({ baseUrl: opts.llm.baseUrl, apiKey: opts.llm.imageGeneration.apiKey, model: opts.llm.imageGeneration.model }, visual.prompt ?? "", `${width}x${height}`, imagePath);
|
|
88
|
+
}
|
|
89
|
+
// 2) Voice (profile TTS or free edge-tts).
|
|
90
|
+
let audioPath;
|
|
91
|
+
if (spec.narration) {
|
|
92
|
+
audioPath = path.join(tmp, "audio.mp3");
|
|
93
|
+
await synthesize(spec.tts?.engine ?? "edge", opts.llm ? { baseUrl: opts.llm.baseUrl, apiKey: opts.llm.apiKey } : undefined, spec.narration, spec.tts?.voice, audioPath);
|
|
94
|
+
}
|
|
95
|
+
// 3) Compose (Ken Burns for stills) + subtitle.
|
|
96
|
+
const fontFile = spec.subtitle_text ? await ensureFont(opts.workspace) : null;
|
|
97
|
+
const st = spec.subtitle_style;
|
|
98
|
+
await composeShot({
|
|
99
|
+
video: videoPath,
|
|
100
|
+
image: imagePath,
|
|
101
|
+
motion: spec.motion ?? "none",
|
|
102
|
+
audio: audioPath,
|
|
103
|
+
subtitle: spec.subtitle_text,
|
|
104
|
+
subtitleStyle: st
|
|
105
|
+
? { color: st.color, fontSizeRatio: st.font_size_ratio, stroke: st.stroke, background: st.background, position: st.position }
|
|
106
|
+
: undefined,
|
|
107
|
+
fontFile,
|
|
108
|
+
fade: spec.params?.transition === "fade",
|
|
109
|
+
width,
|
|
110
|
+
height,
|
|
111
|
+
durationMs: spec.params?.duration_ms,
|
|
112
|
+
out: outPath,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=render-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-runner.js","sourceRoot":"","sources":["../../src/render/render-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA0BtC,SAAS,MAAM,CAAC,IAAyC;IACvD,OAAO,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC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ACJ,CAAC;IAED,gDAAgD;IAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC;IAC/B,MAAM,WAAW,CAAC;QAChB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,MAAM;QAC7B,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,IAAI,CAAC,aAAa;QAC5B,aAAa,EAAE,EAAE;YACf,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE;YAC7H,CAAC,CAAC,SAAS;QACb,QAAQ;QACR,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM;QACxC,KAAK;QACL,MAAM;QACN,UAAU,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW;QACpC,GAAG,EAAE,OAAO;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text-to-speech on the worker. Two engines:
|
|
3
|
+
* - "profile": OpenAI-compatible /v1/audio/speech using the worker's profile
|
|
4
|
+
* key (works if the gateway proxies TTS).
|
|
5
|
+
* - "edge": Microsoft Edge TTS — FREE, no key, runs on the worker's machine.
|
|
6
|
+
* The default, so口播 needs zero paid TTS.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkerLlmAudio {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function ttsProfile(llm: WorkerLlmAudio, text: string, voice: string | undefined, dest: string): Promise<void>;
|
|
13
|
+
/** Free Microsoft Edge TTS. Default voice is Chinese; override per job. */
|
|
14
|
+
export declare function ttsEdge(text: string, voice: string | undefined, dest: string): Promise<void>;
|
|
15
|
+
export declare function synthesize(engine: "profile" | "edge", llm: WorkerLlmAudio | undefined, text: string, voice: string | undefined, dest: string): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createWriteStream } from "node:fs";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import { pipeline } from "node:stream/promises";
|
|
4
|
+
import { MsEdgeTTS, OUTPUT_FORMAT } from "msedge-tts";
|
|
5
|
+
function ver(base) {
|
|
6
|
+
const b = base.replace(/\/+$/, "");
|
|
7
|
+
return b.endsWith("/v1") ? b : `${b}/v1`;
|
|
8
|
+
}
|
|
9
|
+
export async function ttsProfile(llm, text, voice, dest) {
|
|
10
|
+
const res = await fetch(`${ver(llm.baseUrl)}/audio/speech`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: { Authorization: `Bearer ${llm.apiKey}`, "Content-Type": "application/json" },
|
|
13
|
+
body: JSON.stringify({ model: "gpt-4o-mini-tts", input: text, voice: voice || "alloy", response_format: "mp3" }),
|
|
14
|
+
});
|
|
15
|
+
if (!res.ok) {
|
|
16
|
+
throw new Error(`profile TTS HTTP ${res.status}: ${(await res.text().catch(() => "")).slice(0, 200)}`);
|
|
17
|
+
}
|
|
18
|
+
await writeFile(dest, new Uint8Array(await res.arrayBuffer()));
|
|
19
|
+
}
|
|
20
|
+
/** Free Microsoft Edge TTS. Default voice is Chinese; override per job. */
|
|
21
|
+
export async function ttsEdge(text, voice, dest) {
|
|
22
|
+
const tts = new MsEdgeTTS();
|
|
23
|
+
await tts.setMetadata(voice || "zh-CN-XiaoxiaoNeural", OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3);
|
|
24
|
+
const { audioStream } = tts.toStream(text);
|
|
25
|
+
await pipeline(audioStream, createWriteStream(dest));
|
|
26
|
+
}
|
|
27
|
+
export async function synthesize(engine, llm, text, voice, dest) {
|
|
28
|
+
if (engine === "profile" && llm) {
|
|
29
|
+
await ttsProfile(llm, text, voice, dest);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
await ttsEdge(text, voice, dest);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=tts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tts.js","sourceRoot":"","sources":["../../src/render/tts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAetD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAmB,EAAE,IAAY,EAAE,KAAyB,EAAE,IAAY;IACzG,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE;QAC1D,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QACtF,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK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131,39 @@ export declare const ProxyTestResultSchema: z.ZodObject<{
|
|
|
131
131
|
detail: z.ZodString;
|
|
132
132
|
}, z.core.$strip>;
|
|
133
133
|
export type ProxyTestResult = z.infer<typeof ProxyTestResultSchema>;
|
|
134
|
+
/**
|
|
135
|
+
* Auto-detect timezone for a (not-yet-saved) proxy. The center worker first
|
|
136
|
+
* routes a geo-IP lookup *through* the proxy to learn its real exit IP/zone,
|
|
137
|
+
* falling back to a direct lookup of the entered host. Body carries connection
|
|
138
|
+
* details inline because detection happens in the create/edit drawer before the
|
|
139
|
+
* proxy is persisted.
|
|
140
|
+
*/
|
|
141
|
+
export declare const DetectTimezoneBodySchema: z.ZodObject<{
|
|
142
|
+
protocol: z.ZodEnum<{
|
|
143
|
+
socks5: "socks5";
|
|
144
|
+
socks4: "socks4";
|
|
145
|
+
http: "http";
|
|
146
|
+
https: "https";
|
|
147
|
+
}>;
|
|
148
|
+
host: z.ZodString;
|
|
149
|
+
port: z.ZodNumber;
|
|
150
|
+
username: z.ZodString;
|
|
151
|
+
password: z.ZodString;
|
|
152
|
+
}, z.core.$strip>;
|
|
153
|
+
export type DetectTimezoneBody = z.infer<typeof DetectTimezoneBodySchema>;
|
|
154
|
+
export declare const DetectTimezoneResultSchema: z.ZodObject<{
|
|
155
|
+
ok: z.ZodBoolean;
|
|
156
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
157
|
+
exit_ip: z.ZodOptional<z.ZodString>;
|
|
158
|
+
country: z.ZodOptional<z.ZodString>;
|
|
159
|
+
source: z.ZodEnum<{
|
|
160
|
+
host: "host";
|
|
161
|
+
proxy: "proxy";
|
|
162
|
+
none: "none";
|
|
163
|
+
}>;
|
|
164
|
+
detail: z.ZodString;
|
|
165
|
+
}, z.core.$strip>;
|
|
166
|
+
export type DetectTimezoneResult = z.infer<typeof DetectTimezoneResultSchema>;
|
|
134
167
|
export declare const DirectorListItemSchema: z.ZodObject<{
|
|
135
168
|
id: z.ZodString;
|
|
136
169
|
name: z.Z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CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;iBAMnC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,0BAA0B;;;;;;;;;;;iBAYrC,CAAC;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAM9E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkBjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,wBAAwB;;;;;iBAKnC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,eAAO,MAAM,mBAAmB;;;;;iBAS5B,CAAC;AACL,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAMhE,eAAO,MAAM,sBAAsB;;;iBAGjC,CAAC;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,2BAA2B;;iBAMpC,CAAC;AACL,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CACzC,OAAO,2BAA2B,CACnC,CAAC"}
|
|
@@ -115,6 +115,33 @@ export const ProxyTestResultSchema = z.object({
|
|
|
115
115
|
latency_ms: z.number().int().nonnegative(),
|
|
116
116
|
detail: z.string(),
|
|
117
117
|
});
|
|
118
|
+
/**
|
|
119
|
+
* Auto-detect timezone for a (not-yet-saved) proxy. The center worker first
|
|
120
|
+
* routes a geo-IP lookup *through* the proxy to learn its real exit IP/zone,
|
|
121
|
+
* falling back to a direct lookup of the entered host. Body carries connection
|
|
122
|
+
* details inline because detection happens in the create/edit drawer before the
|
|
123
|
+
* proxy is persisted.
|
|
124
|
+
*/
|
|
125
|
+
export const DetectTimezoneBodySchema = z.object({
|
|
126
|
+
protocol: ProxyProtocol,
|
|
127
|
+
host: z.string().min(1).max(255),
|
|
128
|
+
port: z.number().int().positive().max(65535),
|
|
129
|
+
username: z.string().min(1).max(255),
|
|
130
|
+
password: z.string().min(1),
|
|
131
|
+
});
|
|
132
|
+
export const DetectTimezoneResultSchema = z.object({
|
|
133
|
+
ok: z.boolean(),
|
|
134
|
+
/** IANA zone, e.g. "Asia/Tokyo". */
|
|
135
|
+
timezone: z.string().optional(),
|
|
136
|
+
/** Exit IP seen by the geo-IP service (only meaningful for source="proxy"). */
|
|
137
|
+
exit_ip: z.string().optional(),
|
|
138
|
+
/** ISO country code, e.g. "JP". */
|
|
139
|
+
country: z.string().optional(),
|
|
140
|
+
/** Where the zone came from: through the proxy, the entered host, or nothing. */
|
|
141
|
+
source: z.enum(["proxy", "host", "none"]),
|
|
142
|
+
/** One-line diagnostic. */
|
|
143
|
+
detail: z.string(),
|
|
144
|
+
});
|
|
118
145
|
/* ============================================================================
|
|
119
146
|
* dp-directors
|
|
120
147
|
* ============================================================================ */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs-contracts.js","sourceRoot":"","sources":["../src/configs-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;;;;GAeG;AAEH;;kFAEkF;AAElF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE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KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;IACxC,OAAO,EAAE,4CAA4C;CACtD,CAAC,CAAC;AAGL;;kFAEkF;AAElF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC;KACzC,MAAM,CAAC;IACN,2BAA2B,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE;CACvE,CAAC;KACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;IACxC,OAAO,EAAE,4CAA4C;CACtD,CAAC,CAAC"}
|
|
@@ -75,8 +75,8 @@ export declare const ConfigInvalidateMessage: z.ZodObject<{
|
|
|
75
75
|
which: z.ZodArray<z.ZodEnum<{
|
|
76
76
|
social_accounts: "social_accounts";
|
|
77
77
|
telegram: "telegram";
|
|
78
|
-
session: "session";
|
|
79
78
|
proxy: "proxy";
|
|
79
|
+
session: "session";
|
|
80
80
|
llm: "llm";
|
|
81
81
|
persona: "persona";
|
|
82
82
|
}>>;
|
|
@@ -300,8 +300,8 @@ export declare const CenterWorkerWsMessage: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
300
300
|
which: z.ZodArray<z.ZodEnum<{
|
|
301
301
|
social_accounts: "social_accounts";
|
|
302
302
|
telegram: "telegram";
|
|
303
|
-
session: "session";
|
|
304
303
|
proxy: "proxy";
|
|
304
|
+
session: "session";
|
|
305
305
|
llm: "llm";
|
|
306
306
|
persona: "persona";
|
|
307
307
|
}>>;
|
|
@@ -144,6 +144,37 @@ export const ProxyTestResultSchema = z.object({
|
|
|
144
144
|
});
|
|
145
145
|
export type ProxyTestResult = z.infer<typeof ProxyTestResultSchema>;
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Auto-detect timezone for a (not-yet-saved) proxy. The center worker first
|
|
149
|
+
* routes a geo-IP lookup *through* the proxy to learn its real exit IP/zone,
|
|
150
|
+
* falling back to a direct lookup of the entered host. Body carries connection
|
|
151
|
+
* details inline because detection happens in the create/edit drawer before the
|
|
152
|
+
* proxy is persisted.
|
|
153
|
+
*/
|
|
154
|
+
export const DetectTimezoneBodySchema = z.object({
|
|
155
|
+
protocol: ProxyProtocol,
|
|
156
|
+
host: z.string().min(1).max(255),
|
|
157
|
+
port: z.number().int().positive().max(65535),
|
|
158
|
+
username: z.string().min(1).max(255),
|
|
159
|
+
password: z.string().min(1),
|
|
160
|
+
});
|
|
161
|
+
export type DetectTimezoneBody = z.infer<typeof DetectTimezoneBodySchema>;
|
|
162
|
+
|
|
163
|
+
export const DetectTimezoneResultSchema = z.object({
|
|
164
|
+
ok: z.boolean(),
|
|
165
|
+
/** IANA zone, e.g. "Asia/Tokyo". */
|
|
166
|
+
timezone: z.string().optional(),
|
|
167
|
+
/** Exit IP seen by the geo-IP service (only meaningful for source="proxy"). */
|
|
168
|
+
exit_ip: z.string().optional(),
|
|
169
|
+
/** ISO country code, e.g. "JP". */
|
|
170
|
+
country: z.string().optional(),
|
|
171
|
+
/** Where the zone came from: through the proxy, the entered host, or nothing. */
|
|
172
|
+
source: z.enum(["proxy", "host", "none"]),
|
|
173
|
+
/** One-line diagnostic. */
|
|
174
|
+
detail: z.string(),
|
|
175
|
+
});
|
|
176
|
+
export type DetectTimezoneResult = z.infer<typeof DetectTimezoneResultSchema>;
|
|
177
|
+
|
|
147
178
|
/* ============================================================================
|
|
148
179
|
* dp-directors
|
|
149
180
|
* ============================================================================ */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dp-worker",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Dipclaw Worker (worker) — browser automation agent with scheduling, skills, and LLM integration. Connects to dp-center via center mode or runs standalone.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|