@joplo-app/server 0.6.2 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/asset-usage.d.ts +48 -0
  2. package/dist/asset-usage.js +174 -0
  3. package/dist/audio-timing.d.ts +14 -0
  4. package/dist/audio-timing.js +66 -0
  5. package/dist/build.js +15 -2
  6. package/dist/capture.d.ts +15 -0
  7. package/dist/capture.js +49 -0
  8. package/dist/checkpoint.d.ts +10 -0
  9. package/dist/checkpoint.js +75 -0
  10. package/dist/contract.d.ts +63 -1
  11. package/dist/dev.d.ts +1 -0
  12. package/dist/dev.js +15 -7
  13. package/dist/export.d.ts +6 -0
  14. package/dist/export.js +5 -2
  15. package/dist/film.d.ts +12 -1
  16. package/dist/film.js +231 -25
  17. package/dist/index.d.ts +7 -1
  18. package/dist/index.js +5 -1
  19. package/dist/layout-audit-browser.js +114 -0
  20. package/dist/layout-audit.d.ts +94 -0
  21. package/dist/layout-audit.js +86 -0
  22. package/dist/local-resources.d.ts +5 -0
  23. package/dist/local-resources.js +32 -6
  24. package/dist/media-check.d.ts +7 -1
  25. package/dist/media-check.js +44 -3
  26. package/dist/output-file.d.ts +3 -0
  27. package/dist/output-file.js +23 -0
  28. package/dist/project.d.ts +5 -1
  29. package/dist/project.js +20 -4
  30. package/dist/render.d.ts +2 -0
  31. package/dist/render.js +24 -10
  32. package/dist/resources-run.d.ts +1 -0
  33. package/dist/resources-run.js +23 -2
  34. package/dist/timeline.d.ts +76 -0
  35. package/dist/timeline.js +143 -0
  36. package/dist/video-format.d.ts +2 -0
  37. package/dist/video-format.js +12 -0
  38. package/dist/vite-shared.d.ts +1 -1
  39. package/dist/vite-shared.js +2 -2
  40. package/dist/voice-http.d.ts +1 -0
  41. package/dist/voice-http.js +8 -2
  42. package/dist/voice-run.d.ts +17 -1
  43. package/dist/voice-run.js +71 -9
  44. package/dist/voice.d.ts +1 -0
  45. package/dist/voice.js +10 -2
  46. package/dist/watch-config.d.ts +3 -0
  47. package/dist/watch-config.js +10 -0
  48. package/package.json +4 -4
package/dist/voice-run.js CHANGED
@@ -1,22 +1,60 @@
1
- import { localizeProject, speakerRoleAt, spokenLine } from '@joplo-app/core';
1
+ import { JoploError, localizeProject, speakerRoleAt, spokenLine, spokenChars } from '@joplo-app/core';
2
2
  import { joploHome } from "./home.js";
3
3
  import { ProfileStore, UNSUPPORTED_MESSAGE, VoiceCache, VoiceError, estimateVoice, resolveVoices, voiceLocaleOf } from "./voice.js";
4
4
  /** 选定方案的全部场景里,每一步要读的段(文字为空的跳过)。 */
5
- export function projectSegments(project) {
5
+ export function voiceScenarioIds(project, scope = {}) {
6
+ const { workId, scenarioId } = scope;
7
+ if (workId && (!project.works[workId] || project.works[workId].draft))
8
+ throw new JoploError('USAGE', `Unknown or draft work: ${workId}`);
9
+ if (scenarioId && (!project.scenarios[scenarioId] || project.works[project.scenarios[scenarioId].workId]?.draft))
10
+ throw new JoploError('USAGE', `Unknown or draft scenario: ${scenarioId}`);
11
+ if (workId && scenarioId && project.scenarios[scenarioId]?.workId !== workId)
12
+ throw new JoploError('USAGE', `Scenario ${scenarioId} does not belong to work ${workId}`);
6
13
  const picked = new Set(Object.values(project.works).filter(w => !w.draft && (!w.featureId || project.features[w.featureId]?.pick === w.id)).map(w => w.id));
14
+ const ids = new Set(Object.values(project.scenarios).filter(sc => scenarioId ? sc.id === scenarioId : workId ? sc.workId === workId : picked.has(sc.workId)).map(sc => sc.id));
15
+ // Continuing chapters depend on their predecessors, even when selecting one chapter.
16
+ for (const id of ids) {
17
+ const from = project.scenarios[id]?.from;
18
+ if (from && project.scenarios[from] && !project.works[project.scenarios[from].workId]?.draft)
19
+ ids.add(from);
20
+ }
21
+ return ids;
22
+ }
23
+ export function projectSegments(project, scope = {}) {
24
+ const ids = voiceScenarioIds(project, scope);
7
25
  const out = [];
8
26
  for (const sc of Object.values(project.scenarios)) {
9
- if (!picked.has(sc.workId))
27
+ if (!ids.has(sc.id))
10
28
  continue;
11
29
  sc.steps.forEach((st, i) => {
12
30
  const line = spokenLine(st, st.caption, speakerRoleAt(project, sc.id, i + 1));
13
31
  if (line.text)
14
- out.push({ stepId: st.id, text: line.text, role: line.role });
32
+ out.push({ stepId: st.id, ...line });
15
33
  });
16
34
  }
17
35
  return out;
18
36
  }
19
37
  export async function generateProjectVoice(opts) {
38
+ voiceScenarioIds(opts.project, opts);
39
+ const supplied = projectSegments(opts.project, opts);
40
+ if (supplied.length && supplied.every(s => s.audio)) {
41
+ const declared = opts.project.i18n?.locales ?? [];
42
+ if ((opts.locales ?? []).some(l => !declared.includes(l)))
43
+ throw new VoiceError('INVALID', 'Unknown content language');
44
+ const locales = opts.project.i18n ? opts.locales?.length ? opts.locales : declared : [null];
45
+ const rows = locales.map(locale => {
46
+ const p = locale ? localizeProject(opts.project, locale) : opts.project;
47
+ const segments = projectSegments(p, opts);
48
+ const selected = voiceScenarioIds(p, opts), byId = new Map(segments.map(seg => [seg.stepId, seg]));
49
+ const details = Object.values(p.scenarios).filter(sc => selected.has(sc.id)).flatMap(sc => sc.steps.map(st => {
50
+ const seg = byId.get(st.id);
51
+ return { workId: sc.workId, scenarioId: sc.id, stepId: st.id, text: seg?.text ?? '', chars: 0, missing: !!seg?.audio && !p.mediaAssets?.[seg.audio.slice(15)], estimatedBillableChars: 0, ...(seg?.audio ? { audio: 'provided' } : {}) };
52
+ }));
53
+ const failed = details.filter(d => d.missing).map(d => ({ stepId: d.stepId, message: 'Explicit audio resource is not prepared; no voice provider was called' }));
54
+ return { locale, details, segments: segments.length, missing: 0, chars: 0, generated: 0, skipped: segments.length - failed.length, failed };
55
+ });
56
+ return { profile: { id: 'provided', name: 'Existing audio', kind: 'provided' }, source: null, dryRun: !!opts.dryRun, locales: rows, total: { segments: rows.reduce((n, r) => n + r.segments, 0), missing: 0, chars: 0, generated: 0, failed: rows.reduce((n, r) => n + r.failed.length, 0) }, quota: null, usageUrl: null, exhausted: null };
57
+ }
20
58
  const status = opts.cloud ? await opts.cloud.status().catch(() => null) : null;
21
59
  const live = status?.signedIn && status.voice ? status.voice : null;
22
60
  const store = new ProfileStore(opts.home ?? joploHome(), process.env, { catalog: () => live });
@@ -52,12 +90,35 @@ export async function generateProjectVoice(opts) {
52
90
  const locales = project.i18n ? (opts.locales?.length ? opts.locales : declared) : [null];
53
91
  let quota = live?.quota ? { ...live.quota } : null;
54
92
  const result = { profile: { id: base.profile.id, name: base.profile.name, kind: base.profile.kind }, source: base.source, dryRun: !!opts.dryRun, locales: [], total: { segments: 0, missing: 0, chars: 0, generated: 0, failed: 0 }, quota, usageUrl, exhausted: null };
93
+ let billableFailed = 0;
55
94
  for (const locale of locales) {
56
95
  const p = locale ? localizeProject(project, locale) : project;
57
96
  const resolved = resolveVoices(project.voiceConfig, selected, store, voiceLocaleOf(project, locale), fallback, cache.pins(), cache.officialCloud());
58
- const segments = projectSegments(p);
97
+ const segments = projectSegments(p, opts);
59
98
  const est = estimateVoice(segments, resolved, cache);
60
- const row = { locale, segments: segments.length, missing: est.steps, chars: est.chars, generated: 0, skipped: 0, failed: [] };
99
+ const seen = new Set();
100
+ const segmentById = new Map(segments.map(s => [s.stepId, s]));
101
+ const selectedIds = voiceScenarioIds(p, opts);
102
+ const details = [];
103
+ for (const sc of Object.values(p.scenarios))
104
+ for (const st of sc.steps) {
105
+ if (!selectedIds.has(sc.id))
106
+ continue;
107
+ const seg = segmentById.get(st.id);
108
+ if (!seg) {
109
+ details.push({ workId: sc.workId, scenarioId: sc.id, stepId: st.id, text: '', chars: 0, missing: false, estimatedBillableChars: 0 });
110
+ continue;
111
+ }
112
+ const planned = cache.plan(seg, resolved);
113
+ const missing = seg.audio ? !p.mediaAssets?.[seg.audio.slice(15)] : !!planned && !cache.clipOf(planned.key);
114
+ const estimatedBillableChars = missing && planned && !seen.has(planned.key) ? spokenChars(planned.text) : 0;
115
+ if (planned)
116
+ seen.add(planned.key);
117
+ details.push({ workId: sc.workId, scenarioId: sc.id, stepId: st.id, text: seg.text, chars: seg.audio ? 0 : spokenChars(seg.text), missing, estimatedBillableChars, ...(seg.audio ? { audio: 'provided' } : {}) });
118
+ }
119
+ const providedFailed = details.filter(d => d.audio === 'provided' && d.missing).map(d => ({ stepId: d.stepId, message: 'Explicit audio resource is not prepared; no voice provider was called' }));
120
+ const row = { details, locale, segments: segments.length, missing: est.steps, chars: est.chars, generated: 0, skipped: 0, failed: providedFailed };
121
+ result.total.failed += providedFailed.length;
61
122
  result.locales.push(row);
62
123
  result.total.segments += segments.length;
63
124
  result.total.missing += est.steps;
@@ -65,7 +126,7 @@ export async function generateProjectVoice(opts) {
65
126
  if (opts.dryRun || !est.steps || result.exhausted)
66
127
  continue;
67
128
  opts.onProgress?.(`Generating ${est.steps} clip(s)${locale ? ` for ${locale}` : ''} with ${base.profile.name} (about ${est.chars} characters)...`);
68
- const summary = await cache.generate(segments, locale ?? 'en', resolved, store, {
129
+ const summary = await cache.generate(segments, locale ?? 'und', resolved, store, {
69
130
  cloud: opts.cloud,
70
131
  fetch: opts.fetch,
71
132
  project: project.name,
@@ -77,7 +138,8 @@ export async function generateProjectVoice(opts) {
77
138
  });
78
139
  row.generated = summary.generated;
79
140
  row.skipped = summary.skipped;
80
- row.failed = summary.failed;
141
+ row.failed.push(...summary.failed);
142
+ billableFailed += summary.failed.length;
81
143
  result.total.generated += summary.generated;
82
144
  result.total.failed += summary.failed.length;
83
145
  if (summary.quota) {
@@ -89,7 +151,7 @@ export async function generateProjectVoice(opts) {
89
151
  throw new VoiceError(summary.error.code, summary.error.message);
90
152
  }
91
153
  if (result.exhausted)
92
- result.exhausted.remainingSteps = result.total.missing - result.total.generated - result.total.failed;
154
+ result.exhausted.remainingSteps = Math.max(0, result.total.missing - result.total.generated - billableFailed);
93
155
  result.quota = quota;
94
156
  return result;
95
157
  }
package/dist/voice.d.ts CHANGED
@@ -257,6 +257,7 @@ export type Segment = {
257
257
  stepId: string;
258
258
  text: string;
259
259
  role: string | null;
260
+ audio?: string;
260
261
  };
261
262
  export type GenerateSummary = {
262
263
  total: number;
package/dist/voice.js CHANGED
@@ -639,6 +639,8 @@ export class VoiceCache {
639
639
  }
640
640
  /** 这一段的键与要用的音色;文字为空或没有供应商时为 null。 */
641
641
  plan(seg, resolved) {
642
+ if (seg.audio)
643
+ return null;
642
644
  const p = resolved.profile;
643
645
  const text = seg.text.replace(/\s+/g, ' ').trim();
644
646
  if (!p || !text)
@@ -672,6 +674,8 @@ export class VoiceCache {
672
674
  * inflight:同一个项目共用的“正在生成”表(片段键 → 结果)。批量生成与边放边生成传同一张表,同一段同时只请求一次,后来的等先来的结果(generated 为 false)。
673
675
  */
674
676
  async generateOne(seg, locale, resolved, store, opts = {}) {
677
+ if (seg.audio)
678
+ throw new VoiceError('INVALID', 'This line supplies existing audio; it must never call a voice provider');
675
679
  const p = resolved.profile;
676
680
  const j = this.plan(seg, resolved);
677
681
  if (!p || !j)
@@ -810,6 +814,8 @@ export async function reuseSharedVoice(projectDir, project, shared, store, devCo
810
814
  if (st.captionAuto && !st.say && !st.narrate)
811
815
  continue;
812
816
  const line = spokenLine(st, st.caption, speakerRoleAt(p, sc.id, i + 1));
817
+ if (line.audio)
818
+ continue;
813
819
  const fp = voiceFingerprint(voices, line.role, line.text);
814
820
  if (!fp || !line.text)
815
821
  continue;
@@ -827,7 +833,7 @@ export async function reuseSharedVoice(projectDir, project, shared, store, devCo
827
833
  continue;
828
834
  const file = rel.replace(/^voice\//, '');
829
835
  const bytes = await shared.fetch(rel).catch(() => null);
830
- if (bytes && cache.adopt(key, file, bytes, { stepId: st.id, fp, text, locale: locale ?? 'en', origin: 'shared' }))
836
+ if (bytes && cache.adopt(key, file, bytes, { stepId: st.id, fp, text, locale: locale ?? project.i18n?.default ?? 'und', origin: 'shared' }))
831
837
  reused++;
832
838
  }
833
839
  return reused;
@@ -868,6 +874,8 @@ export function bundleVoice(projectDir, project, outDir, store, devConfig, fallb
868
874
  for (const sc of Object.values(p.scenarios))
869
875
  sc.steps.forEach((st, i) => {
870
876
  const line = spokenLine(st, st.caption, speakerRoleAt(p, sc.id, i + 1));
877
+ if (line.audio)
878
+ return;
871
879
  const primary = voiceFingerprint(voices, line.role);
872
880
  if (!primary || !line.text)
873
881
  return;
@@ -883,7 +891,7 @@ export function bundleVoice(projectDir, project, outDir, store, devConfig, fallb
883
891
  .filter(([key, c]) => {
884
892
  if (c.stepId !== st.id || (locale && c.locale !== locale) || typeof c.text !== 'string')
885
893
  return false;
886
- const expected = automaticCaption(st.captionAuto, c.locale);
894
+ const expected = c.locale === 'und' ? st.caption : automaticCaption(st.captionAuto, c.locale);
887
895
  // 先证明文字仍属于当前内容,再考虑来源优先级;未知语言、旧文字或错配缓存键均不能发布。
888
896
  return expected !== null && c.text.replace(/\s+/g, ' ').trim() === expected.replace(/\s+/g, ' ').trim()
889
897
  && key === clipKey(c.fp, expected) && !!cache.clipOf(key);
@@ -0,0 +1,3 @@
1
+ import type { Diagnostic } from '@joplo-app/core';
2
+ /** Dev-service policy, deliberately outside the playback/compiler model. */
3
+ export declare function watchConfigDiagnostics(value: unknown, at?: string): Diagnostic[];
@@ -0,0 +1,10 @@
1
+ /** Dev-service policy, deliberately outside the playback/compiler model. */
2
+ export function watchConfigDiagnostics(value, at = 'joplo.config.ts:1:1') {
3
+ if (value === undefined)
4
+ return [];
5
+ const w = value;
6
+ if (!w || typeof w !== 'object' || Array.isArray(w) || Object.keys(w).some(k => k !== 'ignore') ||
7
+ (w.ignore !== undefined && (!Array.isArray(w.ignore) || w.ignore.some(p => typeof p !== 'string' || !p || /[\\:*?\[\]{}\x00]/.test(p) || p.startsWith('/') || p.split('/').some(s => !s || s === '.' || s === '..') || /^joplo\.config\.tsx?$/.test(p)))))
8
+ return [{ code: 'WATCH_CONFIG_INVALID', severity: 'error', source: 'schema', at, message: 'watch.ignore must contain project-relative file or directory paths (no globs, dot segments, or joplo.config.ts); restart dev after changing it' }];
9
+ return [];
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joplo-app/server",
3
- "version": "0.6.2",
3
+ "version": "0.7.2",
4
4
  "description": "Joplo 作品本地服务:dev 看板、build 静态发布站、render 截图,服务链接与嵌入交付",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "type": "module",
@@ -15,9 +15,9 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@joplo-app/core": "0.6.2",
19
- "@joplo-app/kit": "0.6.2",
20
- "@joplo-app/web": "0.6.2",
18
+ "@joplo-app/core": "0.7.2",
19
+ "@joplo-app/kit": "0.7.2",
20
+ "@joplo-app/web": "0.7.2",
21
21
  "@tailwindcss/vite": "4.3.4",
22
22
  "mediabunny": "1.65.2",
23
23
  "tailwindcss": "4.3.4",