videobook 0.3.0 → 0.3.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 (61) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/dist/asset-media-projection.js +161 -0
  3. package/dist/command-reference.js +3 -1
  4. package/dist/diagnostics.js +10 -4
  5. package/dist/generation-reference-mentions.js +19 -0
  6. package/dist/goal-plan-v3.js +21 -6
  7. package/dist/goal-plan.js +1 -1
  8. package/dist/goal-store.js +2 -2
  9. package/dist/har-capture.js +36 -3
  10. package/dist/jobs/_image-edit-adapter.js +2 -0
  11. package/dist/jobs/_kie-upload.js +3 -1
  12. package/dist/jobs/assess-media-probes.js +94 -0
  13. package/dist/jobs/complete-provider-task.js +2 -5
  14. package/dist/jobs/generate-media.js +22 -12
  15. package/dist/jobs/image-subjects.js +2 -0
  16. package/dist/jobs/kie-paygate.js +3 -3
  17. package/dist/jobs/register-all.js +2 -0
  18. package/dist/jobs/run-notebook.js +16 -1
  19. package/dist/library-asset-projection.js +141 -0
  20. package/dist/lightning-defaults.js +4 -4
  21. package/dist/media/catalog.js +12 -6
  22. package/dist/media/descriptor.js +16 -7
  23. package/dist/media/frontier-gaps.js +0 -1
  24. package/dist/media/har-endpoint.js +25 -0
  25. package/dist/media/json-schema.js +3 -0
  26. package/dist/media/listing.js +26 -4
  27. package/dist/media/preferred-defaults.js +161 -0
  28. package/dist/media/prompt-dialects.js +9 -1
  29. package/dist/media-library.js +158 -153
  30. package/dist/notebook-sticky-settings.js +60 -0
  31. package/dist/provider-usage.js +24 -9
  32. package/dist/tools/estimate-cost.js +9 -4
  33. package/dist/tools/reconcile-project-work.js +37 -184
  34. package/dist/tools/videobook-domain.js +16 -1
  35. package/dist/usage-providers.js +3 -3
  36. package/package.json +15 -15
  37. package/ui/assets/{alive-captions-Cj8C1tCN.js → alive-captions-BWk_4aX0.js} +1 -1
  38. package/ui/assets/confirm-bodies-CNW9vLsi.js +1 -0
  39. package/ui/assets/{fullscreen-DyEncSdm.js → fullscreen-ND_H86Ih.js} +1 -1
  40. package/ui/assets/{goal-ui-BdFeoSWh.js → goal-ui-CCTD4lxi.js} +1 -1
  41. package/ui/assets/index-CTPstLYq.css +1 -0
  42. package/ui/assets/index-D0ftggO4.js +37 -0
  43. package/ui/assets/inspector-BZnbKsEZ.js +1 -0
  44. package/ui/assets/{jobs-ui-BudI4w0r.js → jobs-ui-BNK0IPSl.js} +1 -1
  45. package/ui/assets/{music-video-CT4C55ok.js → music-video-CoOI0cgW.js} +1 -1
  46. package/ui/assets/{ui-mq0uIS5P.css → ui-BBM3YCY6.css} +1 -1
  47. package/ui/assets/ui-koLWlu0t.js +2 -0
  48. package/ui/assets/vendor-Ca2-b3hB.js +19 -0
  49. package/ui/assets/{vendor-flow-nqTFQmTh.js → vendor-flow-C2NYBYCL.js} +1 -1
  50. package/ui/assets/vendor-icons-D3KrGMJY.js +1 -0
  51. package/ui/assets/{vendor-mcp-D_C3EZPv.js → vendor-mcp-9gUvOX4H.js} +2 -2
  52. package/ui/assets/videobook-B8dYNQrG.js +21 -0
  53. package/ui/index.html +14 -14
  54. package/ui/assets/confirm-bodies-BxWXwDf0.js +0 -1
  55. package/ui/assets/index-DWfR79lA.css +0 -1
  56. package/ui/assets/index-QZ8lbemN.js +0 -37
  57. package/ui/assets/inspector-BC6xWkJU.js +0 -1
  58. package/ui/assets/ui-z5r-p0K9.js +0 -2
  59. package/ui/assets/vendor-D8XcMav4.js +0 -19
  60. package/ui/assets/vendor-icons-CGqhCIXV.js +0 -1
  61. package/ui/assets/videobook-CsW453sb.js +0 -21
@@ -80,8 +80,8 @@ function historicalAverage(warnings) {
80
80
  }
81
81
  async function priceRequest(provider, model, payload, endpoint, hints) {
82
82
  try {
83
- const request = { provider, payload, ...(provider === "fal" ? { endpoint } : {}), ...(hints ? { costHints: hints } : {}) };
84
- const estimate = provider === "fal"
83
+ const request = { provider, payload, ...(endpoint ? { endpoint } : {}), ...(hints ? { costHints: hints } : {}) };
84
+ const estimate = provider === "fal" && endpoint
85
85
  ? await estimateFalRequest(endpoint, payload, hints)
86
86
  : cost.estimate(request);
87
87
  const historical = estimate.usd > 0 && historicalAverage(estimate.warnings);
@@ -92,7 +92,7 @@ async function priceRequest(provider, model, payload, endpoint, hints) {
92
92
  ...unknownPrice(historical ? estimate.warnings : []),
93
93
  costUsd: estimate.usd,
94
94
  basis: estimate.source === "free" ? "free" : "estimated",
95
- rateSource: rateFor(provider, model)?.source.url ?? null,
95
+ rateSource: (rateFor(provider, model) ?? (endpoint ? rateFor(provider, endpoint) : undefined))?.source.url ?? null,
96
96
  pricingVersion: `apicity-${COST_PACKAGE_VERSION}:${estimate.rateAsOf ?? (historical ? "fal-historical" : PRICING_AS_OF)}`,
97
97
  units: estimate.breakdown.units ?? null,
98
98
  unit: estimate.breakdown.unit ?? null,
@@ -102,11 +102,24 @@ async function priceRequest(provider, model, payload, endpoint, hints) {
102
102
  return unknownPrice();
103
103
  }
104
104
  }
105
- function activityFor(model, path, operation = "") {
105
+ const MEDIA_ACTIVITY = { image: "images", video: "video", audio: "audio" };
106
+ function kieSunoApiId(provider, path) {
107
+ const match = provider === "kie" ? /\/api\/v1\/generate(\/sounds)?$/u.exec(path) : null;
108
+ if (!match)
109
+ return undefined;
110
+ return match[1] ? "suno/sounds-generate" : "suno/generate";
111
+ }
112
+ function catalogMedia(provider, model, path) {
113
+ return modelEntry(provider === "fal" ? `fal:${path.slice(1)}` : `${provider}:${kieSunoApiId(provider, path) ?? model}`)?.media;
114
+ }
115
+ function activityFor(provider, model, path, operation = "") {
106
116
  if (/\/(responses|completions)$/u.test(path) && /chat|rewrite_prompt/u.test(operation))
107
117
  return "chat";
108
118
  if (/transcrib|speech.to.text|analy|describe|tag_|rename|suggest|translate|vision|image.subjects|regions|verify/iu.test(`${operation} ${path}`))
109
119
  return "analysis";
120
+ const media = catalogMedia(provider, model, path);
121
+ if (media)
122
+ return MEDIA_ACTIVITY[media];
110
123
  if (/video|veo|wan\/|kling|seedance|happyhorse|lipsync/iu.test(`${model} ${path}`))
111
124
  return "video";
112
125
  if (/audio|speech|music|sound|sfx|suno|vocal/iu.test(`${model} ${path}`))
@@ -121,7 +134,7 @@ function isBillable(provider, path, method) {
121
134
  if (provider === "openai" || provider === "xai")
122
135
  return /\/(responses|chat\/completions|images\/(generations|edits)|videos\/(generations|edits|extensions)|audio\/(speech|transcriptions|translations)|embeddings|tts|stt)$/u.test(path);
123
136
  if (provider === "kie")
124
- return /\/(createTask|veo\/(generate|extend))$/u.test(path);
137
+ return /\/(createTask|veo\/(generate|extend))$/u.test(path) || kieSunoApiId(provider, path) !== undefined;
125
138
  if (provider === "fal")
126
139
  return !/\/requests\//u.test(path)
127
140
  && (/^\/(fal-ai|alibaba)\//u.test(path) || modelEntry(`fal:${path.slice(1)}`) !== undefined);
@@ -169,7 +182,8 @@ function responseStatus(body, accepted) {
169
182
  const data = object(body.data);
170
183
  const output = object(body.output);
171
184
  const state = String(body.status ?? data.state ?? data.status ?? output.task_status ?? "").toLowerCase();
172
- if (body.error || data.failCode || (typeof body.code === "number" && body.code >= 400) || data.successFlag === 2 || ["failed", "fail", "error"].includes(state))
185
+ if (body.error || data.failCode || (typeof body.code === "number" && body.code >= 400) || data.successFlag === 2 || data.successFlag === 3
186
+ || ["failed", "fail", "error", "create_task_failed", "generate_audio_failed", "sensitive_word_error"].includes(state))
173
187
  return "failed";
174
188
  if (["cancelled", "canceled"].includes(state))
175
189
  return "cancelled";
@@ -177,7 +191,8 @@ function responseStatus(body, accepted) {
177
191
  return "uncertain";
178
192
  if (data.successFlag === 1 || ["success", "succeeded", "completed", "done"].includes(state))
179
193
  return "completed";
180
- if (["created", "pending", "queued", "in_queue", "running", "in_progress", "processing", "started", "waiting"].includes(state))
194
+ if (data.successFlag === 0
195
+ || ["created", "pending", "queued", "in_queue", "running", "in_progress", "processing", "started", "waiting", "queuing", "generating", "text_success"].includes(state))
181
196
  return "pending";
182
197
  return accepted ? "pending" : "completed";
183
198
  }
@@ -232,12 +247,12 @@ export function providerUsageFetch(provider, transport = fetch) {
232
247
  catch {
233
248
  void 0;
234
249
  }
235
- const activity = provider === "machgen" ? "video" : activityFor(model, url.pathname, context.operation);
250
+ const activity = provider === "machgen" ? "video" : activityFor(provider, model, url.pathname, context.operation);
236
251
  entry = {
237
252
  id: randomUUID(), provider, model, activity, status: "pending",
238
253
  tokenBased: /\/(responses|completions|embeddings)$/u.test(url.pathname) || rateFor(provider, model)?.kind === "tokens",
239
254
  operation: context.operation ?? null, artifactId: context.artifactId ?? null,
240
- ...await priceRequest(provider, model, payload, endpoint, hints),
255
+ ...await priceRequest(provider, model, payload, provider === "fal" ? endpoint : kieSunoApiId(provider, url.pathname), hints),
241
256
  };
242
257
  safeRecord(engine, entry);
243
258
  }
@@ -51,13 +51,18 @@ async function sourceDuration(engine, refs) {
51
51
  }
52
52
  return undefined;
53
53
  }
54
- async function mediaHints(engine, refs) {
54
+ async function mediaHints(engine, refs, model) {
55
+ const audioSeconds = () => sourceDuration(engine, (refs.audio ?? []).filter((ref) => !ref.startsWith("http")));
56
+ if (model.entry.outputLength === "audio") {
57
+ const seconds = await audioSeconds();
58
+ return seconds === undefined ? {} : { durationSeconds: seconds };
59
+ }
55
60
  const videos = (refs.video ?? []).filter((ref) => !ref.startsWith("http"));
56
61
  const videoSeconds = videos.length > 0 ? await referenceVideoDuration(engine, videos) : undefined;
57
62
  if (videoSeconds !== undefined)
58
63
  return { inputDurationSeconds: videoSeconds };
59
- const audioSeconds = await sourceDuration(engine, (refs.audio ?? []).filter((ref) => !ref.startsWith("http")));
60
- return audioSeconds === undefined ? {} : { inputDurationSeconds: audioSeconds };
64
+ const seconds = await audioSeconds();
65
+ return seconds === undefined ? {} : { inputDurationSeconds: seconds };
61
66
  }
62
67
  async function estimateMedia(engine, input) {
63
68
  const modelId = text(input.model);
@@ -71,7 +76,7 @@ async function estimateMedia(engine, input) {
71
76
  const sourceError = await checkSeedanceEditSource(engine, model, refs, input.mode);
72
77
  if (sourceError)
73
78
  return unavailable(sourceError);
74
- const hints = { ...await mediaHints(engine, refs), ...await seedanceDraftCostHints(engine, model.id, options) };
79
+ const hints = { ...await mediaHints(engine, refs, model), ...await seedanceDraftCostHints(engine, model.id, options) };
75
80
  const result = await estimateGeneration(model, {
76
81
  prompt: text(input.prompt),
77
82
  refUrls: placeholderRefs(refs),
@@ -7,7 +7,6 @@ import { legacyMediaForTaskType } from "../media/legacy-task-types.js";
7
7
  import { parseModelId } from "../media/model-id.js";
8
8
  import { computeArtifactStatus, QUEUED_TASK_ID } from "videobook-engine";
9
9
  import { z } from "zod";
10
- import { createHash } from "node:crypto";
11
10
  import { join } from "node:path";
12
11
  import { KieError } from "@apicity/kie";
13
12
  import { XaiError } from "@apicity/xai";
@@ -18,20 +17,19 @@ import { EMPTY_TAG_SUMMARY, readAssetTagSummaries, } from "../asset-tags.js";
18
17
  import { logger } from "../logger.js";
19
18
  import { queue } from "../queue.js";
20
19
  import { getApiKey } from "../api-key.js";
21
- import { findVideoFile, findAudioFile, findPrimaryMediaFile, RENDER_ORIENTATIONS as MEDIA_RENDER_ORIENTATIONS, } from "videobook-engine";
20
+ import { findVideoFile, findAudioFile, RENDER_ORIENTATIONS as MEDIA_RENDER_ORIENTATIONS, } from "videobook-engine";
22
21
  import { readAndAssessDialog } from "../dialog-quality.js";
23
22
  import { hasSpokenAudio, PLAIN_TRANSCRIPT_FILE, readAssetTranscriptSources, TIMED_TRANSCRIPT_FILE, } from "../transcript-projection.js";
24
23
  import { isAnalyzableVideo, readVideoAnalysisSummary, VIDEO_ANALYSIS_FILE, } from "../video-analysis-projection.js";
25
24
  import { failPendingTaskAndLog } from "../jobs/task-failure.js";
26
25
  import { findUnprocessedUploads, processExternalUpload } from "../jobs/process-upload.js";
27
26
  import { planVideoTranscriptJobs } from "../jobs/process-video.js";
28
- import { probeVideo } from "../ffmpeg.js";
29
27
  import { providerEndpoints } from "../media/endpoints.js";
30
28
  import { machgenProvider } from "../media/adapters/machgen.js";
31
29
  import { MEDIA_TASK_TYPES } from "../media/adapters/types.js";
32
30
  import { submitQueuedKieTask } from "../jobs/kie-paygate.js";
33
31
  import { DEFAULT_KEYWORD_GRAPHICS_LINGER_SECONDS, DEFAULT_KEYWORD_GRAPHICS_MAX_COUNT, } from "../remotion/keyword-graphics.js";
34
- import { invalidVideoProxyMetadata, probeStoredVideoFile, videoProxyAssessmentMatches, videoProxyMetadata, videoProxyMetadataMatches, videoProxyValidationError, } from "../video-proxy.js";
32
+ import { assetDuration, assetMediaUrls, assetStreamProfile, findAssetMediaFile, groupByArtifactId, indexByArtifactId, PARTIAL_DOWNLOAD_RE, scheduleMissingVideoPoster, servedVideoProxyFile, } from "../asset-media-projection.js";
35
33
  /** Upper bound on how long a pending task may sit without reaching success/fail
36
34
  * before reconciliation ages it out. Guards against providers leaving jobs in an
37
35
  * intermediate "waiting" state indefinitely. */
@@ -153,29 +151,6 @@ async function analysisOutputProjection(engine, artifactId) {
153
151
  return null;
154
152
  }
155
153
  }
156
- function findAssetMediaFile(files, asset) {
157
- return asset.kind === "audio"
158
- ? findAudioFile(files, asset.kind)
159
- : asset.kind === "video"
160
- ? findVideoFile(files.filter((file) => file.name !== "proxy.mp4"))
161
- : findPrimaryMediaFile(files, asset.kind);
162
- }
163
- async function assessStoredVideoProxy(engine, assetId, sourceFile, proxyFile, sourceProfile) {
164
- let assessment;
165
- try {
166
- const proxy = await probeStoredVideoFile(engine, assetId, proxyFile.name);
167
- const error = videoProxyValidationError(sourceProfile, proxy);
168
- assessment = error
169
- ? invalidVideoProxyMetadata(sourceFile, proxyFile, error)
170
- : videoProxyMetadata(sourceFile, proxyFile, proxy);
171
- }
172
- catch (cause) {
173
- const error = cause instanceof Error ? cause.message : String(cause);
174
- assessment = invalidVideoProxyMetadata(sourceFile, proxyFile, error);
175
- }
176
- await engine.metadata.artifacts.write(assetId, "proxy", assessment);
177
- return assessment.valid;
178
- }
179
154
  /** Read the OSG overlay summary from the asset's render metadata. OSG is stored
180
155
  * identically across orientations, so the first orientation that carries an
181
156
  * osgAssetId wins. Returns null when no overlay is configured. */
@@ -277,9 +252,7 @@ function scheduleWaveformExtraction(bookId, assetId, videoFilename) {
277
252
  logger.error("waveform-enqueue-failed", { assetId, error: err });
278
253
  });
279
254
  }
280
- const PARTIAL_DOWNLOAD_RE = /\.(mp4|mov)\.part$/i;
281
255
  /** Media extensions whose duration can be recovered via ffprobe when metadata lacks it. */
282
- const DURATION_PROBE_EXT_RE = /\.(mp4|mov|webm|mkv|mp3|wav|m4a|aac|ogg|flac)$/i;
283
256
  export const RENDER_ORIENTATIONS = MEDIA_RENDER_ORIENTATIONS;
284
257
  export async function readRenderSettings(engine, assetId, orientations) {
285
258
  const result = {};
@@ -377,30 +350,6 @@ async function readAnalysisRecommendations(engine, assetId) {
377
350
  return {};
378
351
  }
379
352
  }
380
- // Content fingerprint covering every file in the asset directory. Changes
381
- // whenever any file is added, removed, resized, or rewritten, so every URL
382
- // derived from an asset's filePath (including alternate-orientation renders
383
- // like portrait.mp4 / landscape.mp4) invalidates together. Cheap: no file
384
- // reads — just hashes the immutable manifest tuples. Partial downloads are
385
- // excluded: their size grows on every poll while no served URL points at
386
- // them, and including them made every media URL churn (and the browser
387
- // refetch) once per poll tick for the whole duration of a download.
388
- function computeAssetFingerprint(files) {
389
- const settled = files.filter((f) => !PARTIAL_DOWNLOAD_RE.test(f.name));
390
- if (settled.length === 0)
391
- return "";
392
- const sorted = [...settled].sort((a, b) => a.name.localeCompare(b.name));
393
- const hash = createHash("sha1");
394
- for (const f of sorted) {
395
- hash.update(f.name);
396
- hash.update("\0");
397
- hash.update(String(f.sizeBytes ?? 0));
398
- hash.update("\0");
399
- hash.update(f.objectHash);
400
- hash.update("\0");
401
- }
402
- return hash.digest("hex").slice(0, 12);
403
- }
404
353
  function renderedOrientationsFor(files, kind) {
405
354
  const fileSet = new Set(files.map((f) => f.name));
406
355
  if (kind === "final") {
@@ -408,23 +357,6 @@ function renderedOrientationsFor(files, kind) {
408
357
  }
409
358
  return RENDER_ORIENTATIONS.filter((o) => fileSet.has(`${o}.mp4`));
410
359
  }
411
- function indexByArtifactId(rows) {
412
- const map = new Map();
413
- for (const row of rows)
414
- map.set(row.artifactId, row);
415
- return map;
416
- }
417
- function groupByArtifactId(rows) {
418
- const map = new Map();
419
- for (const row of rows) {
420
- const list = map.get(row.artifactId);
421
- if (list)
422
- list.push(row);
423
- else
424
- map.set(row.artifactId, [row]);
425
- }
426
- return map;
427
- }
428
360
  export async function buildAssetList(engine, book_id, sort) {
429
361
  const assets = engine.artifacts.list({ ...(sort ? { sort } : {}) });
430
362
  const pendingAll = engine.jobs.pending.findAll();
@@ -468,30 +400,9 @@ export async function buildAssetList(engine, book_id, sort) {
468
400
  const mediaFile = findAssetMediaFile(files, a);
469
401
  const meta = metadata.ok ? metadata.value : null;
470
402
  const streams = streamsByArtifact.get(a.artifactId) ?? [];
471
- const videoStream = streams.find((stream) => stream.kind === "video" && stream.video);
472
- const audioStream = streams.find((stream) => stream.kind === "audio" && stream.audio);
473
- const frameRate = videoStream?.video?.averageFrameRate
474
- ?? videoStream?.video?.nominalFrameRate;
475
- const streamDuration = videoStream
476
- ? videoStream.durationTicks
477
- * videoStream.timeBase.numerator
478
- / videoStream.timeBase.denominator
479
- : 0;
480
- const metadataDuration = Number(meta?.duration);
481
- const sourceDuration = streamDuration > 0
482
- ? streamDuration
483
- : Number.isFinite(metadataDuration) ? metadataDuration : 0;
484
- const sourceProfile = sourceDuration > 0
485
- ? {
486
- videoDuration: sourceDuration,
487
- avgFps: frameRate
488
- ? frameRate.numerator / frameRate.denominator
489
- : null,
490
- hasAudio: audioStream !== undefined || meta?.hasAudio === true,
491
- }
492
- : null;
403
+ const profile = assetStreamProfile(streams, meta);
404
+ const { audioStream, frameRate } = profile;
493
405
  const fileNames = new Set(files.map((f) => f.name));
494
- const hasThumbnail = fileNames.has("original.jpg");
495
406
  const renders = renderedOrientationsFor(files, a.kind);
496
407
  const hasPartFile = files.some((f) => PARTIAL_DOWNLOAD_RE.test(f.name));
497
408
  const frameDirs = buildFrameDirs(directories, book_id, a.artifactId);
@@ -509,64 +420,22 @@ export async function buildAssetList(engine, book_id, sort) {
509
420
  : Promise.resolve(null),
510
421
  ]);
511
422
  const waveform = await readWaveformOrSchedule(engine, a.artifactId, book_id, mediaFile?.name ?? null);
512
- // Cache-bust media URLs so browsers refetch after trim / re-encode / re-render.
513
- // For video and image assets, use a content fingerprint covering the whole
514
- // asset directory: orientation re-renders (portrait/landscape/square.mp4)
515
- // touch alternate files but not original.mp4, so a primary-mtime cache
516
- // key would leave alternate-orientation URLs cached and stale.
517
- const useFingerprint = a.kind === "video" || a.kind === "image";
518
- let cacheBust = '';
519
- if (useFingerprint) {
520
- const fp = computeAssetFingerprint(files);
521
- if (fp)
522
- cacheBust = `?v=${fp}`;
523
- }
524
- else {
525
- const mediaHash = mediaFile?.objectHash;
526
- if (mediaHash)
527
- cacheBust = `?v=${mediaHash.slice(0, 12)}`;
528
- }
529
- // Character assets: free-form folders have no original.* media. Project
530
- // the first image in the folder so sidebar thumbs and drag-drop keep working.
531
- let charImage = null;
532
- if (a.kind === "character") {
533
- charImage = files.find((f) => /\.(jpg|jpeg|png|webp|gif)$/i.test(f.name)) ?? null;
534
- }
535
- const proxyCandidate = a.kind === "video"
536
- ? files.find((file) => file.name === "proxy.mp4")
537
- : null;
538
- let proxyFile = null;
539
- if (proxyCandidate && mediaFile) {
540
- if (proxyMetadata.ok
541
- && videoProxyMetadataMatches(proxyMetadata.value, mediaFile, proxyCandidate)) {
542
- proxyFile = proxyCandidate;
543
- }
544
- else {
545
- const assessmentMatches = proxyMetadata.ok
546
- && videoProxyAssessmentMatches(proxyMetadata.value, mediaFile, proxyCandidate);
547
- const active = assetWorkRow.ok
548
- && assetWorkRow.value !== null
549
- && (assetWorkRow.value.status === "pending" || assetWorkRow.value.status === "working");
550
- if (!assessmentMatches && !active && sourceProfile) {
551
- const valid = await assessStoredVideoProxy(engine, a.artifactId, mediaFile, proxyCandidate, sourceProfile);
552
- if (valid)
553
- proxyFile = proxyCandidate;
554
- }
555
- }
556
- }
557
- const media_url = charImage
558
- ? `/files/${book_id}/${a.artifactId}/${charImage.name}${cacheBust}`
559
- : proxyFile
560
- ? `/files/${book_id}/${a.artifactId}/${proxyFile.name}${cacheBust}`
561
- : mediaFile
562
- ? `/files/${book_id}/${a.artifactId}/${mediaFile.name}${cacheBust}`
563
- : null;
564
- const isImage = a.kind === "image";
565
- const thumbnail_url = charImage
566
- ? `/files/${book_id}/${a.artifactId}/${charImage.name}${cacheBust}`
567
- : hasThumbnail
568
- ? `/files/${book_id}/${a.artifactId}/original.jpg${cacheBust}`
569
- : isImage ? media_url : null;
423
+ const proxyFile = servedVideoProxyFile({
424
+ bookId: book_id,
425
+ artifact: a,
426
+ files,
427
+ mediaFile,
428
+ proxyMetadata,
429
+ work: assetWorkRow.value,
430
+ sourceProfile: profile.sourceProfile,
431
+ });
432
+ const { media_url, thumbnail_url } = assetMediaUrls({
433
+ bookId: book_id,
434
+ artifact: a,
435
+ files,
436
+ mediaFile,
437
+ proxyFile,
438
+ });
570
439
  // Status derivation lives in videobook-engine (`computeArtifactStatus`). We pass
571
440
  // the asset-type-aware primary media name we already computed so the
572
441
  // engine doesn't have to redo media-type heuristics.
@@ -587,20 +456,13 @@ export async function buildAssetList(engine, book_id, sort) {
587
456
  }
588
457
  : null,
589
458
  });
590
- if (a.kind === "video" && status === "ready" && !hasThumbnail && mediaFile) {
591
- const recovery = await engine.metadata.artifacts.read(a.artifactId, "poster-recovery");
592
- if (!recovery.ok || !recovery.value.failed || recovery.value.sourceHash !== mediaFile.objectHash) {
593
- void queue.enqueue(`extract-video-poster-${book_id}-${a.artifactId}-${mediaFile.objectHash}`, {
594
- type: "extract_video_poster",
595
- bookId: book_id,
596
- posterArtifactId: a.artifactId,
597
- sourceFilename: mediaFile.name,
598
- sourceHash: mediaFile.objectHash,
599
- }).catch((error) => {
600
- logger.error("poster-enqueue-failed", { assetId: a.artifactId, error });
601
- });
602
- }
603
- }
459
+ await scheduleMissingVideoPoster(engine, {
460
+ bookId: book_id,
461
+ artifact: a,
462
+ files,
463
+ mediaFile,
464
+ status,
465
+ });
604
466
  const archiveMeta = archiveMetadata.ok ? archiveMetadata.value : null;
605
467
  const analysisInfo = analysisInfoFromMetadata(meta);
606
468
  if (analysisInfo && fileNames.has("analysis.json")) {
@@ -612,22 +474,13 @@ export async function buildAssetList(engine, book_id, sort) {
612
474
  analysisInfo.llm_exchanges = output.llmExchanges;
613
475
  }
614
476
  }
615
- // Backfill duration if missing from metadata (video + audio; probeVideo
616
- // reads format.duration via ffprobe and works for both).
617
- let duration = meta?.duration ?? null;
618
- if (duration === null && mediaFile && DURATION_PROBE_EXT_RE.test(mediaFile.name)) {
619
- try {
620
- const probe = await probeVideo(join(a.path, mediaFile.name));
621
- if (Number.isFinite(probe.duration) && probe.duration > 0) {
622
- duration = probe.duration;
623
- // Persist so we don't re-probe next time
624
- if (metadata.ok) {
625
- await engine.metadata.artifacts.write(a.artifactId, "original", { ...metadata.value, duration });
626
- }
627
- }
628
- }
629
- catch { /* non-fatal */ }
630
- }
477
+ const duration = assetDuration({
478
+ bookId: book_id,
479
+ artifactId: a.artifactId,
480
+ meta,
481
+ mediaFile,
482
+ profile,
483
+ });
631
484
  const audio_info = audioStream?.audio
632
485
  ? {
633
486
  codec: audioStream.codec,
@@ -925,7 +778,7 @@ export async function pollPendingProviderTasks(engine, book_id, options = {}) {
925
778
  try {
926
779
  const recordInfo = await provider.veo.get.api.v1.veo.recordInfo(task.taskId);
927
780
  const data = recordInfo.data;
928
- // Veo successFlag: 0=submitted/pending, 1=success, 2=fail, 3=processing
781
+ // Veo successFlag: 0=generating, 1=success, 2=task creation failed, 3=generation failed
929
782
  if (data?.successFlag === 1) {
930
783
  const urls = data.response?.resultUrls ?? [];
931
784
  if (urls.length === 0) {
@@ -953,7 +806,7 @@ export async function pollPendingProviderTasks(engine, book_id, options = {}) {
953
806
  });
954
807
  result.completed.push({ assetId: task.artifactId, taskType: task.taskType, jobId });
955
808
  }
956
- else if (data?.successFlag === 2) {
809
+ else if (data?.successFlag === 2 || data?.successFlag === 3) {
957
810
  const failMsg = data.errorMessage ?? "Veo task failed";
958
811
  result.failed.push({ assetId: task.artifactId, taskType: task.taskType, failMsg, failedAt: new Date().toISOString(), prompt });
959
812
  await failPendingTaskAndLog(engine, task.artifactId, task.taskId, { message: failMsg, prompt });
@@ -963,7 +816,7 @@ export async function pollPendingProviderTasks(engine, book_id, options = {}) {
963
816
  assetId: task.artifactId,
964
817
  taskType: task.taskType,
965
818
  progress: 0,
966
- state: data?.successFlag === 3 ? "processing" : "waiting",
819
+ state: "waiting",
967
820
  prompt,
968
821
  startedAt: task.createdAt,
969
822
  });
@@ -17,6 +17,7 @@ import { listNotebookActions, markDescendantsStale, normalizeCellActionFields, n
17
17
  import { hydrateNotebookProviderFailures } from "../notebook-provider-failure.js";
18
18
  import { buildSevenStageScaffold } from "../notebook-workflow.js";
19
19
  import { previewGeneration } from "../media/preview.js";
20
+ import { readNotebookStickySettings, rememberNotebookStickySettings, seedNotebookStickySettings, } from "../notebook-sticky-settings.js";
20
21
  import { generationInputMentions, remapGenerationInputPrompt } from "../generation-input-mentions.js";
21
22
  import { applyPreviewPlaceholderUrls } from "../preview-payload.js";
22
23
  import { jobProviderTaskStatus } from "../provider-task-status.js";
@@ -559,6 +560,7 @@ function notebookPayload(engine, notebook) {
559
560
  cells: normalized.cells.map(cellPayload),
560
561
  posts: notebookPosts(engine, normalized),
561
562
  edges: normalized.edges,
563
+ generation_settings_memory: readNotebookStickySettings(engine, normalized.id),
562
564
  };
563
565
  }
564
566
  const entityKindSchema = z.enum(["prompt", "scene", "character"]);
@@ -1158,6 +1160,7 @@ export function videobookDomainDefs(engine, books) {
1158
1160
  if (args.cell.type === "goal")
1159
1161
  return failure(GOAL_TILE_CREATE_ERROR);
1160
1162
  let cell = engine.notebooks.createCell(cellFromInput(args.cell));
1163
+ let requestedCell = cell;
1161
1164
  let outputCell = null;
1162
1165
  let outputEdge = null;
1163
1166
  try {
@@ -1167,6 +1170,8 @@ export function videobookDomainDefs(engine, books) {
1167
1170
  throw new Error(`Stale notebook revision: expected ${args.expected_revision}`);
1168
1171
  }
1169
1172
  cell = normalizeCellActionFields(cell, notebook);
1173
+ requestedCell = cell;
1174
+ cell = seedNotebookStickySettings(cell, readNotebookStickySettings(engine, String(args.notebook_id)));
1170
1175
  const withCell = seedInitialGenerationPrompt({
1171
1176
  ...notebook,
1172
1177
  cells: [...notebook.cells, cell],
@@ -1209,6 +1214,8 @@ export function videobookDomainDefs(engine, books) {
1209
1214
  ],
1210
1215
  };
1211
1216
  }, { cellId: cell.id });
1217
+ if (result.ok)
1218
+ rememberNotebookStickySettings(engine, String(args.notebook_id), requestedCell);
1212
1219
  return result.ok
1213
1220
  ? json({
1214
1221
  ...cellPayload(cell),
@@ -1239,6 +1246,7 @@ export function videobookDomainDefs(engine, books) {
1239
1246
  return failure(`Stale notebook revision: expected ${args.expected_revision}`);
1240
1247
  }
1241
1248
  const patch = args.cell;
1249
+ const edited = {};
1242
1250
  try {
1243
1251
  const result = await mutateNotebook(engine, String(args.notebook_id), "update_notebook_cell", (notebook) => {
1244
1252
  if (typeof args.expected_revision === "string"
@@ -1298,10 +1306,15 @@ export function videobookDomainDefs(engine, books) {
1298
1306
  ? {}
1299
1307
  : { pinnedResults: patch.pinned_results.map(pinnedResultFromInput) }),
1300
1308
  }, document);
1301
- const next = reconcileInitialGenerationPrompt(cell, normalized);
1309
+ const reconciled = reconcileInitialGenerationPrompt(cell, normalized);
1310
+ const next = reconciled.model !== cell.model
1311
+ ? seedNotebookStickySettings(reconciled, readNotebookStickySettings(engine, String(args.notebook_id)))
1312
+ : reconciled;
1302
1313
  const validation = validateCellConfiguration(next, document);
1303
1314
  if (!validation.ok)
1304
1315
  throw new Error(validation.message);
1316
+ edited.previous = cell;
1317
+ edited.next = reconciled;
1305
1318
  return next;
1306
1319
  });
1307
1320
  if (!found)
@@ -1312,6 +1325,8 @@ export function videobookDomainDefs(engine, books) {
1312
1325
  });
1313
1326
  return markDescendantsStale(updated, String(args.cell_id));
1314
1327
  }, { cellId: args.cell_id });
1328
+ if (result.ok && edited.next)
1329
+ rememberNotebookStickySettings(engine, String(args.notebook_id), edited.next, edited.previous);
1315
1330
  return result.ok
1316
1331
  ? json({ cell_id: args.cell_id, revision: result.value.hash })
1317
1332
  : failure(result.error.message);
@@ -53,13 +53,13 @@ export function createFreeMediaUpload(options = {}) {
53
53
  return capturedProvider("free-media-upload", (fetch) => freemediaupload({ ...options, fetch }), options?.fetch);
54
54
  }
55
55
  export function uploadFalFile(options, input) {
56
- return withHarCapture({ provider: "fal", endpoint: "uploadFile", input }, (fetch) => falUpload(fal({ ...options, fetch }), input), providerUsageFetch("fal", options.fetch));
56
+ return withHarCapture({ provider: "fal", endpoint: "storage.upload.initiate", input }, (fetch) => falUpload(fal({ ...options, fetch }), input), providerUsageFetch("fal", options.fetch));
57
57
  }
58
58
  export function uploadAlibabaFile(options, input) {
59
- return withHarCapture({ provider: "alibaba", endpoint: "uploadFile", input }, (fetch) => alibabaUpload(alibaba({ ...options, fetch }), input), providerUsageFetch("alibaba", options.fetch));
59
+ return withHarCapture({ provider: "alibaba", endpoint: "api.v1.uploads", input }, (fetch) => alibabaUpload(alibaba({ ...options, fetch }), input), providerUsageFetch("alibaba", options.fetch));
60
60
  }
61
61
  export function uploadKieFile(options, file, filename) {
62
- return withHarCapture({ provider: "kie", endpoint: "uploadFile", input: { file, filename } }, (fetch) => kieUpload(kie({ ...options, fetch }), file, filename), providerUsageFetch("kie", options.fetch));
62
+ return withHarCapture({ provider: "kie", endpoint: "api.fileStreamUpload", input: { file, filename } }, (fetch) => kieUpload(kie({ ...options, fetch }), file, filename), providerUsageFetch("kie", options.fetch));
63
63
  }
64
64
  export function submitMediaJob(...args) {
65
65
  const [provider, request, approval] = args;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "videobook",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Local-first MCP server and web UI for AI video creation: notebooks, generation, editing, rendering and publishing.",
5
5
  "keywords": [
6
6
  "mcp",
@@ -36,20 +36,20 @@
36
36
  "start": "node dist/index.js"
37
37
  },
38
38
  "dependencies": {
39
- "@apicity/alibaba": "^0.18.0",
40
- "@apicity/b2": "^0.18.0",
41
- "@apicity/cost": "^0.18.0",
42
- "@apicity/dropbox": "^0.18.0",
43
- "@apicity/elevenlabs": "^0.18.0",
44
- "@apicity/fal": "^0.18.0",
45
- "@apicity/free-media-upload": "^0.18.0",
46
- "@apicity/har": "^0.18.0",
47
- "@apicity/kie": "^0.18.0",
48
- "@apicity/kimicoding": "^0.18.0",
49
- "@apicity/machgen": "^0.18.0",
50
- "@apicity/openai": "^0.18.0",
51
- "@apicity/x": "^0.18.0",
52
- "@apicity/xai": "^0.18.0",
39
+ "@apicity/alibaba": "^0.19.0",
40
+ "@apicity/b2": "^0.19.0",
41
+ "@apicity/cost": "^0.19.0",
42
+ "@apicity/dropbox": "^0.19.0",
43
+ "@apicity/elevenlabs": "^0.19.0",
44
+ "@apicity/fal": "^0.19.0",
45
+ "@apicity/free-media-upload": "^0.19.0",
46
+ "@apicity/har": "^0.19.0",
47
+ "@apicity/kie": "^0.19.0",
48
+ "@apicity/kimicoding": "^0.19.0",
49
+ "@apicity/machgen": "^0.19.0",
50
+ "@apicity/openai": "^0.19.0",
51
+ "@apicity/x": "^0.19.0",
52
+ "@apicity/xai": "^0.19.0",
53
53
  "@devmehq/open-graph-extractor": "^1.1.1",
54
54
  "@ffprobe-installer/ffprobe": "2.1.2",
55
55
  "@modelcontextprotocol/client": "^2.2.0",