@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
|
@@ -3,6 +3,7 @@ import { parseArgs } from 'node:util';
|
|
|
3
3
|
import { type Content, ContentSchema, type Doc, DocListSchema } from '@gobing-ai/kk-core';
|
|
4
4
|
import { createNodeFileSystem, type FileSystem } from '@gobing-ai/ts-runtime';
|
|
5
5
|
import { echoError } from '@gobing-ai/ts-utils';
|
|
6
|
+
import { analyzeEditorialClaims, type EditorialFinding } from './editorial-claims';
|
|
6
7
|
import { buildNewsVoiceScript, formatVoiceScriptToYaml, type ScriptBuilderOptions } from './script-builder';
|
|
7
8
|
import {
|
|
8
9
|
parseStyleContract,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
validateScriptPlan,
|
|
13
14
|
} from './script-plan';
|
|
14
15
|
|
|
16
|
+
export * from './editorial-claims';
|
|
15
17
|
export * from './script-builder';
|
|
16
18
|
export * from './script-plan';
|
|
17
19
|
|
|
@@ -25,6 +27,8 @@ interface ScriptPlanOutcome {
|
|
|
25
27
|
scriptPlan?: ScriptPlan;
|
|
26
28
|
scriptSource: 'plan' | 'template';
|
|
27
29
|
scriptPlanErrors: ScriptPlanError[];
|
|
30
|
+
/** 0385 AC R2/R3 advisory findings — reported, never a rejection (see `editorial-claims.ts`). */
|
|
31
|
+
scriptPlanAdvisories: EditorialFinding[];
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/**
|
|
@@ -37,12 +41,12 @@ interface ScriptPlanOutcome {
|
|
|
37
41
|
async function resolveScriptPlan(fs: FileSystem, docs: Doc[]): Promise<ScriptPlanOutcome> {
|
|
38
42
|
const planPath = process.env.DAILYNEWS_SCRIPT_PLAN;
|
|
39
43
|
if (!planPath) {
|
|
40
|
-
return { scriptSource: 'template', scriptPlanErrors: [] };
|
|
44
|
+
return { scriptSource: 'template', scriptPlanErrors: [], scriptPlanAdvisories: [] };
|
|
41
45
|
}
|
|
42
46
|
const fallback = (errors: ScriptPlanError[]): ScriptPlanOutcome => {
|
|
43
47
|
const reason = errors.map((error) => `${error.itemId}:${error.rule}`).join(', ');
|
|
44
48
|
echoError(`dailynews-gen: script plan rejected, falling back to templates (${reason})`);
|
|
45
|
-
return { scriptSource: 'template', scriptPlanErrors: errors };
|
|
49
|
+
return { scriptSource: 'template', scriptPlanErrors: errors, scriptPlanAdvisories: [] };
|
|
46
50
|
};
|
|
47
51
|
if (!(await fs.exists(planPath))) {
|
|
48
52
|
return fallback([{ itemId: 'episode', rule: 'missing-plan' }]);
|
|
@@ -85,7 +89,17 @@ async function resolveScriptPlan(fs: FileSystem, docs: Doc[]): Promise<ScriptPla
|
|
|
85
89
|
if (!validated.ok) {
|
|
86
90
|
return fallback(validated.errors);
|
|
87
91
|
}
|
|
88
|
-
|
|
92
|
+
// 0385 AC R2/R3: the editorial findings ride alongside an ACCEPTED plan. They are stamped, not
|
|
93
|
+
// turned into rejections — a plan that validates today must keep validating.
|
|
94
|
+
const advisories = analyzeEditorialClaims(validated.plan);
|
|
95
|
+
if (advisories.length > 0) {
|
|
96
|
+
echoError(
|
|
97
|
+
`dailynews-gen: script plan accepted with ${advisories.length} advisory finding(s) (${advisories
|
|
98
|
+
.map((finding) => `${finding.itemId}:${finding.code}`)
|
|
99
|
+
.join(', ')})`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return { scriptPlan: validated.plan, scriptSource: 'plan', scriptPlanErrors: [], scriptPlanAdvisories: advisories };
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
/**
|
|
@@ -148,7 +162,11 @@ export async function processGeneratorIO(
|
|
|
148
162
|
const isZh = (options?.language || 'zh').toLowerCase() === 'zh';
|
|
149
163
|
const planOutcome = isZh
|
|
150
164
|
? await resolveScriptPlan(fs, docs)
|
|
151
|
-
: {
|
|
165
|
+
: {
|
|
166
|
+
scriptSource: 'template' as const,
|
|
167
|
+
scriptPlanErrors: [] as ScriptPlanError[],
|
|
168
|
+
scriptPlanAdvisories: [] as EditorialFinding[],
|
|
169
|
+
};
|
|
152
170
|
// Topic boundary (task 0189): docs the plan declares excluded are not spoken, not counted,
|
|
153
171
|
// and not referenced — title, storyCount, and references must match what is actually said.
|
|
154
172
|
const excludedIds = new Set(planOutcome.scriptPlan?.excluded?.map((ex) => ex.id) ?? []);
|
|
@@ -183,6 +201,7 @@ export async function processGeneratorIO(
|
|
|
183
201
|
})),
|
|
184
202
|
scriptSource: planOutcome.scriptSource,
|
|
185
203
|
scriptPlanErrors: planOutcome.scriptPlanErrors,
|
|
204
|
+
scriptPlanAdvisories: planOutcome.scriptPlanAdvisories,
|
|
186
205
|
},
|
|
187
206
|
};
|
|
188
207
|
|
|
@@ -428,9 +428,16 @@ export function buildNewsVoiceScript(docs: Doc[], options?: ScriptBuilderOptions
|
|
|
428
428
|
|
|
429
429
|
const normalizedLead = normalizeBroadcastText(lead, isZh);
|
|
430
430
|
const normalizedBody = cleanBody === '' ? '' : normalizeBroadcastText(cleanBody, isZh);
|
|
431
|
-
// F613: the plan insight is
|
|
432
|
-
//
|
|
433
|
-
|
|
431
|
+
// F613: the plan insight is spoken when it carries comment; 0385 R3 makes it optional, so a
|
|
432
|
+
// plan item with a blank insight speaks the item's facts and no comment sentence (never a
|
|
433
|
+
// bare 「。」 segment), and the keyword-bucket synthesizer only runs on the template path.
|
|
434
|
+
const plannedInsight = planItem?.insight?.trim() ?? '';
|
|
435
|
+
const insight =
|
|
436
|
+
planItem !== undefined
|
|
437
|
+
? plannedInsight === ''
|
|
438
|
+
? null
|
|
439
|
+
: plannedInsight
|
|
440
|
+
: synthesizePersonalUnderstanding(cleanTitle, cleanBody, isZh, usedInsights);
|
|
434
441
|
const normalizedInsight = insight === null ? null : normalizeBroadcastText(insight, isZh);
|
|
435
442
|
|
|
436
443
|
const factText = isZh ? `${normalizedLead}${normalizedBody}` : `${normalizedLead} ${normalizedBody}`;
|
|
@@ -23,11 +23,33 @@ export interface ScriptPlanSocial {
|
|
|
23
23
|
long: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The cover slot has two legal forms (0347 R4, widened by 0385 R4):
|
|
28
|
+
* - a plain string = the English visual scene (the pre-0347 shape), unchanged;
|
|
29
|
+
* - an object = `{ scene?, headline, sourceIds? }`, where `headline` is the Chinese 当日要点 the
|
|
30
|
+
* episode identity freezes (0385 R4) and `sourceIds` names the plan items the point rests on,
|
|
31
|
+
* so admission dropping them can withhold the point instead of publishing it unsupported.
|
|
32
|
+
*/
|
|
33
|
+
export interface ScriptPlanCoverObject {
|
|
34
|
+
/** English visual scene for image generation (≤ `caps.cover`); optional so a point-only cover validates. */
|
|
35
|
+
scene?: string;
|
|
36
|
+
/** The frozen 当日要点 — the one point the title and the cover share (≤ `caps.coverHeadline`). */
|
|
37
|
+
headline: string;
|
|
38
|
+
/** Plan item ids the headline rests on; withheld when admission drops every one of them. */
|
|
39
|
+
sourceIds?: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ScriptPlanCover = string | ScriptPlanCoverObject;
|
|
43
|
+
|
|
26
44
|
export interface ScriptPlan {
|
|
27
45
|
version: 1;
|
|
28
46
|
intro: string;
|
|
29
47
|
outro: string;
|
|
30
|
-
|
|
48
|
+
/**
|
|
49
|
+
* `insight` is optional (0385 R3): a comment-free item is legal, and an empty string means the
|
|
50
|
+
* same thing as omission — the builder skips the insight sentence, never the item.
|
|
51
|
+
*/
|
|
52
|
+
items: { id: string; lead: string; insight?: string; card?: ScriptPlanItemCard }[];
|
|
31
53
|
/**
|
|
32
54
|
* Docs deliberately not spoken (topic-boundary exclusions, task 0189). An id here is
|
|
33
55
|
* exempt from `missing-item`; listing an id in both `items` and `excluded` is a
|
|
@@ -35,7 +57,7 @@ export interface ScriptPlan {
|
|
|
35
57
|
*/
|
|
36
58
|
excluded?: { id: string; reason: string }[];
|
|
37
59
|
/** Optional master-artifact fields rendered deterministically by `daily-editorial-render` (0345 R10). */
|
|
38
|
-
cover?:
|
|
60
|
+
cover?: ScriptPlanCover;
|
|
39
61
|
cards?: ScriptPlanCards;
|
|
40
62
|
social?: ScriptPlanSocial;
|
|
41
63
|
}
|
|
@@ -51,6 +73,7 @@ export interface StyleContract {
|
|
|
51
73
|
lead: number;
|
|
52
74
|
insight: number;
|
|
53
75
|
cover?: number;
|
|
76
|
+
coverHeadline?: number;
|
|
54
77
|
cardCopy?: number;
|
|
55
78
|
cardTitle?: number;
|
|
56
79
|
socialShort?: number;
|
|
@@ -74,16 +97,29 @@ const ScriptPlanItemCardSchema = z.object({
|
|
|
74
97
|
});
|
|
75
98
|
|
|
76
99
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
100
|
+
* `insight` is optional (0385 R3): the contract lets an item carry no comment, so omitting it — or
|
|
101
|
+
* sending `""` — must validate. A blank insight is skipped by the builder (no bare 「。」 segment)
|
|
102
|
+
* and by the editorial render (the item still renders, only the comment sentence is dropped).
|
|
79
103
|
*/
|
|
80
104
|
const ScriptPlanItemSchema = z.object({
|
|
81
105
|
id: z.string().min(1),
|
|
82
106
|
lead: z.string().min(1),
|
|
83
|
-
insight: z.string().
|
|
107
|
+
insight: z.string().optional(),
|
|
84
108
|
card: ScriptPlanItemCardSchema.optional(),
|
|
85
109
|
});
|
|
86
110
|
|
|
111
|
+
/**
|
|
112
|
+
* 0385 R4: the object form is what carries the episode's 当日要点, so the schema has to accept it —
|
|
113
|
+
* a string-only cover made the canonical `第<issue>期 · <headline>` title unreachable.
|
|
114
|
+
*/
|
|
115
|
+
const ScriptPlanCoverObjectSchema = z.object({
|
|
116
|
+
scene: z.string().min(1).optional(),
|
|
117
|
+
headline: z.string().min(1),
|
|
118
|
+
sourceIds: z.array(z.string().min(1)).optional(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const ScriptPlanCoverSchema = z.union([z.string().min(1), ScriptPlanCoverObjectSchema]);
|
|
122
|
+
|
|
87
123
|
const ScriptPlanExclusionSchema = z.object({
|
|
88
124
|
id: z.string().min(1),
|
|
89
125
|
reason: z.string().min(1),
|
|
@@ -105,7 +141,7 @@ const ScriptPlanSchema = z.object({
|
|
|
105
141
|
outro: z.string().min(1),
|
|
106
142
|
items: z.array(ScriptPlanItemSchema),
|
|
107
143
|
excluded: z.array(ScriptPlanExclusionSchema).optional(),
|
|
108
|
-
cover:
|
|
144
|
+
cover: ScriptPlanCoverSchema.optional(),
|
|
109
145
|
cards: ScriptPlanCardsSchema.optional(),
|
|
110
146
|
social: ScriptPlanSocialSchema.optional(),
|
|
111
147
|
});
|
|
@@ -117,6 +153,7 @@ const StyleContractSchema = z.object({
|
|
|
117
153
|
lead: z.number().int().positive(),
|
|
118
154
|
insight: z.number().int().positive(),
|
|
119
155
|
cover: z.number().int().positive().optional(),
|
|
156
|
+
coverHeadline: z.number().int().positive().optional(),
|
|
120
157
|
cardCopy: z.number().int().positive().optional(),
|
|
121
158
|
cardTitle: z.number().int().positive().optional(),
|
|
122
159
|
socialShort: z.number().int().positive().optional(),
|
|
@@ -217,8 +254,17 @@ export function validateScriptPlan(
|
|
|
217
254
|
|
|
218
255
|
if (valid.intro.length > style.caps.intro) errors.push({ itemId: 'episode', rule: 'cap:intro' });
|
|
219
256
|
if (valid.outro.length > style.caps.outro) errors.push({ itemId: 'episode', rule: 'cap:outro' });
|
|
220
|
-
|
|
221
|
-
|
|
257
|
+
// 0385 R4: both cover forms are capped. The string form is one scene (the pre-0347 shape); the
|
|
258
|
+
// object form caps its scene at the same place and its 当日要点 at the (much tighter) headline cap.
|
|
259
|
+
if (typeof valid.cover === 'string') {
|
|
260
|
+
if (valid.cover.length > (style.caps.cover ?? 240)) errors.push({ itemId: 'episode', rule: 'cap:cover' });
|
|
261
|
+
} else if (valid.cover !== undefined) {
|
|
262
|
+
if (valid.cover.scene !== undefined && valid.cover.scene.length > (style.caps.cover ?? 240)) {
|
|
263
|
+
errors.push({ itemId: 'episode', rule: 'cap:cover' });
|
|
264
|
+
}
|
|
265
|
+
if (valid.cover.headline.length > (style.caps.coverHeadline ?? 25)) {
|
|
266
|
+
errors.push({ itemId: 'episode', rule: 'cap:coverHeadline' });
|
|
267
|
+
}
|
|
222
268
|
}
|
|
223
269
|
if (valid.cards !== undefined && valid.cards.title.length > (style.caps.cardTitle ?? 20)) {
|
|
224
270
|
errors.push({ itemId: 'episode', rule: 'cap:cardTitle' });
|
|
@@ -233,7 +279,10 @@ export function validateScriptPlan(
|
|
|
233
279
|
}
|
|
234
280
|
for (const item of valid.items) {
|
|
235
281
|
if (item.lead.length > style.caps.lead) errors.push({ itemId: item.id, rule: 'cap:lead' });
|
|
236
|
-
|
|
282
|
+
// 0385 R3: an omitted/blank insight is legal (the item still renders), so it has no cap,
|
|
283
|
+
// no banned-phrase and no duplicate rule to break.
|
|
284
|
+
const insight = item.insight?.trim() ?? '';
|
|
285
|
+
if (insight.length > style.caps.insight) errors.push({ itemId: item.id, rule: 'cap:insight' });
|
|
237
286
|
if (item.card !== undefined && item.card.copy.length > (style.caps.cardCopy ?? 12)) {
|
|
238
287
|
errors.push({ itemId: item.id, rule: 'cap:cardCopy' });
|
|
239
288
|
}
|
|
@@ -241,7 +290,8 @@ export function validateScriptPlan(
|
|
|
241
290
|
// unknown-id is already reported above; skip the redundancy check rather than double-report.
|
|
242
291
|
if (
|
|
243
292
|
doc !== undefined &&
|
|
244
|
-
|
|
293
|
+
insight !== '' &&
|
|
294
|
+
redundantInsightClauses(insight, `${item.lead}${doc.body}`) >= REDUNDANT_INSIGHT_CLAUSE_LIMIT
|
|
245
295
|
) {
|
|
246
296
|
errors.push({ itemId: item.id, rule: 'redundant-insight' });
|
|
247
297
|
}
|
|
@@ -250,7 +300,14 @@ export function validateScriptPlan(
|
|
|
250
300
|
const fields: { itemId: string; text: string }[] = [
|
|
251
301
|
{ itemId: 'episode', text: valid.intro },
|
|
252
302
|
{ itemId: 'episode', text: valid.outro },
|
|
253
|
-
...(valid.cover
|
|
303
|
+
...(typeof valid.cover === 'string'
|
|
304
|
+
? [{ itemId: 'episode', text: valid.cover }]
|
|
305
|
+
: valid.cover !== undefined
|
|
306
|
+
? [
|
|
307
|
+
{ itemId: 'episode', text: valid.cover.headline },
|
|
308
|
+
...(valid.cover.scene !== undefined ? [{ itemId: 'episode', text: valid.cover.scene }] : []),
|
|
309
|
+
]
|
|
310
|
+
: []),
|
|
254
311
|
...(valid.cards !== undefined
|
|
255
312
|
? [
|
|
256
313
|
{ itemId: 'episode', text: valid.cards.title },
|
|
@@ -265,7 +322,7 @@ export function validateScriptPlan(
|
|
|
265
322
|
: []),
|
|
266
323
|
...valid.items.flatMap((item) => [
|
|
267
324
|
{ itemId: item.id, text: item.lead },
|
|
268
|
-
{ itemId: item.id, text: item.insight },
|
|
325
|
+
...((item.insight?.trim() ?? '') !== '' ? [{ itemId: item.id, text: item.insight as string }] : []),
|
|
269
326
|
...(item.card !== undefined
|
|
270
327
|
? [
|
|
271
328
|
{ itemId: item.id, text: item.card.copy },
|
|
@@ -280,10 +337,13 @@ export function validateScriptPlan(
|
|
|
280
337
|
}
|
|
281
338
|
}
|
|
282
339
|
|
|
340
|
+
// Two comment-free items are not "the same insight" — only real comment text can collide.
|
|
283
341
|
const seenInsights = new Set<string>();
|
|
284
342
|
for (const item of valid.items) {
|
|
285
|
-
|
|
286
|
-
|
|
343
|
+
const insight = item.insight?.trim() ?? '';
|
|
344
|
+
if (insight === '') continue;
|
|
345
|
+
if (seenInsights.has(insight)) errors.push({ itemId: item.id, rule: 'duplicate-insight' });
|
|
346
|
+
else seenInsights.add(insight);
|
|
287
347
|
}
|
|
288
348
|
|
|
289
349
|
return errors.length > 0 ? { ok: false, errors } : { ok: true, plan: valid };
|
|
@@ -12672,6 +12672,19 @@ async function auditVoiceSegments(script, segmentWavs, segmentMetadata, client)
|
|
|
12672
12672
|
}
|
|
12673
12673
|
|
|
12674
12674
|
// ../../plugins/generations/voice-gen/src/voicebox-client.ts
|
|
12675
|
+
init_dist();
|
|
12676
|
+
var GPU_BACKENDS = new Set(["gpu", "mps", "metal", "cuda"]);
|
|
12677
|
+
function detectCpuFallback(payload) {
|
|
12678
|
+
if (payload.gpu_available !== true)
|
|
12679
|
+
return;
|
|
12680
|
+
const variant = (payload.backend_variant ?? "").toLowerCase();
|
|
12681
|
+
if (!variant || GPU_BACKENDS.has(variant))
|
|
12682
|
+
return;
|
|
12683
|
+
return payload;
|
|
12684
|
+
}
|
|
12685
|
+
function requireGpu(env) {
|
|
12686
|
+
return ["1", "true", "yes"].includes((env.VOICEBOX_REQUIRE_GPU ?? "").toLowerCase());
|
|
12687
|
+
}
|
|
12675
12688
|
function resolveVoiceboxTimeoutMs() {
|
|
12676
12689
|
const raw = process.env.VOICEBOX_TIMEOUT_MS;
|
|
12677
12690
|
const parsed = raw ? Number.parseInt(raw, 10) : Number.NaN;
|
|
@@ -12686,8 +12699,9 @@ function createVoiceboxClient(options = {}) {
|
|
|
12686
12699
|
return {
|
|
12687
12700
|
url,
|
|
12688
12701
|
async health() {
|
|
12702
|
+
let res;
|
|
12689
12703
|
try {
|
|
12690
|
-
|
|
12704
|
+
res = await customFetch(`${url}/health`, { signal: AbortSignal.timeout(requestTimeoutMs) });
|
|
12691
12705
|
if (!res.ok) {
|
|
12692
12706
|
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
12693
12707
|
}
|
|
@@ -12695,6 +12709,21 @@ function createVoiceboxClient(options = {}) {
|
|
|
12695
12709
|
const reason = err instanceof Error ? err.message : String(err);
|
|
12696
12710
|
throw new Error(`Voicebox health check failed at ${url}: ${reason} \u2014 is Voicebox.app running with its REST server enabled? (restart the app or fix VOICEBOX_URL)`);
|
|
12697
12711
|
}
|
|
12712
|
+
let payload;
|
|
12713
|
+
try {
|
|
12714
|
+
payload = await res.json();
|
|
12715
|
+
} catch {
|
|
12716
|
+
payload = undefined;
|
|
12717
|
+
}
|
|
12718
|
+
const fallback = payload && detectCpuFallback(payload);
|
|
12719
|
+
if (fallback) {
|
|
12720
|
+
const detail = `backend_variant: "${fallback.backend_variant}", gpu_available: true, gpu_type: "${fallback.gpu_type ?? "unknown"}"`;
|
|
12721
|
+
const message = `Voicebox at ${url} is rendering on CPU (${detail}) \u2014 expect ~5.6x realtime degradation. Restart Voicebox.app while Metal is free, or set VOICEBOX_REQUIRE_GPU=0 to accept it.`;
|
|
12722
|
+
if (requireGpu(process.env)) {
|
|
12723
|
+
throw new Error(`voice-gen: ${message}`);
|
|
12724
|
+
}
|
|
12725
|
+
echoError(`voice-gen: warning: ${message}`);
|
|
12726
|
+
}
|
|
12698
12727
|
},
|
|
12699
12728
|
async resolveProfile(nameOrId) {
|
|
12700
12729
|
let res;
|
|
@@ -13514,6 +13543,7 @@ var DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com";
|
|
|
13514
13543
|
var DEFAULT_PROFILES_PATH = new URL("../profiles.json", import.meta.url).pathname;
|
|
13515
13544
|
var TRANSCRIBE_PROMPT = "Transcribe this audio verbatim. Output only the transcript, no commentary.";
|
|
13516
13545
|
var RETRY_AFTER_CAP_SEC = 120;
|
|
13546
|
+
var TERMINAL_STATUSES = new Set([400, 401, 402, 403, 404]);
|
|
13517
13547
|
var PLACEHOLDER_VOICE = "voice_REPLACE_ME";
|
|
13518
13548
|
function findOutput(json, type) {
|
|
13519
13549
|
for (const step of json.steps ?? []) {
|
|
@@ -13548,29 +13578,36 @@ function createGeminiVoiceClient(options = {}) {
|
|
|
13548
13578
|
const styleOverride = env.GEMINI_TTS_STYLE;
|
|
13549
13579
|
const maxAttempts = positiveInt(env.GEMINI_TTS_MAX_ATTEMPTS, 4);
|
|
13550
13580
|
const timeoutMs = positiveInt(env.GEMINI_TTS_TIMEOUT_MS, 120000);
|
|
13581
|
+
const segmentTimeoutMs = positiveInt(env.GEMINI_TTS_SEGMENT_TIMEOUT_MS, 180000);
|
|
13551
13582
|
const buffered = new Map;
|
|
13552
13583
|
let profiles;
|
|
13553
13584
|
let seq = 0;
|
|
13554
13585
|
async function post(body, label) {
|
|
13555
13586
|
const apiKey = env.GEMINI_API_KEY ?? "";
|
|
13587
|
+
const deadline = Date.now() + segmentTimeoutMs;
|
|
13556
13588
|
for (let attempt = 1;; attempt++) {
|
|
13589
|
+
const remaining = deadline - Date.now();
|
|
13590
|
+
if (remaining <= 0) {
|
|
13591
|
+
throw new Error(`${label}: segment budget ${segmentTimeoutMs}ms exhausted after ${attempt - 1} attempt(s)`);
|
|
13592
|
+
}
|
|
13593
|
+
const attemptMs = Math.min(timeoutMs, remaining);
|
|
13557
13594
|
let res;
|
|
13558
13595
|
try {
|
|
13559
13596
|
res = await withDeadline(doFetch(`${baseUrl}/v1beta/interactions`, {
|
|
13560
13597
|
method: "POST",
|
|
13561
13598
|
headers: { "content-type": "application/json", "x-goog-api-key": apiKey },
|
|
13562
13599
|
body: JSON.stringify(body),
|
|
13563
|
-
signal: AbortSignal.timeout(
|
|
13564
|
-
}),
|
|
13600
|
+
signal: AbortSignal.timeout(attemptMs)
|
|
13601
|
+
}), attemptMs);
|
|
13565
13602
|
} catch (err) {
|
|
13566
13603
|
const msg = err instanceof Error ? err.message : String(err);
|
|
13567
|
-
if (attempt >= maxAttempts)
|
|
13568
|
-
throw new Error(`${label}: request failed after ${attempt}
|
|
13569
|
-
await sleep(2000 * 2 ** (attempt - 1));
|
|
13604
|
+
if (attempt >= maxAttempts || Date.now() >= deadline)
|
|
13605
|
+
throw new Error(`${label}: request failed after ${attempt} attempt(s) within ${segmentTimeoutMs}ms: ${msg}`);
|
|
13606
|
+
await sleep(Math.min(2000 * 2 ** (attempt - 1), Math.max(0, deadline - Date.now())));
|
|
13570
13607
|
continue;
|
|
13571
13608
|
}
|
|
13572
13609
|
if (res.ok)
|
|
13573
|
-
return withDeadline(res.json(), timeoutMs);
|
|
13610
|
+
return withDeadline(res.json(), Math.min(timeoutMs, Math.max(1, deadline - Date.now())));
|
|
13574
13611
|
const raw = await withDeadline(res.text(), timeoutMs);
|
|
13575
13612
|
let apiMessage = raw.slice(0, 300);
|
|
13576
13613
|
try {
|
|
@@ -13580,6 +13617,9 @@ function createGeminiVoiceClient(options = {}) {
|
|
|
13580
13617
|
if (retryAfter > RETRY_AFTER_CAP_SEC) {
|
|
13581
13618
|
throw new Error(`${label}: HTTP ${res.status} quota/reset horizon too far out (retry-after ${retryAfter}s \u2248 ${(retryAfter / 3600).toFixed(1)}h): ${apiMessage}`);
|
|
13582
13619
|
}
|
|
13620
|
+
if (TERMINAL_STATUSES.has(res.status)) {
|
|
13621
|
+
throw new Error(`${label}: HTTP ${res.status} is not retryable (auth/billing/request class) \u2014 failing fast instead of burning the segment budget: ${apiMessage}`);
|
|
13622
|
+
}
|
|
13583
13623
|
const retryable = res.status === 429 || res.status >= 500;
|
|
13584
13624
|
if (!retryable || attempt >= maxAttempts) {
|
|
13585
13625
|
throw new Error(`${label}: HTTP ${res.status} after ${attempt} attempt(s): ${apiMessage}`);
|
|
@@ -8,6 +8,12 @@ const DEFAULT_PROFILES_PATH = new URL('../profiles.json', import.meta.url).pathn
|
|
|
8
8
|
const TRANSCRIBE_PROMPT = 'Transcribe this audio verbatim. Output only the transcript, no commentary.';
|
|
9
9
|
/** retry-after above this (Google daily-quota 429s: ~70_000s) is never actionable inside a run. */
|
|
10
10
|
const RETRY_AFTER_CAP_SEC = 120;
|
|
11
|
+
/**
|
|
12
|
+
* 4xx that retrying can never fix: auth, billing (2026-11-20: a depleted project answered 402 on
|
|
13
|
+
* every call) and malformed requests. Retried, they burn the whole per-segment budget for a
|
|
14
|
+
* certain failure, which is how one episode spent 23 minutes failing over.
|
|
15
|
+
*/
|
|
16
|
+
const TERMINAL_STATUSES = new Set([400, 401, 402, 403, 404]);
|
|
11
17
|
const PLACEHOLDER_VOICE = 'voice_REPLACE_ME';
|
|
12
18
|
|
|
13
19
|
type Env = Record<string, string | undefined>;
|
|
@@ -78,13 +84,24 @@ export function createGeminiVoiceClient(options: GeminiVoiceClientOptions = {}):
|
|
|
78
84
|
const styleOverride = env.GEMINI_TTS_STYLE;
|
|
79
85
|
const maxAttempts = positiveInt(env.GEMINI_TTS_MAX_ATTEMPTS, 4);
|
|
80
86
|
const timeoutMs = positiveInt(env.GEMINI_TTS_TIMEOUT_MS, 120_000);
|
|
87
|
+
// Wall-clock ceiling for ONE segment across every attempt and backoff, so a stalled endpoint
|
|
88
|
+
// cannot multiply the per-request timeout by the attempt count (R1).
|
|
89
|
+
const segmentTimeoutMs = positiveInt(env.GEMINI_TTS_SEGMENT_TIMEOUT_MS, 180_000);
|
|
81
90
|
const buffered = new Map<string, Uint8Array>();
|
|
82
91
|
let profiles: Record<string, { voice?: string }> | undefined;
|
|
83
92
|
let seq = 0;
|
|
84
93
|
|
|
85
94
|
async function post(body: unknown, label: string): Promise<InteractionResponse> {
|
|
86
95
|
const apiKey = env.GEMINI_API_KEY ?? '';
|
|
96
|
+
const deadline = Date.now() + segmentTimeoutMs;
|
|
87
97
|
for (let attempt = 1; ; attempt++) {
|
|
98
|
+
const remaining = deadline - Date.now();
|
|
99
|
+
if (remaining <= 0) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`${label}: segment budget ${segmentTimeoutMs}ms exhausted after ${attempt - 1} attempt(s)`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const attemptMs = Math.min(timeoutMs, remaining);
|
|
88
105
|
let res: Response;
|
|
89
106
|
try {
|
|
90
107
|
res = await withDeadline(
|
|
@@ -92,18 +109,24 @@ export function createGeminiVoiceClient(options: GeminiVoiceClientOptions = {}):
|
|
|
92
109
|
method: 'POST',
|
|
93
110
|
headers: { 'content-type': 'application/json', 'x-goog-api-key': apiKey },
|
|
94
111
|
body: JSON.stringify(body),
|
|
95
|
-
signal: AbortSignal.timeout(
|
|
112
|
+
signal: AbortSignal.timeout(attemptMs),
|
|
96
113
|
}),
|
|
97
|
-
|
|
114
|
+
attemptMs,
|
|
98
115
|
);
|
|
99
116
|
} catch (err: unknown) {
|
|
100
117
|
const msg = err instanceof Error ? err.message : String(err);
|
|
101
|
-
if (attempt >= maxAttempts)
|
|
102
|
-
throw new Error(
|
|
103
|
-
|
|
118
|
+
if (attempt >= maxAttempts || Date.now() >= deadline)
|
|
119
|
+
throw new Error(
|
|
120
|
+
`${label}: request failed after ${attempt} attempt(s) within ${segmentTimeoutMs}ms: ${msg}`,
|
|
121
|
+
);
|
|
122
|
+
await sleep(Math.min(2000 * 2 ** (attempt - 1), Math.max(0, deadline - Date.now())));
|
|
104
123
|
continue;
|
|
105
124
|
}
|
|
106
|
-
if (res.ok)
|
|
125
|
+
if (res.ok)
|
|
126
|
+
return withDeadline(
|
|
127
|
+
res.json(),
|
|
128
|
+
Math.min(timeoutMs, Math.max(1, deadline - Date.now())),
|
|
129
|
+
) as Promise<InteractionResponse>;
|
|
107
130
|
const raw = await withDeadline(res.text(), timeoutMs);
|
|
108
131
|
let apiMessage = raw.slice(0, 300);
|
|
109
132
|
try {
|
|
@@ -120,6 +143,11 @@ export function createGeminiVoiceClient(options: GeminiVoiceClientOptions = {}):
|
|
|
120
143
|
`${label}: HTTP ${res.status} quota/reset horizon too far out (retry-after ${retryAfter}s ≈ ${(retryAfter / 3600).toFixed(1)}h): ${apiMessage}`,
|
|
121
144
|
);
|
|
122
145
|
}
|
|
146
|
+
if (TERMINAL_STATUSES.has(res.status)) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`${label}: HTTP ${res.status} is not retryable (auth/billing/request class) — failing fast instead of burning the segment budget: ${apiMessage}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
123
151
|
const retryable = res.status === 429 || res.status >= 500;
|
|
124
152
|
if (!retryable || attempt >= maxAttempts) {
|
|
125
153
|
throw new Error(`${label}: HTTP ${res.status} after ${attempt} attempt(s): ${apiMessage}`);
|