@cliangdev/conductor 0.50.0 → 0.51.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.
Files changed (57) hide show
  1. package/assets/claude/skills/conductor-marketing-create/SKILL.md +2 -2
  2. package/assets/claude/skills/conductor-marketing-create/references/capabilities.md +12 -2
  3. package/assets/claude/skills/conductor-marketing-create/references/compliance-checklist.md +5 -0
  4. package/assets/claude/skills/conductor-marketing-create/references/direct.md +47 -0
  5. package/assets/claude/skills/conductor-marketing-create/references/realism-check.md +18 -0
  6. package/assets/claude/skills/conductor-marketing-create/references/team-run.md +6 -1
  7. package/assets/cli-manifest.json +8 -0
  8. package/dist/commands/config.d.ts.map +1 -1
  9. package/dist/commands/config.js +113 -0
  10. package/dist/commands/config.js.map +1 -1
  11. package/dist/commands/doctor.d.ts +5 -0
  12. package/dist/commands/doctor.d.ts.map +1 -1
  13. package/dist/commands/doctor.js +41 -0
  14. package/dist/commands/doctor.js.map +1 -1
  15. package/dist/lib/config.d.ts +14 -0
  16. package/dist/lib/config.d.ts.map +1 -1
  17. package/dist/lib/config.js.map +1 -1
  18. package/dist/lib/gemini-omni.d.ts +37 -0
  19. package/dist/lib/gemini-omni.d.ts.map +1 -0
  20. package/dist/lib/gemini-omni.js +133 -0
  21. package/dist/lib/gemini-omni.js.map +1 -0
  22. package/dist/lib/mp4-probe.d.ts +4 -0
  23. package/dist/lib/mp4-probe.d.ts.map +1 -1
  24. package/dist/lib/mp4-probe.js +70 -7
  25. package/dist/lib/mp4-probe.js.map +1 -1
  26. package/dist/lib/provenance-sidecar.d.ts +11 -0
  27. package/dist/lib/provenance-sidecar.d.ts.map +1 -1
  28. package/dist/lib/provenance-sidecar.js.map +1 -1
  29. package/dist/lib/vertex-veo.d.ts +38 -0
  30. package/dist/lib/vertex-veo.d.ts.map +1 -0
  31. package/dist/lib/vertex-veo.js +212 -0
  32. package/dist/lib/vertex-veo.js.map +1 -0
  33. package/dist/lib/video-common.d.ts +141 -0
  34. package/dist/lib/video-common.d.ts.map +1 -0
  35. package/dist/lib/video-common.js +219 -0
  36. package/dist/lib/video-common.js.map +1 -0
  37. package/dist/lib/video-generation.d.ts +44 -0
  38. package/dist/lib/video-generation.d.ts.map +1 -0
  39. package/dist/lib/video-generation.js +132 -0
  40. package/dist/lib/video-generation.js.map +1 -0
  41. package/dist/lib/video-spend.d.ts +9 -0
  42. package/dist/lib/video-spend.d.ts.map +1 -0
  43. package/dist/lib/video-spend.js +44 -0
  44. package/dist/lib/video-spend.js.map +1 -0
  45. package/dist/mcp/index.d.ts +967 -0
  46. package/dist/mcp/index.d.ts.map +1 -1
  47. package/dist/mcp/index.js +46 -0
  48. package/dist/mcp/index.js.map +1 -1
  49. package/dist/mcp/tools/creative-images.d.ts +5 -0
  50. package/dist/mcp/tools/creative-images.d.ts.map +1 -1
  51. package/dist/mcp/tools/creative-images.js +13 -9
  52. package/dist/mcp/tools/creative-images.js.map +1 -1
  53. package/dist/mcp/tools/creative-videos.d.ts +59 -0
  54. package/dist/mcp/tools/creative-videos.d.ts.map +1 -0
  55. package/dist/mcp/tools/creative-videos.js +83 -0
  56. package/dist/mcp/tools/creative-videos.js.map +1 -0
  57. package/package.json +1 -1
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Shared pieces of `generate_creative_video`: types, the per-route capability table, the rate table and
3
+ * cost estimate, input validation and the video placement fit. No network or disk here.
4
+ */
5
+ import { type PlacementFit } from './image-common.js';
6
+ export type VideoRoute = 'vertex' | 'gemini';
7
+ export type VideoTier = 'lite' | 'fast' | 'standard';
8
+ export type VideoAspect = '9:16' | '16:9';
9
+ export type VideoResolution = '720p' | '1080p';
10
+ export declare const VIDEO_TIERS: readonly VideoTier[];
11
+ export declare const VIDEO_ASPECTS: readonly VideoAspect[];
12
+ export declare const VIDEO_RESOLUTIONS: readonly VideoResolution[];
13
+ export declare const DEFAULT_VIDEO_TIER: VideoTier;
14
+ export declare const DEFAULT_VIDEO_DURATION = 4;
15
+ export declare const DEFAULT_VIDEO_REGION = "us-central1";
16
+ export declare const DEFAULT_PER_CALL_CAP_USD = 2;
17
+ export declare const DEFAULT_DAILY_CAP_USD = 5;
18
+ export declare const MAX_FRAME_BYTES: number;
19
+ export declare const VERTEX_MODELS: Record<VideoTier, string>;
20
+ export declare const OMNI_MODEL = "gemini-omni-1.1-flash";
21
+ /** What each route accepts. Veo takes only these durations; Omni takes any whole second in its range. */
22
+ export declare const CAPABILITIES: {
23
+ readonly vertex: {
24
+ readonly durations: readonly number[];
25
+ readonly resolutions: readonly VideoResolution[];
26
+ readonly aspects: readonly VideoAspect[];
27
+ readonly maxCount: 2;
28
+ };
29
+ readonly gemini: {
30
+ readonly minDuration: 3;
31
+ readonly maxDuration: 10;
32
+ readonly resolutions: readonly VideoResolution[];
33
+ readonly aspects: readonly VideoAspect[];
34
+ readonly maxCount: 2;
35
+ };
36
+ };
37
+ /** A frame image already read from disk. */
38
+ export interface VideoFrame {
39
+ base64: string;
40
+ mimeType: 'image/jpeg' | 'image/png';
41
+ }
42
+ /** Params after defaults; paths are validated and read by the orchestrator. */
43
+ export interface VideoRequest {
44
+ prompt: string;
45
+ imagePath?: string;
46
+ lastFramePath?: string;
47
+ aspect: VideoAspect;
48
+ durationSeconds: number;
49
+ resolution: VideoResolution;
50
+ tier: VideoTier;
51
+ generateAudio: boolean;
52
+ count: number;
53
+ negativePrompt?: string;
54
+ seed?: number;
55
+ confirmCost: boolean;
56
+ }
57
+ /** Raw MCP params. */
58
+ export interface VideoParams {
59
+ prompt: string;
60
+ imagePath?: string;
61
+ lastFramePath?: string;
62
+ aspect?: string;
63
+ durationSeconds?: number;
64
+ resolution?: string;
65
+ tier?: string;
66
+ generateAudio?: boolean;
67
+ count?: number;
68
+ negativePrompt?: string;
69
+ seed?: number;
70
+ confirmCost?: boolean;
71
+ }
72
+ /** Conservative (high-side) estimates in USD per second; overridable via config `videoRates`. Re-verify against the console. */
73
+ export declare const DEFAULT_VIDEO_RATES: Record<string, number>;
74
+ export declare function rateKey(route: VideoRoute, tier: VideoTier, resolution: VideoResolution, audio: boolean): string;
75
+ export declare function rateFor(route: VideoRoute, tier: VideoTier, resolution: VideoResolution, audio: boolean, overrides?: Record<string, number>): {
76
+ key: string;
77
+ usdPerSecond: number;
78
+ };
79
+ export interface CostEstimate {
80
+ estimateUsd: number;
81
+ perClipUsd: number;
82
+ usdPerSecond: number;
83
+ breakdown: string;
84
+ }
85
+ /** seconds x rate x count. Omni always makes audio, so its rate ignores `generateAudio`. */
86
+ export declare function estimateCost(req: Pick<VideoRequest, 'durationSeconds' | 'resolution' | 'tier' | 'generateAudio' | 'count'>, route: VideoRoute, overrides?: Record<string, number>): CostEstimate;
87
+ /**
88
+ * Applies defaults and checks everything that does not touch the disk. Throws a plain Error on the first
89
+ * problem; returns warnings (never blocking) alongside the request.
90
+ */
91
+ export declare function normalizeVideoParams(params: VideoParams, route: VideoRoute, region?: string): {
92
+ request: VideoRequest;
93
+ warnings: string[];
94
+ };
95
+ /** Full-bleed fit per placement, plus a warning when 720p would be upscaled at 1080-wide placements. */
96
+ export declare function videoPlacementFit(width: number, height: number): {
97
+ placementFit: Record<string, PlacementFit>;
98
+ warnings: string[];
99
+ };
100
+ /** Typed failure with a stable `code` and extra fields the MCP layer returns as a structured error. */
101
+ export declare class VideoError extends Error {
102
+ readonly code: string;
103
+ readonly details: Record<string, unknown>;
104
+ constructor(code: string, message: string, details?: Record<string, unknown>);
105
+ }
106
+ export declare const SETUP_VERTEX = "`conductor config set-vertex-project <id>` and `gcloud auth login`";
107
+ export declare const SETUP_GEMINI = "`conductor config set-gemini-api-key <key>`";
108
+ export declare class VideoRouteNotConfigured extends VideoError {
109
+ /** `chosen` is config `videoRoute` when it names a route that is missing its setup. */
110
+ constructor(chosen?: VideoRoute);
111
+ }
112
+ /**
113
+ * Marks a failure that happened after Google accepted the job (a lost poll, a failed download), so the
114
+ * caller counts it as spent. Safety-filtered and timed-out results are billable without the mark.
115
+ */
116
+ export declare function markBilled<E extends VideoError>(err: E): E;
117
+ export declare function isBilled(err: unknown): boolean;
118
+ export declare class VideoCostCapExceeded extends VideoError {
119
+ constructor(estimateUsd: number, capUsd: number);
120
+ }
121
+ export declare class VideoDailyCapExceeded extends VideoError {
122
+ constructor(estimateUsd: number, spentTodayUsd: number, capUsd: number);
123
+ }
124
+ export declare class VideoCostConfirmationRequired extends VideoError {
125
+ constructor(info: {
126
+ estimateUsd: number;
127
+ breakdown: string;
128
+ spentTodayUsd: number;
129
+ dailyCapUsd: number;
130
+ route: VideoRoute;
131
+ model: string;
132
+ });
133
+ }
134
+ export declare class VideoSafetyFiltered extends VideoError {
135
+ constructor(reasons?: string);
136
+ }
137
+ /** Maps an HTTP failure from either route to a plain message. */
138
+ export declare function httpFailure(route: VideoRoute, status: number, apiMessage: string, model: string): VideoError;
139
+ /** Extracts `error.message` from a JSON error body, falling back to the status text. Never includes request headers. */
140
+ export declare function readErrorMessage(res: Response): Promise<string>;
141
+ //# sourceMappingURL=video-common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-common.d.ts","sourceRoot":"","sources":["../../src/lib/video-common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEnE,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAC5C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAA;AACpD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAA;AACzC,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,CAAA;AAE9C,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAAiC,CAAA;AAC7E,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAAqB,CAAA;AACrE,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAAsB,CAAA;AAE9E,eAAO,MAAM,kBAAkB,EAAE,SAAkB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K,EAAE,MAAM,CAAA;KAAE;CAG3I;AAED,qBAAa,mBAAoB,SAAQ,UAAU;gBACrC,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAS5G;AAED,wHAAwH;AACxH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAOrE"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Shared pieces of `generate_creative_video`: types, the per-route capability table, the rate table and
3
+ * cost estimate, input validation and the video placement fit. No network or disk here.
4
+ */
5
+ import { placementFit } from './image-common.js';
6
+ export const VIDEO_TIERS = ['lite', 'fast', 'standard'];
7
+ export const VIDEO_ASPECTS = ['9:16', '16:9'];
8
+ export const VIDEO_RESOLUTIONS = ['720p', '1080p'];
9
+ export const DEFAULT_VIDEO_TIER = 'fast';
10
+ export const DEFAULT_VIDEO_DURATION = 4;
11
+ export const DEFAULT_VIDEO_REGION = 'us-central1';
12
+ export const DEFAULT_PER_CALL_CAP_USD = 2;
13
+ export const DEFAULT_DAILY_CAP_USD = 5;
14
+ export const MAX_FRAME_BYTES = 20 * 1024 * 1024;
15
+ export const VERTEX_MODELS = {
16
+ lite: 'veo-3.1-lite-generate-001',
17
+ fast: 'veo-3.1-fast-generate-001',
18
+ standard: 'veo-3.1-generate-001',
19
+ };
20
+ export const OMNI_MODEL = 'gemini-omni-1.1-flash';
21
+ /** What each route accepts. Veo takes only these durations; Omni takes any whole second in its range. */
22
+ export const CAPABILITIES = {
23
+ vertex: { durations: [4, 6, 8], resolutions: VIDEO_RESOLUTIONS, aspects: VIDEO_ASPECTS, maxCount: 2 },
24
+ gemini: { minDuration: 3, maxDuration: 10, resolutions: VIDEO_RESOLUTIONS, aspects: VIDEO_ASPECTS, maxCount: 2 },
25
+ };
26
+ /** Conservative (high-side) estimates in USD per second; overridable via config `videoRates`. Re-verify against the console. */
27
+ export const DEFAULT_VIDEO_RATES = {
28
+ lite: 0.05,
29
+ 'lite+audio': 0.08,
30
+ fast: 0.15,
31
+ 'fast+audio': 0.2,
32
+ standard: 0.4,
33
+ 'standard+audio': 0.6,
34
+ 'omni-720p': 0.1,
35
+ 'omni-1080p': 0.15,
36
+ };
37
+ export function rateKey(route, tier, resolution, audio) {
38
+ if (route === 'gemini')
39
+ return `omni-${resolution}`;
40
+ return audio ? `${tier}+audio` : tier;
41
+ }
42
+ export function rateFor(route, tier, resolution, audio, overrides) {
43
+ const key = rateKey(route, tier, resolution, audio);
44
+ const o = overrides?.[key];
45
+ const usdPerSecond = typeof o === 'number' && Number.isFinite(o) && o >= 0 ? o : DEFAULT_VIDEO_RATES[key];
46
+ return { key, usdPerSecond };
47
+ }
48
+ const money = (n) => `$${n.toFixed(2)}`;
49
+ const round4 = (n) => Math.round(n * 10000) / 10000;
50
+ /** seconds x rate x count. Omni always makes audio, so its rate ignores `generateAudio`. */
51
+ export function estimateCost(req, route, overrides) {
52
+ const { key, usdPerSecond } = rateFor(route, req.tier, req.resolution, req.generateAudio, overrides);
53
+ const perClipUsd = round4(req.durationSeconds * usdPerSecond);
54
+ const estimateUsd = round4(perClipUsd * req.count);
55
+ return {
56
+ estimateUsd,
57
+ perClipUsd,
58
+ usdPerSecond,
59
+ breakdown: `${req.count} clip${req.count === 1 ? '' : 's'} x ${req.durationSeconds} s x ${money(usdPerSecond)}/s (${key}) = ${money(estimateUsd)}, an estimate`,
60
+ };
61
+ }
62
+ const oneOf = (list, v) => typeof v === 'string' && list.includes(v);
63
+ /**
64
+ * Applies defaults and checks everything that does not touch the disk. Throws a plain Error on the first
65
+ * problem; returns warnings (never blocking) alongside the request.
66
+ */
67
+ export function normalizeVideoParams(params, route, region) {
68
+ const warnings = [];
69
+ const prompt = typeof params.prompt === 'string' ? params.prompt.trim() : '';
70
+ if (!prompt)
71
+ throw new Error('prompt is required — describe the motion, the subject and any sound.');
72
+ const aspect = params.aspect ?? '9:16';
73
+ if (!oneOf(VIDEO_ASPECTS, aspect))
74
+ throw new Error(`aspect must be one of ${VIDEO_ASPECTS.join(', ')}.`);
75
+ const resolution = params.resolution ?? '1080p';
76
+ if (!oneOf(VIDEO_RESOLUTIONS, resolution))
77
+ throw new Error(`resolution must be one of ${VIDEO_RESOLUTIONS.join(', ')}.`);
78
+ const tier = params.tier ?? DEFAULT_VIDEO_TIER;
79
+ if (!oneOf(VIDEO_TIERS, tier))
80
+ throw new Error(`tier must be one of ${VIDEO_TIERS.join(', ')}.`);
81
+ const durationSeconds = params.durationSeconds ?? DEFAULT_VIDEO_DURATION;
82
+ if (route === 'vertex') {
83
+ if (!CAPABILITIES.vertex.durations.includes(durationSeconds))
84
+ throw new Error('durationSeconds must be 4, 6 or 8 for Veo.');
85
+ }
86
+ else if (!Number.isInteger(durationSeconds) || durationSeconds < CAPABILITIES.gemini.minDuration || durationSeconds > CAPABILITIES.gemini.maxDuration) {
87
+ throw new Error('durationSeconds must be a whole number from 3 to 10 for Gemini Omni.');
88
+ }
89
+ const count = params.count ?? 1;
90
+ if (!Number.isInteger(count) || count < 1 || count > 2)
91
+ throw new Error('count must be 1 or 2.');
92
+ if (params.generateAudio !== undefined && typeof params.generateAudio !== 'boolean')
93
+ throw new Error('generateAudio must be true or false.');
94
+ if (params.confirmCost !== undefined && typeof params.confirmCost !== 'boolean')
95
+ throw new Error('confirmCost must be true or false.');
96
+ if (params.negativePrompt !== undefined && typeof params.negativePrompt !== 'string')
97
+ throw new Error('negativePrompt must be text.');
98
+ if (params.seed !== undefined && (!Number.isInteger(params.seed) || params.seed < 0))
99
+ throw new Error('seed must be a whole number, 0 or more.');
100
+ if (params.lastFramePath && !params.imagePath)
101
+ throw new Error('lastFramePath needs imagePath (the first frame).');
102
+ if (route === 'gemini') {
103
+ if (params.tier !== undefined)
104
+ warnings.push(`tier "${params.tier}" is ignored on Gemini Omni (one model, ${OMNI_MODEL}).`);
105
+ if (params.seed !== undefined)
106
+ warnings.push('seed is ignored on Gemini Omni.');
107
+ if (params.generateAudio !== true)
108
+ warnings.push('Omni always makes audio; it is stripped from the saved file when ffmpeg is available.');
109
+ }
110
+ else if (region && region !== DEFAULT_VIDEO_REGION) {
111
+ warnings.push(`Veo on Vertex is documented for ${DEFAULT_VIDEO_REGION} only; region "${region}" may be refused. Run \`conductor config set-vertex-region ${DEFAULT_VIDEO_REGION}\` if it fails.`);
112
+ }
113
+ return {
114
+ request: {
115
+ prompt,
116
+ ...(params.imagePath ? { imagePath: params.imagePath } : {}),
117
+ ...(params.lastFramePath ? { lastFramePath: params.lastFramePath } : {}),
118
+ aspect,
119
+ durationSeconds,
120
+ resolution,
121
+ tier,
122
+ generateAudio: params.generateAudio ?? false,
123
+ count,
124
+ ...(params.negativePrompt?.trim() ? { negativePrompt: params.negativePrompt.trim() } : {}),
125
+ ...(params.seed !== undefined ? { seed: params.seed } : {}),
126
+ confirmCost: params.confirmCost === true,
127
+ },
128
+ warnings,
129
+ };
130
+ }
131
+ /** Full-bleed fit per placement, plus a warning when 720p would be upscaled at 1080-wide placements. */
132
+ export function videoPlacementFit(width, height) {
133
+ const fit = placementFit(width, height);
134
+ const warnings = [];
135
+ const over = Object.entries(fit).filter(([, f]) => !f.ok);
136
+ if (over.length) {
137
+ warnings.push(`This ${width}x${height} clip is upscaled at ${over.map(([p, f]) => `${p} (${f.scale}x)`).join(', ')} when shown full-bleed on a 1080-wide placement; fine for a draft, use 1080p for a final.`);
138
+ }
139
+ return { placementFit: fit, warnings };
140
+ }
141
+ /** Typed failure with a stable `code` and extra fields the MCP layer returns as a structured error. */
142
+ export class VideoError extends Error {
143
+ constructor(code, message, details = {}) {
144
+ super(message);
145
+ this.code = code;
146
+ this.details = details;
147
+ this.name = 'VideoError';
148
+ }
149
+ }
150
+ export const SETUP_VERTEX = '`conductor config set-vertex-project <id>` and `gcloud auth login`';
151
+ export const SETUP_GEMINI = '`conductor config set-gemini-api-key <key>`';
152
+ export class VideoRouteNotConfigured extends VideoError {
153
+ /** `chosen` is config `videoRoute` when it names a route that is missing its setup. */
154
+ constructor(chosen) {
155
+ const message = chosen === 'vertex'
156
+ ? `videoRoute is set to vertex, but no Vertex project is set. Run ${SETUP_VERTEX}, or switch with \`conductor config set-video-route gemini\`. Nothing was generated or billed.`
157
+ : chosen === 'gemini'
158
+ ? `videoRoute is set to gemini, but no Gemini API key was found (CONDUCTOR_GEMINI_API_KEY, GEMINI_API_KEY or config). Run ${SETUP_GEMINI}, or switch with \`conductor config set-video-route vertex\`. Nothing was generated or billed.`
159
+ : `No video route is set up. Either run ${SETUP_VERTEX} (Veo on Vertex AI), or ${SETUP_GEMINI} (Gemini Omni). Nothing was generated or billed.`;
160
+ super('VIDEO_ROUTE_NOT_CONFIGURED', message, chosen ? { videoRoute: chosen } : {});
161
+ }
162
+ }
163
+ /**
164
+ * Marks a failure that happened after Google accepted the job (a lost poll, a failed download), so the
165
+ * caller counts it as spent. Safety-filtered and timed-out results are billable without the mark.
166
+ */
167
+ export function markBilled(err) {
168
+ err.details['billed'] = true;
169
+ return err;
170
+ }
171
+ export function isBilled(err) {
172
+ if (!(err instanceof VideoError))
173
+ return false;
174
+ return err instanceof VideoSafetyFiltered || err.code === 'VIDEO_TIMEOUT' || err.details['billed'] === true;
175
+ }
176
+ export class VideoCostCapExceeded extends VideoError {
177
+ constructor(estimateUsd, capUsd) {
178
+ super('VIDEO_COST_CAP_EXCEEDED', `Estimated ${money(estimateUsd)} is over the per-call cap of ${money(capUsd)}. Use fewer or shorter clips, a cheaper tier, or raise the cap with \`conductor config set-video-caps --per-call <usd>\`.`, { estimateUsd, perCallCapUsd: capUsd });
179
+ }
180
+ }
181
+ export class VideoDailyCapExceeded extends VideoError {
182
+ constructor(estimateUsd, spentTodayUsd, capUsd) {
183
+ super('VIDEO_DAILY_CAP_EXCEEDED', `Estimated ${money(estimateUsd)} plus ${money(spentTodayUsd)} already spent today passes the daily cap of ${money(capUsd)}. Wait until tomorrow or raise it with \`conductor config set-video-caps --daily <usd>\`.`, { estimateUsd, spentTodayUsd, dailyCapUsd: capUsd });
184
+ }
185
+ }
186
+ export class VideoCostConfirmationRequired extends VideoError {
187
+ constructor(info) {
188
+ super('VIDEO_COST_CONFIRMATION_REQUIRED', `This will cost about ${money(info.estimateUsd)} (${info.breakdown}). Tell the person, and call again with confirmCost: true only after they agree.`, info);
189
+ }
190
+ }
191
+ export class VideoSafetyFiltered extends VideoError {
192
+ constructor(reasons) {
193
+ super('VIDEO_SAFETY_FILTERED', `The model's safety filter blocked the video${reasons ? ` (${reasons})` : ''}. Google bills a filtered request, so the estimate was counted as spent. Rewrite the prompt (and check the first frame) and try again.`, reasons ? { reasons } : {});
194
+ }
195
+ }
196
+ /** Maps an HTTP failure from either route to a plain message. */
197
+ export function httpFailure(route, status, apiMessage, model) {
198
+ const setup = route === 'vertex' ? SETUP_VERTEX : SETUP_GEMINI;
199
+ const name = route === 'vertex' ? 'Vertex AI' : 'the Gemini API';
200
+ if (status === 404) {
201
+ return new VideoError('VIDEO_MODEL_NOT_FOUND', `${name} says model ${model} was not found. Valid ids: ${route === 'vertex' ? Object.values(VERTEX_MODELS).join(', ') : OMNI_MODEL}. CONDUCTOR_VIDEO_MODEL overrides the id.`);
202
+ }
203
+ if (status === 429)
204
+ return new VideoError('VIDEO_QUOTA', `${name} is out of quota or rate limited (429). Wait a few minutes or raise the quota. It says: ${apiMessage}`);
205
+ if (status === 401 || status === 403)
206
+ return new VideoError('VIDEO_AUTH', `${name} rejected the credentials (${status}). Check ${setup}. It says: ${apiMessage}`);
207
+ return new VideoError('VIDEO_FAILED', `${name} video generation failed (${status}): ${apiMessage}`);
208
+ }
209
+ /** Extracts `error.message` from a JSON error body, falling back to the status text. Never includes request headers. */
210
+ export async function readErrorMessage(res) {
211
+ try {
212
+ const body = (await res.json());
213
+ return body.error?.message ?? res.statusText ?? 'unknown error';
214
+ }
215
+ catch {
216
+ return res.statusText || 'unknown error';
217
+ }
218
+ }
219
+ //# sourceMappingURL=video-common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-common.js","sourceRoot":"","sources":["../../src/lib/video-common.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAA;AAOnE,MAAM,CAAC,MAAM,WAAW,GAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAA;AAC7E,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACrE,MAAM,CAAC,MAAM,iBAAiB,GAA+B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE9E,MAAM,CAAC,MAAM,kBAAkB,GAAc,MAAM,CAAA;AACnD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAA;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAA;AACjD,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAA;AACzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AACtC,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAE/C,MAAM,CAAC,MAAM,aAAa,GAA8B;IACtD,IAAI,EAAE,2BAA2B;IACjC,IAAI,EAAE,2BAA2B;IACjC,QAAQ,EAAE,sBAAsB;CACjC,CAAA;AACD,MAAM,CAAC,MAAM,UAAU,GAAG,uBAAuB,CAAA;AAEjD,yGAAyG;AACzG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAsB,EAAE,WAAW,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,EAAE;IAC1H,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,EA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AI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAqC,CAAA;QACnE,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,GAAG,CAAC,UAAU,IAAI,eAAe,CAAA;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,CAAC,UAAU,IAAI,eAAe,CAAA;IAC1C,CAAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type OmniDeps } from './gemini-omni.js';
2
+ import { type VertexDeps } from './vertex-veo.js';
3
+ import { type SpendOptions } from './video-spend.js';
4
+ import { type VideoParams, type VideoRequest, type VideoRoute } from './video-common.js';
5
+ export interface RouteChoice {
6
+ route: VideoRoute;
7
+ /** Region for Vertex. */
8
+ region: string;
9
+ project?: string;
10
+ apiKey?: string;
11
+ }
12
+ /** Config `videoRoute`; unset: vertex if a project is set, else gemini if a key resolves. Null when neither works. */
13
+ export declare function pickVideoRoute(): RouteChoice | null;
14
+ export declare function videoModel(route: VideoRoute, tier: VideoRequest['tier']): string;
15
+ export declare function videoCaps(): {
16
+ perCallUsd: number;
17
+ dailyUsd: number;
18
+ };
19
+ export interface GenerateVideosOptions {
20
+ onProgress?: (message: string) => void;
21
+ cwd?: string;
22
+ spend?: SpendOptions;
23
+ vertex?: VertexDeps;
24
+ omni?: OmniDeps;
25
+ }
26
+ export interface GenerateVideosResult {
27
+ videos: Buffer[];
28
+ request: VideoRequest;
29
+ route: VideoRoute;
30
+ model: string;
31
+ /** The estimate for everything asked for. */
32
+ estimateUsd: number;
33
+ /** The estimate for one clip. */
34
+ perClipUsd: number;
35
+ /** What was counted as spent for this call (less than estimateUsd when an Omni run stopped early). */
36
+ billedUsd: number;
37
+ spentTodayUsd: number;
38
+ dailyCapUsd: number;
39
+ warnings: string[];
40
+ sourceImagePath?: string;
41
+ lastFramePath?: string;
42
+ }
43
+ export declare function generateVideos(params: VideoParams, options?: GenerateVideosOptions): Promise<GenerateVideosResult>;
44
+ //# sourceMappingURL=video-generation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-generation.d.ts","sourceRoot":"","sources":["../../src/lib/video-generation.ts"],"names":[],"mappings":"AAUA,OAAO,EAAsC,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACxE,OAAO,EAeL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAA;AAE1B,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,UAAU,CAAA;IACjB,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,sHAAsH;AACtH,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAUnD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM,CAEhF;AAED,wBAAgB,SAAS,IAAI;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAIpE;AAaD,MAAM,WAAW,qBAAqB;IACpC,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,OAAO,EAAE,YAAY,CAAA;IACrB,KAAK,EAAE,UAAU,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAA;IACnB,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,sGAAsG;IACtG,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6E5H"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Picks the video route and runs the gate, in this order: route configured, inputs valid, per-call cap,
3
+ * daily cap, cost confirmation. Only then does it call Veo (Vertex) or Gemini Omni. Spend is recorded after
4
+ * a successful call, and after any failure Google still bills (safety filter, timeout, a job lost after it
5
+ * was accepted, a failed download): see isBilled.
6
+ */
7
+ import { existsSync, statSync } from 'node:fs';
8
+ import { readFile } from 'node:fs/promises';
9
+ import { extname, isAbsolute, resolve } from 'node:path';
10
+ import { readConfig } from './config.js';
11
+ import { generateOmniClip, resolveGeminiKey } from './gemini-omni.js';
12
+ import { generateWithVertex } from './vertex-veo.js';
13
+ import { record, spentToday } from './video-spend.js';
14
+ import { DEFAULT_DAILY_CAP_USD, DEFAULT_PER_CALL_CAP_USD, DEFAULT_VIDEO_REGION, MAX_FRAME_BYTES, OMNI_MODEL, VERTEX_MODELS, VideoCostCapExceeded, VideoCostConfirmationRequired, VideoDailyCapExceeded, VideoRouteNotConfigured, estimateCost, isBilled, normalizeVideoParams, } from './video-common.js';
15
+ /** Config `videoRoute`; unset: vertex if a project is set, else gemini if a key resolves. Null when neither works. */
16
+ export function pickVideoRoute() {
17
+ const cfg = readConfig();
18
+ const project = cfg?.vertexProject?.trim();
19
+ const region = cfg?.vertexRegion?.trim() || DEFAULT_VIDEO_REGION;
20
+ const key = resolveGeminiKey();
21
+ const vertex = project ? { route: 'vertex', region, project } : null;
22
+ const gemini = key ? { route: 'gemini', region, apiKey: key.key } : null;
23
+ if (cfg?.videoRoute === 'vertex')
24
+ return vertex;
25
+ if (cfg?.videoRoute === 'gemini')
26
+ return gemini;
27
+ return vertex ?? gemini;
28
+ }
29
+ export function videoModel(route, tier) {
30
+ return process.env['CONDUCTOR_VIDEO_MODEL']?.trim() || (route === 'vertex' ? VERTEX_MODELS[tier] : OMNI_MODEL);
31
+ }
32
+ export function videoCaps() {
33
+ const cfg = readConfig();
34
+ const ok = (n, d) => (typeof n === 'number' && Number.isFinite(n) && n > 0 ? n : d);
35
+ return { perCallUsd: ok(cfg?.videoPerCallCapUsd, DEFAULT_PER_CALL_CAP_USD), dailyUsd: ok(cfg?.videoDailyCapUsd, DEFAULT_DAILY_CAP_USD) };
36
+ }
37
+ const FRAME_TYPES = { '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.png': 'image/png' };
38
+ function checkFrame(label, p, cwd) {
39
+ const abs = isAbsolute(p) ? p : resolve(cwd, p);
40
+ if (!existsSync(abs) || !statSync(abs).isFile())
41
+ throw new Error(`${label} not found: ${p}`);
42
+ const mimeType = FRAME_TYPES[extname(abs).toLowerCase()];
43
+ if (!mimeType)
44
+ throw new Error(`${label} must be a JPEG or PNG: ${p}`);
45
+ if (statSync(abs).size > MAX_FRAME_BYTES)
46
+ throw new Error(`${label} is over 20 MB: ${p}`);
47
+ return { abs, mimeType };
48
+ }
49
+ export async function generateVideos(params, options = {}) {
50
+ const cwd = options.cwd ?? process.cwd();
51
+ // 1. A route must be set up.
52
+ const choice = pickVideoRoute();
53
+ if (!choice) {
54
+ const chosen = readConfig()?.videoRoute;
55
+ throw new VideoRouteNotConfigured(chosen === 'vertex' || chosen === 'gemini' ? chosen : undefined);
56
+ }
57
+ // 2. Inputs against what the route can do.
58
+ const { request, warnings } = normalizeVideoParams(params, choice.route, choice.region);
59
+ const image = request.imagePath ? checkFrame('imagePath', request.imagePath, cwd) : undefined;
60
+ const last = request.lastFramePath ? checkFrame('lastFramePath', request.lastFramePath, cwd) : undefined;
61
+ const model = videoModel(choice.route, request.tier);
62
+ // 3. Caps, then confirmation.
63
+ const caps = videoCaps();
64
+ const est = estimateCost(request, choice.route, readConfig()?.videoRates);
65
+ if (est.estimateUsd > caps.perCallUsd)
66
+ throw new VideoCostCapExceeded(est.estimateUsd, caps.perCallUsd);
67
+ const before = spentToday(options.spend);
68
+ if (before + est.estimateUsd > caps.dailyUsd)
69
+ throw new VideoDailyCapExceeded(est.estimateUsd, before, caps.dailyUsd);
70
+ if (!request.confirmCost) {
71
+ throw new VideoCostConfirmationRequired({ estimateUsd: est.estimateUsd, breakdown: est.breakdown, spentTodayUsd: before, dailyCapUsd: caps.dailyUsd, route: choice.route, model });
72
+ }
73
+ const load = async (f) => f ? { base64: (await readFile(f.abs)).toString('base64'), mimeType: f.mimeType } : undefined;
74
+ const frames = { image: await load(image), lastFrame: await load(last) };
75
+ const clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
76
+ const videos = [];
77
+ let billedUsd = 0;
78
+ const bill = (usd) => {
79
+ record(usd, options.spend);
80
+ billedUsd += usd;
81
+ };
82
+ try {
83
+ if (choice.route === 'vertex') {
84
+ const out = await generateWithVertex(request, clean(frames), { project: choice.project, region: choice.region, model, onProgress: options.onProgress }, options.vertex);
85
+ videos.push(...out.videos);
86
+ warnings.push(...out.warnings);
87
+ bill(est.estimateUsd);
88
+ }
89
+ else {
90
+ for (let i = 0; i < request.count; i++) {
91
+ if (request.count > 1)
92
+ options.onProgress?.(`Clip ${i + 1} of ${request.count}`);
93
+ try {
94
+ const out = await generateOmniClip(request, clean(frames), { apiKey: choice.apiKey, model, onProgress: options.onProgress }, options.omni);
95
+ videos.push(out.video);
96
+ warnings.push(...out.warnings);
97
+ bill(est.perClipUsd);
98
+ }
99
+ catch (err) {
100
+ // Keep the clips already made (and billed) rather than throwing them away.
101
+ if (videos.length === 0)
102
+ throw err;
103
+ if (isBilled(err))
104
+ bill(est.perClipUsd);
105
+ warnings.push(`Clip ${i + 1} of ${request.count} failed (${err.message}); returning the ${videos.length} that finished.`);
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ catch (err) {
112
+ // Google bills a safety-filtered request, and a timed-out or lost job may still finish and be billed.
113
+ if (isBilled(err))
114
+ bill(choice.route === 'vertex' ? est.estimateUsd : est.perClipUsd);
115
+ throw err;
116
+ }
117
+ return {
118
+ videos,
119
+ request,
120
+ route: choice.route,
121
+ model,
122
+ estimateUsd: est.estimateUsd,
123
+ perClipUsd: est.perClipUsd,
124
+ billedUsd: Math.round(billedUsd * 10000) / 10000,
125
+ spentTodayUsd: spentToday(options.spend),
126
+ dailyCapUsd: caps.dailyUsd,
127
+ warnings,
128
+ ...(image ? { sourceImagePath: image.abs } : {}),
129
+ ...(last ? { lastFramePath: last.abs } : {}),
130
+ };
131
+ }
132
+ //# sourceMappingURL=video-generation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-generation.js","sourceRoot":"","sources":["../../src/lib/video-generation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAiB,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAE,kBAAkB,EAAmB,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAqB,MAAM,kBAAkB,CAAA;AACxE,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,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,eAAe,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC7C,CAAA;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const SPEND_PATH: string;
2
+ export interface SpendOptions {
3
+ path?: string;
4
+ now?: Date;
5
+ }
6
+ export declare function localDate(d: Date): string;
7
+ export declare function spentToday(opts?: SpendOptions): number;
8
+ export declare function record(amountUsd: number, opts?: SpendOptions): number;
9
+ //# sourceMappingURL=video-spend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"video-spend.d.ts","sourceRoot":"","sources":["../../src/lib/video-spend.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,UAAU,QAA4D,CAAA;AAGnF,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,IAAI,CAAA;CACX;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAGzC;AAYD,wBAAgB,UAAU,CAAC,IAAI,GAAE,YAAiB,GAAG,MAAM,CAE1D;AAED,wBAAgB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,MAAM,CAczE"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Local ledger of estimated video spend, keyed by local date, so the daily cap holds across sessions.
3
+ * `~/.conductor/video-spend.json`: { "2026-11-04": 1.2 }. Only today and the last few days are kept.
4
+ */
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ export const SPEND_PATH = path.join(os.homedir(), '.conductor', 'video-spend.json');
9
+ const KEEP_DAYS = 7;
10
+ export function localDate(d) {
11
+ const p = (n) => String(n).padStart(2, '0');
12
+ return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
13
+ }
14
+ function read(file) {
15
+ try {
16
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
17
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
18
+ return {};
19
+ return Object.fromEntries(Object.entries(parsed).filter(([, v]) => typeof v === 'number' && Number.isFinite(v)));
20
+ }
21
+ catch {
22
+ return {};
23
+ }
24
+ }
25
+ export function spentToday(opts = {}) {
26
+ return read(opts.path ?? SPEND_PATH)[localDate(opts.now ?? new Date())] ?? 0;
27
+ }
28
+ export function record(amountUsd, opts = {}) {
29
+ const file = opts.path ?? SPEND_PATH;
30
+ const now = opts.now ?? new Date();
31
+ const today = localDate(now);
32
+ const cutoff = localDate(new Date(now.getFullYear(), now.getMonth(), now.getDate() - KEEP_DAYS));
33
+ const ledger = Object.fromEntries(Object.entries(read(file)).filter(([day]) => day >= cutoff));
34
+ ledger[today] = Math.round(((ledger[today] ?? 0) + amountUsd) * 10000) / 10000;
35
+ try {
36
+ fs.mkdirSync(path.dirname(file), { recursive: true });
37
+ fs.writeFileSync(file, JSON.stringify(ledger, null, 2) + '\n', { mode: 0o600 });
38
+ }
39
+ catch {
40
+ /* a ledger that cannot be written must not lose the clip */
41
+ }
42
+ return ledger[today];
43
+ }
44
+ //# sourceMappingURL=video-spend.js.map