@gobing-ai/knowledge-kit 0.1.29 → 0.1.30
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/.claude-plugin/marketplace.json +1 -1
- package/dist/board/api.js +8724 -3861
- package/dist/board/collect/index.js +69 -1
- package/dist/board/daily-voice/index.js +474 -265
- package/dist/board/itc/index.js +69 -1
- package/dist/board/wiki/index.css +1305 -0
- package/dist/board/wiki/index.js +1621 -0
- package/dist/index.js +34689 -28532
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +14 -1
- package/plugins/generations/core-facts-gen/dist/index.js +14 -1
- package/plugins/generations/daily-article-gen/dist/index.js +14 -1
- package/plugins/generations/dailynews-gen/dist/index.js +14 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +32 -2
- package/plugins/generations/episode-plan-gen/src/index.ts +19 -1
- package/plugins/generations/gemini-tts/dist/index.js +14 -1
- package/plugins/generations/image-gen/dist/index.js +14 -1
- package/plugins/generations/music-gen/dist/index.js +15 -2
- package/plugins/generations/news-report-gen/dist/index.js +14 -1
- package/plugins/generations/vibe-voice-tts/dist/index.js +14 -1
- package/plugins/generations/video-gen/README.md +245 -8
- package/plugins/generations/video-gen/dist/index.js +22447 -4763
- package/plugins/generations/video-gen/package.json +1 -0
- package/plugins/generations/video-gen/presets/formats/avatar.yaml +5 -0
- package/plugins/generations/video-gen/presets/formats/editorial.yaml +6 -0
- package/plugins/generations/video-gen/presets/formats/hybrid-pip.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/daily-ai.yaml +5 -0
- package/plugins/generations/video-gen/presets/styles/neutral.yaml +3 -0
- package/plugins/generations/video-gen/python/colab_comfyui_h3.py +322 -0
- package/plugins/generations/video-gen/python/comfyui-h3-i2v-api.json +47 -0
- package/plugins/generations/video-gen/python/comfyui-h3-models.json +32 -0
- package/plugins/generations/video-gen/python/comfyui_model_cache.py +388 -0
- package/plugins/generations/video-gen/python/drive_client.py +187 -0
- package/plugins/generations/video-gen/src/brief-cli.ts +65 -0
- package/plugins/generations/video-gen/src/brief.ts +464 -0
- package/plugins/generations/video-gen/src/ccu-ledger.ts +206 -3
- package/plugins/generations/video-gen/src/colab-runner.ts +346 -35
- package/plugins/generations/video-gen/src/index.ts +141 -109
- package/plugins/generations/video-gen/src/inputs.ts +162 -4
- package/plugins/generations/video-gen/src/layout.ts +33 -0
- package/plugins/generations/video-gen/src/props.ts +27 -3
- package/plugins/generations/video-gen/src/remotion/AvatarReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/EditorialReel.tsx +17 -1
- package/plugins/generations/video-gen/src/remotion/Root.tsx +2 -0
- package/plugins/generations/video-gen/src/remotion/engine.ts +3 -7
- package/plugins/generations/video-gen/src/render.ts +25 -0
- package/plugins/generations/video-gen/src/request.ts +150 -20
- package/plugins/generations/video-gen/src/visual-provider.ts +116 -3
- package/plugins/generations/voice-gen/dist/index.js +14 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +14 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +14 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +14 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +14 -1
- package/plugins/ingestions/web-search/dist/index.js +14 -1
- package/plugins/kk/config.example.yaml +1 -1
- package/plugins/kk/mcp-tools.yaml +47 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/itc-surfdash-locales.json +42 -0
- package/plugins/kk/scripts/daily-stages.ts +87 -6
- package/plugins/kk/scripts/kk-workflow-stages.ts +64 -9
- package/plugins/kk/scripts/video-stages.ts +332 -0
- package/plugins/kk/scripts/wiki-normalize-audio.ts +354 -0
- package/plugins/kk/scripts/wiki-normalize-document.ts +495 -0
- package/plugins/kk/scripts/wiki-normalize-stages.ts +96 -0
- package/plugins/kk/scripts/wiki-stage-runtime.ts +39 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +2 -1
- package/plugins/kk/workflows/kk-collect.yaml +10 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +70 -8
- package/plugins/kk/workflows/kk-smart-seo.yaml +8 -0
- package/plugins/kk/workflows/kk-storm-research.yaml +10 -0
- package/plugins/kk/workflows/kk-video-generate.yaml +169 -0
- package/plugins/kk/workflows/kk-wiki-digest.yaml +49 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +281 -268
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/cnblogs-pub/dist/index.js +281 -268
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/csdn-pub/dist/index.js +281 -268
- package/plugins/publishings/csdn-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/emdash-pub/dist/index.js +33 -3
- package/plugins/publishings/infoq-pub/dist/index.js +281 -268
- package/plugins/publishings/infoq-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/jike-pub/dist/index.js +281 -268
- package/plugins/publishings/jike-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/juejin-pub/dist/index.js +281 -268
- package/plugins/publishings/juejin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +281 -268
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/medium-pub/dist/index.js +281 -268
- package/plugins/publishings/medium-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/podcast-pub/dist/index.js +39 -9
- package/plugins/publishings/qiita-pub/dist/index.js +33 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +281 -268
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +175 -0
- package/plugins/publishings/sspai-pub/dist/index.js +281 -268
- package/plugins/publishings/sspai-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/substack-pub/dist/index.js +281 -268
- package/plugins/publishings/substack-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +99 -39
- package/plugins/publishings/surfdash-pub/plugin.json +54 -0
- package/plugins/publishings/surfdash-pub/src/index.ts +36 -5
- package/plugins/publishings/threads-pub/dist/index.js +281 -268
- package/plugins/publishings/threads-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/wechatmp-pub/dist/index.js +665 -451
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +215 -3
- package/plugins/publishings/weibo-pub/dist/index.js +281 -268
- package/plugins/publishings/weibo-pub/dist/profile-check.js +189 -1
- package/plugins/publishings/x-pub/dist/index.js +281 -268
- package/plugins/publishings/x-pub/dist/profile-check.js +216 -1
- package/plugins/publishings/xhs-pub/dist/index.js +281 -268
- package/plugins/publishings/xhs-pub/dist/profile-check.js +119 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +281 -268
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +202 -0
- package/plugins/publishings/youtube-pub/dist/index.js +14 -1
- package/plugins/publishings/zenn-pub/dist/index.js +37 -7
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import type { Doc } from '@gobing-ai/kk-core';
|
|
4
|
+
import type { FileSystem } from '@gobing-ai/ts-runtime';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { nodeFileSystem } from './fs';
|
|
7
|
+
import { probeAudioDuration } from './hook-slicer';
|
|
8
|
+
import { type RunProcess, runtimeRunProcess } from './process';
|
|
9
|
+
import {
|
|
10
|
+
AVATAR_PROVIDERS,
|
|
11
|
+
ColabRequestSchema,
|
|
12
|
+
type ExplicitVideoRequest,
|
|
13
|
+
HookWindowSchema,
|
|
14
|
+
parseExplicitVideoRequest,
|
|
15
|
+
VideoPresentationSchema,
|
|
16
|
+
} from './request';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Standalone video briefs (D91 R2–R3, task 0455).
|
|
20
|
+
*
|
|
21
|
+
* A brief is authored YAML; the shipped `presets/` are portable data; runtime settings (provider,
|
|
22
|
+
* GPU, fallback) live in operator config, never in a brief or a preset. This module is the only
|
|
23
|
+
* place those three layers meet, and its output is the request 0454's parser already validates —
|
|
24
|
+
* so a brief cannot express anything the renderer does not accept.
|
|
25
|
+
*
|
|
26
|
+
* Precedence: brief → style → format → built-ins for presentation, `runtime_file` → `video:` config
|
|
27
|
+
* → defaults for runtime. Media paths always resolve against the brief file's directory.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const DEFAULT_PLUGIN_ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
31
|
+
|
|
32
|
+
/** Shipped format presets (one file each under `presets/formats/`). */
|
|
33
|
+
export const SHIPPED_FORMATS = ['editorial', 'avatar', 'hybrid-pip'] as const;
|
|
34
|
+
/** Shipped style presets (one file each under `presets/styles/`). */
|
|
35
|
+
export const SHIPPED_STYLES = ['neutral', 'daily-ai'] as const;
|
|
36
|
+
export const DEFAULT_VIDEO_FORMAT = 'editorial';
|
|
37
|
+
export const DEFAULT_VIDEO_STYLE = 'neutral';
|
|
38
|
+
/** Format default when the preset names no duration: a 60s short, clamped to the source at render. */
|
|
39
|
+
export const DEFAULT_DURATION_TARGET_SEC = 60;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A preset name is one path segment of portable data. Anything else (separators, `..`, uppercase,
|
|
43
|
+
* dots) is refused by NAME, so a traversal never becomes a read.
|
|
44
|
+
*/
|
|
45
|
+
const PRESET_NAME_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
|
|
46
|
+
|
|
47
|
+
/** Providers whose work is a Colab GPU job, and therefore need a GPU class. */
|
|
48
|
+
const GPU_PROVIDERS = ['wan21-i2v', 'comfyui-minimax-h3', 'musetalk', 'echomimic-v2'] as const;
|
|
49
|
+
|
|
50
|
+
/** Presentation overrides as any single layer may declare them: every field optional. */
|
|
51
|
+
export const VideoPresentationOverrideSchema = z.strictObject({
|
|
52
|
+
captionStyle: z.enum(['kinetic', 'off']).optional(),
|
|
53
|
+
brandLabel: z.string().min(1).optional(),
|
|
54
|
+
cta: z.string().min(1).optional(),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/** A layer that declares presentation overrides (format, style or the brief itself). */
|
|
58
|
+
export type VideoPresentationOverride = z.infer<typeof VideoPresentationOverrideSchema>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The authored `brief.yaml`. Strict on purpose: a typo in a field name must fail the run, not be
|
|
62
|
+
* silently dropped. No provider, GPU, credential or output-path key belongs here.
|
|
63
|
+
*/
|
|
64
|
+
export const VideoBriefSchema = z.strictObject({
|
|
65
|
+
title: z.string().min(1),
|
|
66
|
+
audio: z.string().min(1),
|
|
67
|
+
images: z.array(z.string().min(1)).optional(),
|
|
68
|
+
format: z.string().min(1).optional(),
|
|
69
|
+
style: z.string().min(1).optional(),
|
|
70
|
+
description: z.string().min(1).optional(),
|
|
71
|
+
portrait: z.string().min(1).optional(),
|
|
72
|
+
clip: HookWindowSchema.optional(),
|
|
73
|
+
presentation: VideoPresentationOverrideSchema.optional(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/** Parsed {@link VideoBriefSchema} payload. */
|
|
77
|
+
export type VideoBrief = z.infer<typeof VideoBriefSchema>;
|
|
78
|
+
|
|
79
|
+
/** A format preset: the visual mode plus its default reel length and presentation. */
|
|
80
|
+
export const VideoFormatPresetSchema = z.strictObject({
|
|
81
|
+
visualMode: z.enum(['editorial', 'avatar', 'hybrid-pip']),
|
|
82
|
+
durationTargetSec: z.number().positive().optional(),
|
|
83
|
+
presentation: VideoPresentationOverrideSchema.optional(),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/** A style preset: presentation only — the look, never the mode or the runtime. */
|
|
87
|
+
export const VideoStylePresetSchema = z.strictObject({
|
|
88
|
+
presentation: VideoPresentationOverrideSchema.optional(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Runtime settings, from a `runtime_file` or the operator config's `video:` key. Provider choice,
|
|
93
|
+
* fallback policy and GPU class are operator decisions, not portable preset data.
|
|
94
|
+
*/
|
|
95
|
+
export const VideoRuntimeSchema = z.strictObject({
|
|
96
|
+
provider: z.enum(['local-ken-burns', 'wan21-i2v', 'comfyui-minimax-h3', 'musetalk', 'echomimic-v2']).optional(),
|
|
97
|
+
allowEditorialFallback: z.boolean().optional(),
|
|
98
|
+
colab: ColabRequestSchema.optional(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/** Parsed {@link VideoRuntimeSchema} payload. */
|
|
102
|
+
export type VideoRuntime = z.infer<typeof VideoRuntimeSchema>;
|
|
103
|
+
|
|
104
|
+
/** Which layer supplied the runtime settings. */
|
|
105
|
+
export type VideoRuntimeSource = 'runtime_file' | 'config' | 'default';
|
|
106
|
+
|
|
107
|
+
/** Which layer won for each resolved presentation field. */
|
|
108
|
+
export interface PresentationSources {
|
|
109
|
+
captionStyle: 'brief' | 'style' | 'format' | 'builtin';
|
|
110
|
+
brandLabel?: 'brief' | 'style' | 'format';
|
|
111
|
+
cta?: 'brief' | 'style' | 'format';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Everything a caller needs after resolution: the request, the executor envelope and provenance. */
|
|
115
|
+
export interface ResolvedVideoBrief {
|
|
116
|
+
request: ExplicitVideoRequest;
|
|
117
|
+
input: Doc[];
|
|
118
|
+
format: string;
|
|
119
|
+
style: string;
|
|
120
|
+
sources: {
|
|
121
|
+
runtime: VideoRuntimeSource;
|
|
122
|
+
presentation: PresentationSources;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Injection points: the filesystem seam, the process seam and the environment. */
|
|
127
|
+
export interface ResolveVideoBriefOptions {
|
|
128
|
+
fs?: FileSystem;
|
|
129
|
+
runProcess?: RunProcess;
|
|
130
|
+
/** Where the render writes. Defaults to `<brief dir>/output`. */
|
|
131
|
+
outputDir?: string;
|
|
132
|
+
/** Explicit runtime YAML; beats the operator `video:` config. */
|
|
133
|
+
runtimeFile?: string;
|
|
134
|
+
env?: Record<string, string | undefined>;
|
|
135
|
+
/** Preset root override (tests). Defaults to the plugin's own `presets/`. */
|
|
136
|
+
presetsDir?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function describeIssues(error: z.ZodError): string {
|
|
140
|
+
return error.issues.map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`).join('; ');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
144
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
145
|
+
? (value as Record<string, unknown>)
|
|
146
|
+
: null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Read + decode one YAML file through the fs seam, naming the file on every failure. */
|
|
150
|
+
async function readYaml(fs: FileSystem, path: string, label: string): Promise<unknown> {
|
|
151
|
+
let text: string;
|
|
152
|
+
try {
|
|
153
|
+
text = await fs.readFile(path);
|
|
154
|
+
} catch {
|
|
155
|
+
throw new Error(`video-gen: ${label} ${path} is missing or unreadable`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
return Bun.YAML.parse(text);
|
|
159
|
+
} catch {
|
|
160
|
+
throw new Error(`video-gen: ${label} ${path} is not readable YAML`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Throw unless `path` is a readable, non-empty file. */
|
|
165
|
+
async function assertReadableFile(fs: FileSystem, path: string, label: string): Promise<void> {
|
|
166
|
+
try {
|
|
167
|
+
const stat = await fs.stat(path);
|
|
168
|
+
if (stat === null || !stat.isFile() || (await Bun.file(path).slice(0, 1).arrayBuffer()).byteLength === 0) {
|
|
169
|
+
throw new Error('no readable bytes');
|
|
170
|
+
}
|
|
171
|
+
} catch {
|
|
172
|
+
throw new Error(`video-gen: ${label} ${path} is missing or unreadable`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Refuse a preset name that is not one portable path segment. */
|
|
177
|
+
function assertPresetName(name: string, kind: 'format' | 'style', shipped: readonly string[]): void {
|
|
178
|
+
if (!PRESET_NAME_PATTERN.test(name)) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`video-gen: "${name}" is not a valid preset name for a ${kind} (lowercase letters, digits and dashes)`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
if (!shipped.includes(name)) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`video-gen: unknown ${kind} preset "${name}" (shipped: ${[...shipped].sort().join(', ')}; add a preset file to use another)`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Load one shipped preset file by name; the name check runs before any read. */
|
|
191
|
+
async function readPreset(
|
|
192
|
+
fs: FileSystem,
|
|
193
|
+
presetsDir: string,
|
|
194
|
+
kind: 'format' | 'style',
|
|
195
|
+
name: string,
|
|
196
|
+
): Promise<unknown> {
|
|
197
|
+
const path = join(presetsDir, `${kind}s`, `${name}.yaml`);
|
|
198
|
+
return readYaml(fs, path, `shipped ${kind} preset`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Load a shipped format preset by name. */
|
|
202
|
+
export async function findShippedFormat(
|
|
203
|
+
name: string,
|
|
204
|
+
presetsDir = join(DEFAULT_PLUGIN_ROOT, 'presets'),
|
|
205
|
+
fs: FileSystem = nodeFileSystem,
|
|
206
|
+
): Promise<z.infer<typeof VideoFormatPresetSchema>> {
|
|
207
|
+
assertPresetName(name, 'format', SHIPPED_FORMATS);
|
|
208
|
+
const parsed = VideoFormatPresetSchema.safeParse(await readPreset(fs, presetsDir, 'format', name));
|
|
209
|
+
if (!parsed.success) {
|
|
210
|
+
throw new Error(`video-gen: shipped format preset "${name}" is invalid: ${describeIssues(parsed.error)}`);
|
|
211
|
+
}
|
|
212
|
+
return parsed.data;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Load a shipped style preset by name. */
|
|
216
|
+
export async function findShippedStyle(
|
|
217
|
+
name: string,
|
|
218
|
+
presetsDir = join(DEFAULT_PLUGIN_ROOT, 'presets'),
|
|
219
|
+
fs: FileSystem = nodeFileSystem,
|
|
220
|
+
): Promise<z.infer<typeof VideoStylePresetSchema>> {
|
|
221
|
+
assertPresetName(name, 'style', SHIPPED_STYLES);
|
|
222
|
+
const parsed = VideoStylePresetSchema.safeParse(await readPreset(fs, presetsDir, 'style', name));
|
|
223
|
+
if (!parsed.success) {
|
|
224
|
+
throw new Error(`video-gen: shipped style preset "${name}" is invalid: ${describeIssues(parsed.error)}`);
|
|
225
|
+
}
|
|
226
|
+
return parsed.data;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Resolve one presentation field across the layers (brief wins over style over format over builtin). */
|
|
230
|
+
function resolvePresentationField<K extends 'captionStyle' | 'brandLabel' | 'cta'>(
|
|
231
|
+
key: K,
|
|
232
|
+
layers: {
|
|
233
|
+
brief?: VideoPresentationOverride;
|
|
234
|
+
style?: VideoPresentationOverride;
|
|
235
|
+
format?: VideoPresentationOverride;
|
|
236
|
+
},
|
|
237
|
+
): { value: VideoPresentationOverride[K] | undefined; source: PresentationSources[K] | undefined } {
|
|
238
|
+
if (layers.brief?.[key] !== undefined) return { value: layers.brief[key], source: 'brief' };
|
|
239
|
+
if (layers.style?.[key] !== undefined) return { value: layers.style[key], source: 'style' };
|
|
240
|
+
if (layers.format?.[key] !== undefined) return { value: layers.format[key], source: 'format' };
|
|
241
|
+
return { value: undefined, source: undefined };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Merge presentation with the documented precedence and record which layer won each field, so an
|
|
246
|
+
* operator can see why a CTA or a brand label appeared without re-reading three files.
|
|
247
|
+
*/
|
|
248
|
+
export function mergePresentation(layers: {
|
|
249
|
+
brief?: VideoPresentationOverride;
|
|
250
|
+
style?: VideoPresentationOverride;
|
|
251
|
+
format?: VideoPresentationOverride;
|
|
252
|
+
}): { presentation: z.infer<typeof VideoPresentationSchema>; sources: PresentationSources } {
|
|
253
|
+
const captionStyle = resolvePresentationField('captionStyle', layers);
|
|
254
|
+
const brandLabel = resolvePresentationField('brandLabel', layers);
|
|
255
|
+
const cta = resolvePresentationField('cta', layers);
|
|
256
|
+
const presentation = VideoPresentationSchema.parse({
|
|
257
|
+
// Built-in: kinetic captions, the shell's own default; `cta` falls through to PODCAST_CTA.
|
|
258
|
+
captionStyle: captionStyle.value ?? 'kinetic',
|
|
259
|
+
...(brandLabel.value === undefined ? {} : { brandLabel: brandLabel.value }),
|
|
260
|
+
...(cta.value === undefined ? {} : { cta: cta.value }),
|
|
261
|
+
});
|
|
262
|
+
return {
|
|
263
|
+
presentation,
|
|
264
|
+
sources: {
|
|
265
|
+
captionStyle: captionStyle.source ?? 'builtin',
|
|
266
|
+
...(brandLabel.source === undefined ? {} : { brandLabel: brandLabel.source }),
|
|
267
|
+
...(cta.source === undefined ? {} : { cta: cta.source }),
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** The operator config path: `KK_CONFIG`, else `~/.config/kk/config.yaml` (ADR-042). */
|
|
273
|
+
function resolveConfigPath(env: Record<string, string | undefined>): string {
|
|
274
|
+
const configured = env.KK_CONFIG;
|
|
275
|
+
if (typeof configured === 'string' && configured.trim() !== '') return resolve(configured.trim());
|
|
276
|
+
const home = env.HOME ?? '';
|
|
277
|
+
return join(home, '.config', 'kk', 'config.yaml');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Read and validate runtime settings from one source; a missing file is `null`, not an error. */
|
|
281
|
+
async function readRuntimeLayer(fs: FileSystem, path: string, label: string): Promise<VideoRuntime | null> {
|
|
282
|
+
if (!(await fs.exists(path))) return null;
|
|
283
|
+
const parsed = VideoRuntimeSchema.safeParse(await readYaml(fs, path, label));
|
|
284
|
+
if (!parsed.success) {
|
|
285
|
+
throw new Error(`video-gen: invalid video runtime ${path}: ${describeIssues(parsed.error)}`);
|
|
286
|
+
}
|
|
287
|
+
return parsed.data;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Resolve the runtime layer: explicit `runtime_file` > the operator config's `video:` key > defaults.
|
|
292
|
+
* A runtime file always wins whole — merging objects across layers would make the effective GPU
|
|
293
|
+
* class depend on a file the operator did not edit.
|
|
294
|
+
*/
|
|
295
|
+
async function resolveRuntime(
|
|
296
|
+
fs: FileSystem,
|
|
297
|
+
env: Record<string, string | undefined>,
|
|
298
|
+
runtimeFile: string | undefined,
|
|
299
|
+
): Promise<{ runtime: VideoRuntime; source: VideoRuntimeSource }> {
|
|
300
|
+
if (runtimeFile !== undefined) {
|
|
301
|
+
const runtime = await readRuntimeLayer(fs, resolve(runtimeFile), 'video runtime');
|
|
302
|
+
if (runtime === null) throw new Error(`video-gen: video runtime ${runtimeFile} is missing or unreadable`);
|
|
303
|
+
return { runtime, source: 'runtime_file' };
|
|
304
|
+
}
|
|
305
|
+
const configPath = resolveConfigPath(env);
|
|
306
|
+
if (await fs.exists(configPath)) {
|
|
307
|
+
const document = asRecord(await readYaml(fs, configPath, 'video config'));
|
|
308
|
+
const section = document?.video;
|
|
309
|
+
if (section !== undefined) {
|
|
310
|
+
const parsed = VideoRuntimeSchema.safeParse(section);
|
|
311
|
+
if (!parsed.success) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
`video-gen: invalid video config (video:) in ${configPath}: ${describeIssues(parsed.error)}`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
return { runtime: parsed.data, source: 'config' };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return { runtime: {}, source: 'default' };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Refuse a provider/mode/GPU combination before any GPU allocation: avatar and PiP need a named
|
|
324
|
+
* presenter provider, and every GPU provider needs an explicit GPU class.
|
|
325
|
+
*/
|
|
326
|
+
function assertRuntimeForMode(mode: ExplicitVideoRequest['visualMode'], runtime: VideoRuntime): void {
|
|
327
|
+
const provider = runtime.provider;
|
|
328
|
+
if (mode !== 'editorial') {
|
|
329
|
+
if (provider === undefined) {
|
|
330
|
+
throw new Error(
|
|
331
|
+
`video-gen: format "${mode}" needs a named GPU provider in the video runtime (${AVATAR_PROVIDERS.join(' or ')})`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (!(AVATAR_PROVIDERS as readonly string[]).includes(provider)) {
|
|
335
|
+
throw new Error(
|
|
336
|
+
`video-gen: format "${mode}" needs a presenter provider (${AVATAR_PROVIDERS.join(', ')}), got "${provider}"`,
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (provider !== undefined && (GPU_PROVIDERS as readonly string[]).includes(provider)) {
|
|
341
|
+
if (runtime.colab?.gpu === undefined) {
|
|
342
|
+
throw new Error(
|
|
343
|
+
`video-gen: provider "${provider}" runs on Colab and needs colab.gpu (T4, L4 or A100) in the video runtime`,
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Validate a brief clip against the probed source length (the renderer would otherwise fail late). */
|
|
350
|
+
async function resolveClip(
|
|
351
|
+
clip: { startSec: number; endSec: number } | undefined,
|
|
352
|
+
audioPath: string,
|
|
353
|
+
runProcess: RunProcess,
|
|
354
|
+
): Promise<{ startSec: number; endSec: number } | undefined> {
|
|
355
|
+
if (clip === undefined) return undefined;
|
|
356
|
+
// `HookWindowSchema` already forces non-negative bounds; the ordering and the source bound are
|
|
357
|
+
// what a brief can still get wrong.
|
|
358
|
+
if (!Number.isFinite(clip.endSec) || clip.endSec <= clip.startSec) {
|
|
359
|
+
throw new Error(
|
|
360
|
+
`video-gen: brief clip must end after it starts (start ${clip.startSec}s, end ${clip.endSec}s)`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
const durationSec = await probeAudioDuration(audioPath, runProcess);
|
|
364
|
+
if (clip.endSec > durationSec) {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`video-gen: brief clip ends at ${clip.endSec}s but the brief audio is only ${durationSec.toFixed(1)}s`,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
return { startSec: clip.startSec, endSec: clip.endSec };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Resolve a brief file into the request `kk executor run video-gen` consumes.
|
|
374
|
+
*
|
|
375
|
+
* Order is the fail-closed contract for R2: brief → presets → media readability → mode/provider/GPU
|
|
376
|
+
* policy → clip bounds. Nothing here touches a renderer or a GPU, and the caller's next step is
|
|
377
|
+
* either the executor or a diagnostic.
|
|
378
|
+
*/
|
|
379
|
+
export async function resolveVideoBrief(
|
|
380
|
+
briefPath: string,
|
|
381
|
+
options: ResolveVideoBriefOptions = {},
|
|
382
|
+
): Promise<ResolvedVideoBrief> {
|
|
383
|
+
const fs = options.fs ?? nodeFileSystem;
|
|
384
|
+
const runProcess = options.runProcess ?? runtimeRunProcess;
|
|
385
|
+
const env = options.env ?? process.env;
|
|
386
|
+
const presetRoot = options.presetsDir ?? join(DEFAULT_PLUGIN_ROOT, 'presets');
|
|
387
|
+
const absoluteBrief = resolve(briefPath);
|
|
388
|
+
const briefDir = dirname(absoluteBrief);
|
|
389
|
+
|
|
390
|
+
const parsed = VideoBriefSchema.safeParse(await readYaml(fs, absoluteBrief, 'brief'));
|
|
391
|
+
if (!parsed.success) {
|
|
392
|
+
throw new Error(`video-gen: invalid brief ${absoluteBrief}: ${describeIssues(parsed.error)}`);
|
|
393
|
+
}
|
|
394
|
+
const brief = parsed.data;
|
|
395
|
+
|
|
396
|
+
const formatName = brief.format ?? DEFAULT_VIDEO_FORMAT;
|
|
397
|
+
const styleName = brief.style ?? DEFAULT_VIDEO_STYLE;
|
|
398
|
+
const format = await findShippedFormat(formatName, presetRoot, fs);
|
|
399
|
+
const style = await findShippedStyle(styleName, presetRoot, fs);
|
|
400
|
+
const { presentation, sources: presentationSources } = mergePresentation({
|
|
401
|
+
format: format.presentation,
|
|
402
|
+
style: style.presentation,
|
|
403
|
+
brief: brief.presentation,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Media: brief-relative, absolute on output, readable before anything else happens.
|
|
407
|
+
const absolute = (path: string): string => (isAbsolute(path) ? path : resolve(briefDir, path));
|
|
408
|
+
const audioPath = absolute(brief.audio);
|
|
409
|
+
const imagePaths = (brief.images ?? []).map(absolute);
|
|
410
|
+
const portraitPath = brief.portrait === undefined ? undefined : absolute(brief.portrait);
|
|
411
|
+
|
|
412
|
+
await assertReadableFile(fs, audioPath, 'brief audio');
|
|
413
|
+
for (const [position, imagePath] of imagePaths.entries()) {
|
|
414
|
+
await assertReadableFile(fs, imagePath, `brief image ${position + 1}`);
|
|
415
|
+
}
|
|
416
|
+
if (portraitPath !== undefined) await assertReadableFile(fs, portraitPath, 'brief portrait');
|
|
417
|
+
|
|
418
|
+
// Mode requirements: a still for anything that composites slides, a portrait for a presenter.
|
|
419
|
+
if (format.visualMode !== 'avatar' && imagePaths.length === 0) {
|
|
420
|
+
throw new Error(
|
|
421
|
+
`video-gen: format "${formatName}" needs at least one image (avatar is the only format with a presenter-only frame)`,
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
if (format.visualMode !== 'editorial' && portraitPath === undefined) {
|
|
425
|
+
throw new Error(`video-gen: format "${formatName}" needs a portrait (the operator's own or consented image)`);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const { runtime, source: runtimeSource } = await resolveRuntime(fs, env, options.runtimeFile);
|
|
429
|
+
assertRuntimeForMode(format.visualMode, runtime);
|
|
430
|
+
const hook = await resolveClip(brief.clip, audioPath, runProcess);
|
|
431
|
+
|
|
432
|
+
const outputDir = options.outputDir === undefined ? join(briefDir, 'output') : resolve(options.outputDir);
|
|
433
|
+
const request = parseExplicitVideoRequest(
|
|
434
|
+
{
|
|
435
|
+
inputKind: 'explicit',
|
|
436
|
+
title: brief.title,
|
|
437
|
+
...(brief.description === undefined ? {} : { description: brief.description }),
|
|
438
|
+
audioPath,
|
|
439
|
+
imagePaths,
|
|
440
|
+
...(portraitPath === undefined ? {} : { hostPortraitPath: portraitPath }),
|
|
441
|
+
outputDir,
|
|
442
|
+
visualMode: format.visualMode,
|
|
443
|
+
durationTargetSec: format.durationTargetSec ?? DEFAULT_DURATION_TARGET_SEC,
|
|
444
|
+
...(hook === undefined ? {} : { hook }),
|
|
445
|
+
presentation,
|
|
446
|
+
...(runtime.provider === undefined ? {} : { provider: runtime.provider }),
|
|
447
|
+
// Explicit, not implied: a standalone brief propagates editorial GPU failures unless
|
|
448
|
+
// the runtime asked for the fallback.
|
|
449
|
+
allowEditorialFallback: runtime.allowEditorialFallback === true,
|
|
450
|
+
...(runtime.colab === undefined ? {} : { colab: runtime.colab }),
|
|
451
|
+
},
|
|
452
|
+
briefDir,
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
return {
|
|
456
|
+
request,
|
|
457
|
+
// The executor validates a generator's `--in` against the kind contract, so the request
|
|
458
|
+
// rides in the first Doc's metadata (ADR-009) — the same envelope the daily stage writes.
|
|
459
|
+
input: [{ id: 'video-gen-request', body: '', metadata: request }],
|
|
460
|
+
format: formatName,
|
|
461
|
+
style: styleName,
|
|
462
|
+
sources: { runtime: runtimeSource, presentation: presentationSources },
|
|
463
|
+
};
|
|
464
|
+
}
|