@cliangdev/conductor 0.23.0 → 0.24.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.
@@ -12,6 +12,10 @@ import { dirname, join } from 'node:path';
12
12
  import { fileURLToPath } from 'node:url';
13
13
  import { apiGet, apiPost, ApiError } from '../mcp/api.js';
14
14
  import { findBrowserFactory } from './creative-browser.js';
15
+ import { resolveFfmpegPath } from './media-probe.js';
16
+ /** Frames per second for a MOTION render's ffmpeg encode — fixed, not user-configurable (see
17
+ * conductor-creative/README.md's job/render.mjs section). */
18
+ const MOTION_FPS = 30;
15
19
  /** Where `npm run build` copies `conductor-creative/`'s runtime files, relative to this file's own
16
20
  * compiled location (`dist/lib/creative-render.js` -> `dist/creative/job/`). */
17
21
  function jobDir() {
@@ -34,11 +38,10 @@ async function loadRenderCore() {
34
38
  return { run: renderMod.run, createApiTransport: transportMod.createApiTransport };
35
39
  }
36
40
  /**
37
- * A CLIP (or, once PR 2 lands, MOTION) creative has no local browser render path — the backend either
38
- * assembles the frames itself synchronously (CLIP) or refuses with a 422 explaining why (MOTION, until
39
- * its renderer ships). Either way this just POSTs the render and relays what came back — `ApiError`'s
40
- * `message` is already the server's own plain-English sentence (an RFC 7807 `detail`), so a MOTION 422
41
- * reaches the caller unchanged rather than wrapped in a generic "never started" message.
41
+ * A CLIP creative has no local browser render path at all — it's a finished video used as-is, and
42
+ * the backend assembles its frames itself synchronously. This just POSTs the render and relays what
43
+ * came back — `ApiError`'s `message` is already the server's own plain-English sentence (an RFC 7807
44
+ * `detail`), so a failure reaches the caller unchanged rather than wrapped in a generic message.
42
45
  */
43
46
  async function renderViaApi(params, config) {
44
47
  try {
@@ -53,16 +56,29 @@ async function renderViaApi(params, config) {
53
56
  }
54
57
  }
55
58
  /**
56
- * Renders a Creative end to end. STILL creatives find a local browser and run the render core against
57
- * the external API, reading back the stored render (frames with signed URLs, final state) whether or
58
- * not the render itself succeeded — a FAILED render still has an id and an error message worth
59
- * returning. CLIP (and MOTION) creatives never launch a browser — see {@link renderViaApi}.
59
+ * Renders a Creative end to end. STILL and MOTION creatives both find a local browser and run the
60
+ * render core against the external API, reading back the stored render (frames with signed URLs,
61
+ * final state) whether or not the render itself succeeded — a FAILED render still has an id and an
62
+ * error message worth returning. A MOTION render (not previewOnly) additionally needs a local ffmpeg
63
+ * binary — resolved the same way `upload_creative_media`/`media-probe.ts` finds one (a system binary
64
+ * on PATH first, else the bundled `ffmpeg-static` fallback) — and runs at a fixed 30fps; a previewOnly
65
+ * MOTION render (the key-moments contact sheet) needs neither ffmpeg nor a video encode, so it skips
66
+ * this resolution entirely. CLIP creatives never launch a browser — see {@link renderViaApi}.
60
67
  */
61
68
  export async function renderCreative(params, config, log = () => { }) {
62
69
  const creative = await apiGet(`/api/v2/projects/${config.projectId}/marketing/creatives/${params.creativeId}`, config);
63
- if (creative.kind && creative.kind !== 'STILL') {
70
+ if (creative.kind === 'CLIP') {
64
71
  return renderViaApi(params, config);
65
72
  }
73
+ let ffmpegPath;
74
+ if (creative.kind === 'MOTION' && !params.previewOnly) {
75
+ try {
76
+ ffmpegPath = await resolveFfmpegPath();
77
+ }
78
+ catch (err) {
79
+ return { ok: false, error: err instanceof Error ? err.message : String(err), frames: [] };
80
+ }
81
+ }
66
82
  const { run, createApiTransport } = await loadRenderCore();
67
83
  const transport = createApiTransport({
68
84
  apiUrl: config.apiUrl,
@@ -74,7 +90,9 @@ export async function renderCreative(params, config, log = () => { }) {
74
90
  workflowRunId: params.workflowRunId,
75
91
  });
76
92
  const browserFactory = await findBrowserFactory(log);
77
- const ok = await run({ transport, browserFactory, log });
93
+ // fps only matters on the MOTION encode path (run() ignores it otherwise); passing it
94
+ // unconditionally keeps this call site simple and matches the engine's own default.
95
+ const ok = await run({ transport, browserFactory, log, ffmpegPath, fps: MOTION_FPS });
78
96
  const renderId = transport.getRenderId();
79
97
  if (!renderId) {
80
98
  return { ok: false, error: 'The render was never started — the API rejected the request before a render id was assigned.', fr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