@gobing-ai/knowledge-kit 0.1.20 → 0.1.23
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/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1279 -261
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +13938 -8966
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/gemini-tts/dist/index.js +47 -7
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23580 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +951 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/generations/omni-voice-gen/uv.toml +5 -0
- package/plugins/generations/vibe-voice-tts/README.md +64 -0
- package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
- package/plugins/generations/vibe-voice-tts/package.json +16 -0
- package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
- package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
- package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
- package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
- package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
- package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
- package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
- package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
- package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
- package/plugins/generations/voice-gen/dist/index.js +31 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
- package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
- package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
- package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
- package/plugins/generations/voxcpm-tts/uv.toml +5 -0
- package/plugins/kk/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +933 -60
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +332 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
- package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
- package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
- package/plugins/publishings/threads-pub/dist/index.js +58 -6
- package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
- package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
- package/plugins/publishings/weibo-pub/dist/index.js +11 -1
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/dist/index.js +95 -10
- package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type { MusicModel } from './brief';
|
|
3
|
+
import type { ResolvedJob } from './presets';
|
|
4
|
+
import { renderBriefPrompt } from './render';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Digest input (task 0397 Design "Digest input"): the canonical request that
|
|
8
|
+
* 0400 uses as its run-scoped dedupe key and that 0398 records as take
|
|
9
|
+
* provenance.
|
|
10
|
+
*
|
|
11
|
+
* The canonical form is `{model, prompt, lyrics, durationTarget, language,
|
|
12
|
+
* images, takeIndex}` with absent values as `null` (never omitted, so a missing
|
|
13
|
+
* field cannot alias a present one), image *content* hashes in brief order, and
|
|
14
|
+
* `takeIndex` last.
|
|
15
|
+
*
|
|
16
|
+
* `takeIndex` is part of the key on purpose: `takes: N` renders N structurally
|
|
17
|
+
* identical requests, so without it takes 2..N would collide with take 1 and
|
|
18
|
+
* run-scoped dedupe would refuse the run's own takes.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** The canonical digest input. `null` means "absent", never "empty". */
|
|
22
|
+
export interface MusicDigestInput {
|
|
23
|
+
model: MusicModel;
|
|
24
|
+
prompt: string;
|
|
25
|
+
lyrics: string | null;
|
|
26
|
+
durationTarget: string | null;
|
|
27
|
+
language: string;
|
|
28
|
+
/** SHA-256 hex of each reference image, in brief order. */
|
|
29
|
+
images: string[];
|
|
30
|
+
/** 0-based take index within the job. */
|
|
31
|
+
takeIndex: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Options for {@link digestInput}. */
|
|
35
|
+
export interface DigestOptions {
|
|
36
|
+
/** SHA-256 hex of each brief image, in brief order; required when the brief carries images. */
|
|
37
|
+
imageHashes?: string[];
|
|
38
|
+
/** 0-based take index; defaults to 0. */
|
|
39
|
+
takeIndex?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** SHA-256 hex helper: the digest module's single hashing primitive. */
|
|
43
|
+
function createSha256Hex(text: string): string {
|
|
44
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Build the canonical digest input for one take of a resolved job. */
|
|
48
|
+
export function digestInput(job: ResolvedJob, options: DigestOptions = {}): MusicDigestInput {
|
|
49
|
+
const takeIndex = options.takeIndex ?? 0;
|
|
50
|
+
if (!Number.isInteger(takeIndex) || takeIndex < 0) {
|
|
51
|
+
throw new Error(`takeIndex must be a non-negative integer (got ${String(takeIndex)})`);
|
|
52
|
+
}
|
|
53
|
+
const imageHashes = options.imageHashes ?? [];
|
|
54
|
+
if (imageHashes.length !== job.images.length) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`digest needs one content hash per image: ${String(job.images.length)} image(s) in the brief, ${String(imageHashes.length)} hash(es) supplied`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
model: job.model.value,
|
|
61
|
+
prompt: renderBriefPrompt(job),
|
|
62
|
+
lyrics: job.lyrics === undefined ? null : job.lyrics,
|
|
63
|
+
durationTarget: job.model.value === 'pro' ? (job.duration_target.value ?? null) : null,
|
|
64
|
+
language: job.language.value,
|
|
65
|
+
images: [...imageHashes],
|
|
66
|
+
takeIndex,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Canonical JSON: fixed key order, no whitespace, `null` for absent values. */
|
|
71
|
+
export function canonicalDigestJson(input: MusicDigestInput): string {
|
|
72
|
+
return JSON.stringify({
|
|
73
|
+
model: input.model,
|
|
74
|
+
prompt: input.prompt,
|
|
75
|
+
lyrics: input.lyrics,
|
|
76
|
+
durationTarget: input.durationTarget,
|
|
77
|
+
language: input.language,
|
|
78
|
+
images: input.images,
|
|
79
|
+
takeIndex: input.takeIndex,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** SHA-256 hex of the canonical JSON — the value 0400 compares against sidecars. */
|
|
84
|
+
export function canonicalDigestSha256(input: MusicDigestInput): string {
|
|
85
|
+
return createSha256Hex(canonicalDigestJson(input));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Digest input, canonical JSON and hash for one take. */
|
|
89
|
+
export interface TakeDigest {
|
|
90
|
+
input: MusicDigestInput;
|
|
91
|
+
canonicalJson: string;
|
|
92
|
+
sha256: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Compute the full digest bundle for one take of a resolved job. */
|
|
96
|
+
export function takeDigest(job: ResolvedJob, options: DigestOptions = {}): TakeDigest {
|
|
97
|
+
const input = digestInput(job, options);
|
|
98
|
+
const canonicalJson = canonicalDigestJson(input);
|
|
99
|
+
return { input, canonicalJson, sha256: createSha256Hex(canonicalJson) };
|
|
100
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@gobing-ai/music-gen` — the music generator plugin over the self-hosted
|
|
3
|
+
* Lyria 3 instance.
|
|
4
|
+
*
|
|
5
|
+
* The frozen 0397 contract (brief schema, prompt renderer, request mapping,
|
|
6
|
+
* preset resolution, canonical digest) plus 0398's plugin surface (adapter,
|
|
7
|
+
* offline adapter, config, artifact + sidecar, Content mapping and the generator
|
|
8
|
+
* entry). The plugin entry is this file (`plugin.json` `entry: ./src/index.ts`),
|
|
9
|
+
* so `main()` runs only when the module is executed, never when it is imported.
|
|
10
|
+
*
|
|
11
|
+
* Contract authority: `docs/design/music-gen.md`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// ── 0398: plugin surface ────────────────────────────────────────────────────
|
|
15
|
+
export * from './adapter';
|
|
16
|
+
export * from './artifact';
|
|
17
|
+
export * from './audio';
|
|
18
|
+
// ── 0405: measurement, take checks, masters and delivery profiles ───────────
|
|
19
|
+
export * from './audio/checks';
|
|
20
|
+
export * from './audio/master';
|
|
21
|
+
export * from './audio/measure';
|
|
22
|
+
export * from './audio/profile';
|
|
23
|
+
export {
|
|
24
|
+
AUDIO_FORMATS,
|
|
25
|
+
type AudioFormat,
|
|
26
|
+
BRIEF_FIELD_TARGETS,
|
|
27
|
+
type BriefFieldTarget,
|
|
28
|
+
DEFAULT_TAKES,
|
|
29
|
+
durationSeconds,
|
|
30
|
+
formatDuration,
|
|
31
|
+
LANGUAGE_PATTERN,
|
|
32
|
+
MAX_DURATION_SECONDS,
|
|
33
|
+
MAX_IMAGES,
|
|
34
|
+
MAX_TAKES,
|
|
35
|
+
MIN_DURATION_SECONDS,
|
|
36
|
+
MMSS_PATTERN,
|
|
37
|
+
MUSIC_MODELS,
|
|
38
|
+
type MusicBrief,
|
|
39
|
+
MusicBriefSchema,
|
|
40
|
+
type MusicModel,
|
|
41
|
+
parseMusicBrief,
|
|
42
|
+
parseMusicBriefYaml,
|
|
43
|
+
type StructureEntry,
|
|
44
|
+
StructureEntrySchema,
|
|
45
|
+
} from './brief';
|
|
46
|
+
export * from './config';
|
|
47
|
+
export * from './content';
|
|
48
|
+
export {
|
|
49
|
+
canonicalDigestJson,
|
|
50
|
+
canonicalDigestSha256,
|
|
51
|
+
type DigestOptions,
|
|
52
|
+
digestInput,
|
|
53
|
+
type MusicDigestInput,
|
|
54
|
+
type TakeDigest,
|
|
55
|
+
takeDigest,
|
|
56
|
+
} from './digest';
|
|
57
|
+
export * from './job';
|
|
58
|
+
export * from './plugin';
|
|
59
|
+
export {
|
|
60
|
+
assertPresetPortable,
|
|
61
|
+
BUILTIN_DEFAULTS,
|
|
62
|
+
CLIP_STRUCTURE_CEILING_SECONDS,
|
|
63
|
+
explainJob,
|
|
64
|
+
type FieldSource,
|
|
65
|
+
FORBIDDEN_PRESET_KEYS,
|
|
66
|
+
JobResolutionError,
|
|
67
|
+
type LoadedMusicPresets,
|
|
68
|
+
type LoadMusicPresetsOptions,
|
|
69
|
+
loadMusicPresets,
|
|
70
|
+
loadPresetFile,
|
|
71
|
+
MUSIC_PRESET_ROOT,
|
|
72
|
+
type MusicFormatPreset,
|
|
73
|
+
MusicFormatPresetSchema,
|
|
74
|
+
type MusicJobOverrides,
|
|
75
|
+
type MusicPresetProblem,
|
|
76
|
+
type MusicThemePreset,
|
|
77
|
+
MusicThemePresetSchema,
|
|
78
|
+
type NamedPresetOptions,
|
|
79
|
+
PRESET_STATUSES,
|
|
80
|
+
PROVENANCE_DATE_PATTERN,
|
|
81
|
+
PresetContractViolation,
|
|
82
|
+
PresetDataError,
|
|
83
|
+
type PresetLayer,
|
|
84
|
+
type PresetLayers,
|
|
85
|
+
type PresetProvenance,
|
|
86
|
+
PresetProvenanceSchema,
|
|
87
|
+
type PresetStatus,
|
|
88
|
+
parsePresetDocument,
|
|
89
|
+
presetLayerForFormat,
|
|
90
|
+
presetLayerForTheme,
|
|
91
|
+
type ResolvedJob,
|
|
92
|
+
resolveJob,
|
|
93
|
+
resolveNamedJob,
|
|
94
|
+
type Sourced,
|
|
95
|
+
themeDirectionGaps,
|
|
96
|
+
UnknownPresetError,
|
|
97
|
+
} from './presets';
|
|
98
|
+
export {
|
|
99
|
+
AVOID_PREFIX,
|
|
100
|
+
INSTANCE_OWNED_PROMPT_MARKERS,
|
|
101
|
+
INSTRUMENTAL_DIRECTIVE,
|
|
102
|
+
type PromptSegments,
|
|
103
|
+
renderBriefPrompt,
|
|
104
|
+
renderPromptText,
|
|
105
|
+
renderStructureLine,
|
|
106
|
+
} from './render';
|
|
107
|
+
export {
|
|
108
|
+
type MusicGenerateRequest,
|
|
109
|
+
REQUEST_FIELD_ORIGINS,
|
|
110
|
+
REQUEST_KEY_ORDER,
|
|
111
|
+
renderGenerateRequest,
|
|
112
|
+
renderTakeRequests,
|
|
113
|
+
serializeRequest,
|
|
114
|
+
} from './request';
|
|
115
|
+
export {
|
|
116
|
+
type AnalyzeEstimateInput,
|
|
117
|
+
DEFAULT_TAKES_CAP,
|
|
118
|
+
type DedupeDecision,
|
|
119
|
+
type DedupeScanInput,
|
|
120
|
+
enforceRunScopedDedupe,
|
|
121
|
+
estimateAnalyze,
|
|
122
|
+
estimateGenerate,
|
|
123
|
+
findRunDirDuplicates,
|
|
124
|
+
formatEstimate,
|
|
125
|
+
formatUsd,
|
|
126
|
+
type GenerateEstimateInput,
|
|
127
|
+
type GenerationPlan,
|
|
128
|
+
type GenerationPlanInput,
|
|
129
|
+
HARD_TAKES_CAP,
|
|
130
|
+
planGeneration,
|
|
131
|
+
type RunDirDuplicate,
|
|
132
|
+
requireConfirmation,
|
|
133
|
+
resolveTakeCount,
|
|
134
|
+
resolveTakesCap,
|
|
135
|
+
type SpendEmit,
|
|
136
|
+
type SpendEstimate,
|
|
137
|
+
type SpendKind,
|
|
138
|
+
SpendRefusal,
|
|
139
|
+
type SpendRequest,
|
|
140
|
+
type TakeDigestEntry,
|
|
141
|
+
withConfirmation,
|
|
142
|
+
} from './spend';
|
|
143
|
+
|
|
144
|
+
if (import.meta.main) {
|
|
145
|
+
const { main } = await import('./plugin');
|
|
146
|
+
process.exit(await main());
|
|
147
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Doc } from '@gobing-ai/kk-core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { AUDIO_FORMATS, MUSIC_MODELS, type MusicBrief, parseMusicBriefYaml, StructureEntrySchema } from './brief';
|
|
4
|
+
import type { PresetLayer, PresetLayers, ResolvedJob } from './presets';
|
|
5
|
+
import { resolveJob } from './presets';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The `--in` envelope (task 0398 R1/R5).
|
|
9
|
+
*
|
|
10
|
+
* A generator plugin's only input channel is the `--in` JSON (the spawn argv is
|
|
11
|
+
* frozen at `--in`/`--out`), so the brief rides inside one doc and everything
|
|
12
|
+
* the plugin needs besides the brief rides the first doc's `metadata`.
|
|
13
|
+
*
|
|
14
|
+
* - **The brief is `docs[0].body`, parsed as the YAML authoring form** the plugin
|
|
15
|
+
* README documents. One authored document, one schema (`MusicBriefSchema`) —
|
|
16
|
+
* voice-gen's `parseDocToVoiceScript` is the precedent for YAML-in-body.
|
|
17
|
+
* - **`docs[0].metadata.musicGen`** carries only what is not the brief: the
|
|
18
|
+
* preset layers 0399 will load from disk (accepted inline so this task does not
|
|
19
|
+
* depend on 0399's loader), the `outputStem` override, and the `force`/`reason`
|
|
20
|
+
* pair 0400's spend guard records. Strict on purpose: a typo'd key fails loud
|
|
21
|
+
* instead of vanishing into a paid request.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** `metadata` key this plugin owns. */
|
|
25
|
+
export const MUSIC_JOB_METADATA_KEY = 'musicGen';
|
|
26
|
+
|
|
27
|
+
/** One preset layer, as 0399's loader will hand it over. `name` is required so `explainJob` can cite it. */
|
|
28
|
+
export const PresetLayerSchema = z.strictObject({
|
|
29
|
+
name: z.string().min(1),
|
|
30
|
+
model: z.enum(MUSIC_MODELS).optional(),
|
|
31
|
+
duration_target: z.string().min(1).optional(),
|
|
32
|
+
language: z.string().min(1).optional(),
|
|
33
|
+
instrumental: z.boolean().optional(),
|
|
34
|
+
lyrics_policy: z.enum(['allowed', 'forbidden']).optional(),
|
|
35
|
+
audio_format: z.enum(AUDIO_FORMATS).optional(),
|
|
36
|
+
style: z.string().min(1).optional(),
|
|
37
|
+
avoid: z.array(z.string().min(1)).optional(),
|
|
38
|
+
structure: z.array(StructureEntrySchema).optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** The three preset layers in precedence order (`brief > workflow > theme > format`). */
|
|
42
|
+
export const PresetLayersSchema = z.strictObject({
|
|
43
|
+
workflow: PresetLayerSchema.optional(),
|
|
44
|
+
theme: PresetLayerSchema.optional(),
|
|
45
|
+
format: PresetLayerSchema.optional(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
/** The plugin-level knobs that are not the brief. */
|
|
49
|
+
export const MusicJobSpecSchema = z.strictObject({
|
|
50
|
+
presets: PresetLayersSchema.optional(),
|
|
51
|
+
/** Overrides the `--out` basename for artifact naming (image-gen's `outputStem` precedent). */
|
|
52
|
+
outputStem: z.string().min(1).optional(),
|
|
53
|
+
/** True when the operator accepted a paid re-send (0400 records it; 0398 only mirrors it into the sidecar). */
|
|
54
|
+
force: z.boolean().optional(),
|
|
55
|
+
/** Why `force` was passed. Required by 0400's policy; recorded verbatim here. */
|
|
56
|
+
reason: z.string().min(1).optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/** Parsed `metadata.musicGen`. */
|
|
60
|
+
export type MusicJobSpec = z.infer<typeof MusicJobSpecSchema>;
|
|
61
|
+
|
|
62
|
+
/** One resolved job plus the plugin knobs and the brief it came from. */
|
|
63
|
+
export interface MusicJob {
|
|
64
|
+
brief: MusicBrief;
|
|
65
|
+
spec: MusicJobSpec;
|
|
66
|
+
job: ResolvedJob;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Render zod issues as one actionable line. */
|
|
70
|
+
function zodIssues(error: z.ZodError): string {
|
|
71
|
+
return error.issues.map((issue) => `${issue.path.join('.') || 'spec'}: ${issue.message}`).join('; ');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Parse `docs[0].metadata.musicGen`; absent means "brief only, no preset layers". */
|
|
75
|
+
export function parseMusicJobSpec(docs: readonly Doc[]): MusicJobSpec {
|
|
76
|
+
const raw = docs[0]?.metadata?.[MUSIC_JOB_METADATA_KEY];
|
|
77
|
+
if (raw === undefined || raw === null) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
const result = MusicJobSpecSchema.safeParse(raw);
|
|
81
|
+
if (!result.success) {
|
|
82
|
+
throw new Error(`Invalid music job spec at metadata.${MUSIC_JOB_METADATA_KEY}: ${zodIssues(result.error)}`);
|
|
83
|
+
}
|
|
84
|
+
return result.data;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Parse the brief out of `docs[0].body` (the YAML authoring form). */
|
|
88
|
+
export function parseMusicJobBrief(docs: readonly Doc[]): MusicBrief {
|
|
89
|
+
const body = docs[0]?.body ?? '';
|
|
90
|
+
if (body.trim() === '') {
|
|
91
|
+
throw new Error(
|
|
92
|
+
'Invalid music job input: docs[0].body must carry the music brief as YAML (the plugin README authoring form)',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return parseMusicBriefYaml(body);
|
|
97
|
+
} catch (error: unknown) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Invalid music brief in docs[0].body: ${error instanceof Error ? error.message : String(error)}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Cast a parsed preset layer to the resolution layer type (the schemas cover the same fields). */
|
|
105
|
+
function asPresetLayers(spec: MusicJobSpec): PresetLayers {
|
|
106
|
+
const layer = (value: z.infer<typeof PresetLayerSchema> | undefined): PresetLayer | undefined =>
|
|
107
|
+
value === undefined ? undefined : (value as PresetLayer);
|
|
108
|
+
const presets = spec.presets;
|
|
109
|
+
if (presets === undefined) {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
const workflow = layer(presets.workflow);
|
|
113
|
+
const theme = layer(presets.theme);
|
|
114
|
+
const format = layer(presets.format);
|
|
115
|
+
return {
|
|
116
|
+
...(workflow === undefined ? {} : { workflow }),
|
|
117
|
+
...(theme === undefined ? {} : { theme }),
|
|
118
|
+
...(format === undefined ? {} : { format }),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Parse and resolve the whole job: brief from the body, preset layers from
|
|
124
|
+
* metadata, then 0397's `resolveJob`. Every authoring error fails here — before
|
|
125
|
+
* the adapter is built, so before any spend.
|
|
126
|
+
*/
|
|
127
|
+
export function parseMusicJob(docs: readonly Doc[]): MusicJob {
|
|
128
|
+
const brief = parseMusicJobBrief(docs);
|
|
129
|
+
const spec = parseMusicJobSpec(docs);
|
|
130
|
+
return { brief, spec, job: resolveJob(brief, asPresetLayers(spec)) };
|
|
131
|
+
}
|