@mengine/medeo-client 1.3.0 → 1.3.1-alpha.1

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { $ as VideoDocumentSchemaVersion, A as assertValidVideoDocument, B as BgmPart, C as index_d_exports, D as VideoDocumentMirrorSchema, E as VideoDocumentDraft, F as SpeechHostMap, G as SpeechPart, H as DEFAULT_UNIT_TIME_MS, I as buildSpeechHostMap, J as TrackItem, K as Timeline, L as derivePositionFromAbs, M as InitialDocumentFacts, N as buildInitialVideoDocument, O as videoDocumentMirrorSchema, P as DerivedItemPosition, Q as VideoDocument, R as fromVideoDocument, S as ValidationError, T as TrackItemDraft, U as PartKind, V as CaptionPart, W as PartUnion, X as VIDEO_DOCUMENT_SCHEMA_VERSION, Y as TrackItemTimePosition, Z as VideoClipPart, _ as PlannedSemanticOpKind, a as MirrorVideoDocumentOptions, at as CaptionPart$1, b as SchemaValidator, c as CommitOptions, ct as SpeedShift, d as SemanticEditor, dt as TrackItem$1, et as VideoDocumentValidationIssue, f as SemanticOpInput, g as ImplementedSemanticOpKind, h as IMPLEMENTED_SEMANTIC_OP_KINDS, i as MirrorVideoDocumentAdapter, it as Attachment, j as validateVideoDocument, k as VideoDocumentValidationError, l as OpActor, lt as Timeline$1, m as TransactAudit, n as videoDocumentSchema, nt as VideoDraft, o as createMirrorVideoDocument, ot as CaptionStyle, p as SemanticOpName, q as Track, r as readVideoDocumentFromDraft, rt as VideoDraftPartUnion, s as createMirrorVideoDocumentAdapter, st as PartAggregation, t as partUnionSchema, tt as VideoDocumentValidationIssueCode, u as SemanticDocumentAdapter, ut as Track$1, v as SemanticOpKind, w as TrackDraft, x as SnapshotReadable, y as isImplementedSemanticOpKind, z as toVideoDocument } from "./index-DWVYLTjv.js";
1
+ import { t as index_d_exports } from "./index-CMa6ZCtX.js";
2
+ import { $ as VoiceDescriptor, A as generatePartId, At as effectiveVideoClipDurationMs, B as ResolvedEntityClipPlacement, C as PlannedSemanticOpKind, Ct as VideoClipPart, D as SnapshotReadable, Dt as VideoDocumentValidationIssueCode, E as SchemaValidator, Et as VideoDocumentValidationIssue, F as videoDocumentMirrorSchema, Ft as PartAggregation, G as EntityTimelineProjectionError, H as ResolvedEntityTrack, I as VideoDocumentValidationError, It as SpeedShift, J as CaptionSegmentSelection, K as EntityRelationRows, L as assertValidVideoDocument, Lt as Timeline$1, M as TrackItemDraft, Mt as Attachment, N as VideoDocumentDraft, Nt as CaptionPart$1, O as ValidationError, Ot as VideoDraft, P as VideoDocumentMirrorSchema, Pt as CaptionStyle, Q as SequenceRange, R as validateVideoDocument, Rt as Track$1, S as ImplementedSemanticOpKind, St as VIDEO_DOCUMENT_SCHEMA_VERSION, T as isImplementedSemanticOpKind, Tt as VideoDocumentSchemaVersion, U as resolveEntityTimelineLayout, V as ResolvedEntityTimelineLayout, W as projectEntityTimeline, X as ScriptTextSegment, Y as CaptionStyleFields, Z as SequenceDuration, _ as SemanticEditor, _t as SpeechPart, a as PlainMemoryAdapter, at as DerivedItemPosition, b as TransactAudit, bt as TrackItem, c as MirrorVideoDocumentAdapter, ct as derivePositionFromAbs, d as createMirrorVideoDocument, dt as BgmPart, et as JsonObject, f as createMirrorVideoDocumentAdapter, ft as CaptionPart, g as SemanticDocumentAdapter, gt as PartUnion, h as OpActor, ht as PartKind, i as JournalEntry, it as buildInitialVideoDocument, j as TrackDraft, jt as speedOf, k as PartIdFactory, kt as VideoDraftPartUnion, l as MirrorVideoDocumentOptions, lt as fromVideoDocument, m as CommitOptions, mt as ENTITY_TIMELINE_PROJECTION_SCHEMA_VERSION, n as videoDocumentSchema, nt as EntityId, o as PlainMemoryAdapterOptions, ot as SpeechHostMap, p as writeVideoDocumentToDraft, pt as DEFAULT_UNIT_TIME_MS, q as EntityRow, r as readVideoDocumentFromDraft, rt as InitialDocumentFacts, s as createPlainMemoryAdapter, st as buildSpeechHostMap, t as partUnionSchema, tt as JsonValue, u as applyEntityTimelineProjection, ut as toVideoDocument, v as SemanticOpInput, vt as Timeline, w as SemanticOpKind, wt as VideoDocument, x as IMPLEMENTED_SEMANTIC_OP_KINDS, xt as TrackItemTimePosition, y as SemanticOpName, yt as Track, z as EntityTimelineTrackRole, zt as TrackItem$1 } from "./index-PYtGeXNk.js";
2
3
  import { PeerID } from "loro-crdt";
3
4
  import { DocState } from "@mengine/sync";
4
5
  import { BaseDocStorage, Connection, DocDiff, DocPushReceipt, DocSnapshotRecord, DocStorage, DocStorageOptions, DocUpdate, DocUpdateRecord } from "@mengine/storage";
@@ -177,33 +178,496 @@ interface MengineEventStreamOptions {
177
178
  }
178
179
  declare function readMengineEventStream(options: MengineEventStreamOptions): Promise<void>;
179
180
  //#endregion
180
- //#region src/editor/id-gen.d.ts
181
+ //#region ../medeo-dsl/src/composition.d.ts
182
+ type ScriptCompositionIssueCode = 'composition_missing' | 'composition_ambiguous' | 'composition_dangling' | 'unknown_segment' | 'empty_selection' | 'invalid_script' | 'invalid_selection';
181
183
  /**
182
- * Part-id generation, aligned with the online ecosystem.
184
+ * Raised when a variant's complete content cannot be assembled from its
185
+ * required composition Relation. Assembly never falls back to variant-local
186
+ * text: a missing, ambiguous, or dangling source is an error, not an empty
187
+ * read.
188
+ */
189
+ declare class ScriptCompositionError extends Error {
190
+ readonly code: ScriptCompositionIssueCode;
191
+ readonly entityId: EntityId;
192
+ constructor(code: ScriptCompositionIssueCode, entityId: EntityId, message: string);
193
+ }
194
+ interface AssembledCaptionContent {
195
+ readonly caption: EntityRow<'caption'>;
196
+ readonly audioScript: EntityRow<'audio-script'>;
197
+ /** Selected AudioScript segments in Caption selection order. */
198
+ readonly segments: readonly ScriptTextSegment[];
199
+ /** Complete display text: the selected segments' text joined in order. */
200
+ readonly text: string;
201
+ }
202
+ interface AssembledPhoneticScriptContent {
203
+ readonly phoneticScript: EntityRow<'phonetic-script'>;
204
+ readonly audioScript: EntityRow<'audio-script'>;
205
+ /** All AudioScript segments in script order; the pronunciation variant never reorders text. */
206
+ readonly segments: readonly ScriptTextSegment[];
207
+ /** Complete base text owned by the AudioScript. */
208
+ readonly text: string;
209
+ }
210
+ /**
211
+ * Resolve the one AudioScript a variant composes. Relations are queried from
212
+ * both endpoints, so persisted endpoint positions do not matter.
213
+ */
214
+ declare function findComposedAudioScript(rows: EntityRelationRows, variantEntityId: EntityId, variantKind: 'caption' | 'phonetic-script'): EntityRow<'audio-script'>;
215
+ /** Join the whole AudioScript text in segment order. */
216
+ declare function assembleScriptText(script: EntityRow<'audio-script'>): string;
217
+ /**
218
+ * Assemble the complete Caption content from its AudioScript: the selected
219
+ * segments in selection order, joined as display text. The Caption payload
220
+ * never carries text, so a broken composition fails here instead of silently
221
+ * rendering an empty caption.
222
+ */
223
+ declare function assembleCaptionContent(rows: EntityRelationRows, captionEntityId: EntityId): AssembledCaptionContent;
224
+ /**
225
+ * Assemble the complete Phonetic Script content for TTS: the composed
226
+ * AudioScript's base text plus the variant's own phoneme and prosody fields.
227
+ */
228
+ declare function assemblePhoneticScriptContent(rows: EntityRelationRows, phoneticScriptEntityId: EntityId): AssembledPhoneticScriptContent;
229
+ /** Select source text without creating another authoritative text field. */
230
+ declare function selectAudioScriptSegments(script: EntityRow<'audio-script'>, selections: readonly CaptionSegmentSelection[]): readonly ScriptTextSegment[];
231
+ //#endregion
232
+ //#region src/entity-editor/entity-graph-http-client.d.ts
233
+ /** One authenticated revision of the authoritative Medeo Entity graph. */
234
+ interface EntityGraphState {
235
+ readonly revision: number;
236
+ readonly rows: EntityRelationRows;
237
+ }
238
+ interface EntityGraphCommitOptions {
239
+ /** Server version vector proving the explicit legacy-to-Entity migration baseline. */
240
+ readonly migrationBaseVv?: string;
241
+ }
242
+ /** Browser-safe authenticated CAS client for a document's Entity graph. */
243
+ declare class EntityGraphHttpClient {
244
+ private readonly options;
245
+ private readonly transport;
246
+ private readonly endpoint;
247
+ constructor(options: MengineHttpClientOptions);
248
+ fetchState(): Promise<EntityGraphState>;
249
+ /**
250
+ * Replace the complete Entity graph under the baseline revision.
251
+ *
252
+ * Deletion intent is derived from baseline IDs omitted from `nextRows`, so a
253
+ * transient create-then-remove never becomes a request to delete unknown
254
+ * persisted data.
255
+ */
256
+ commit(baseState: EntityGraphState, nextRows: EntityRelationRows, options?: EntityGraphCommitOptions): Promise<EntityGraphState>;
257
+ private request;
258
+ }
259
+ //#endregion
260
+ //#region src/entity-editor/types.d.ts
261
+ /** Injectable domain-id mint shared by Entity and Relation authoring surfaces. */
262
+ type EntityTimelineIdFactory = (prefix: 'entity' | 'relation') => string;
263
+ interface ImageMediaAssetFact {
264
+ readonly assetId: string;
265
+ readonly kind: 'image';
266
+ readonly storageKey?: string;
267
+ }
268
+ interface VideoMediaAssetFact {
269
+ readonly assetId: string;
270
+ readonly kind: 'video';
271
+ readonly durationMs: number;
272
+ readonly storageKey?: string;
273
+ }
274
+ interface AudioMediaAssetFact {
275
+ readonly assetId: string;
276
+ readonly kind: 'audio';
277
+ readonly durationMs: number;
278
+ readonly storageKey: string;
279
+ }
280
+ interface VoiceMediaAssetFact {
281
+ /** Stable external speech result id, independent of the placed Clip id. */
282
+ readonly assetId: string;
283
+ readonly kind: 'voice';
284
+ readonly durationMs: number;
285
+ readonly storageKey: string;
286
+ /** Present for synthesized voice, absent for original recorded audio. */
287
+ readonly voice?: VoiceDescriptor;
288
+ }
289
+ /** Facts resolved from media storage. A trim window never substitutes for intrinsic duration. */
290
+ type MediaAssetFact = ImageMediaAssetFact | VideoMediaAssetFact | AudioMediaAssetFact | VoiceMediaAssetFact;
291
+ type ClipPlacement = {
292
+ readonly kind: 'sequential';
293
+ readonly order: number;
294
+ } | {
295
+ readonly kind: 'absolute';
296
+ readonly targetRange: SequenceRange<number>;
297
+ } | {
298
+ readonly kind: 'anchored';
299
+ readonly hostClipEntityId: string;
300
+ readonly anchorOffset: number;
301
+ };
302
+ interface InsertPlacedClipInput {
303
+ readonly trackEntityId: string;
304
+ readonly contentEntityId: string;
305
+ readonly sourceRange: SequenceRange<number>;
306
+ readonly duration: SequenceDuration<number>;
307
+ readonly placement: ClipPlacement;
308
+ readonly clipPayload?: JsonObject;
309
+ /** Stable caller-owned placement identity, when one already exists outside the graph. */
310
+ readonly clipEntityId?: string;
311
+ }
312
+ interface SetClipPlacementInput {
313
+ readonly clipEntityId: string;
314
+ readonly placement: ClipPlacement;
315
+ }
316
+ type SequentialClipAnchor = {
317
+ readonly position: 'before' | 'after';
318
+ readonly clipEntityId: string;
319
+ } | {
320
+ readonly position: 'trackStart';
321
+ };
322
+ interface MoveSequentialClipsInput {
323
+ readonly clipEntityIds: readonly string[];
324
+ readonly anchor: SequentialClipAnchor;
325
+ readonly onAnchored: 'follow' | 'keepAbsolute';
326
+ }
327
+ interface MoveClipsToStartsInput {
328
+ readonly moves: readonly {
329
+ readonly clipEntityId: string;
330
+ readonly newStartMs: number;
331
+ }[];
332
+ /** Absolute-time drags preserve every voiceover's current visible landing. */
333
+ readonly onAnchored: 'keepAbsolute';
334
+ }
335
+ interface DeleteClipTreeInput {
336
+ readonly clipEntityIds: readonly string[];
337
+ readonly onAnchored: 'cascade' | 'detach';
338
+ }
339
+ interface VoiceoverCaptionFact {
340
+ /** Stable placed caption identity supplied by the materialized side effect. */
341
+ readonly captionClipEntityId: string;
342
+ /** Ordered selection of AudioScript segments; caption text is never passed inline. */
343
+ readonly selections: readonly CaptionSegmentSelection[];
344
+ readonly startMs: number;
345
+ readonly durationMs: number;
346
+ readonly style?: CaptionStyleFields;
347
+ }
348
+ type VoiceoverTakeInput = {
349
+ readonly timelineEntityId: string; /** Stable placed speech identity, distinct from media.assetId. */
350
+ readonly voiceoverClipEntityId: string;
351
+ readonly media: VoiceMediaAssetFact; /** Existing pronunciation variant; its composed AudioScript stays the text owner. */
352
+ readonly phoneticScriptEntityId: string;
353
+ readonly volume: number;
354
+ readonly captions: readonly VoiceoverCaptionFact[];
355
+ } & ({
356
+ readonly placement: ClipPlacement;
357
+ readonly hostClipEntityId?: never;
358
+ readonly anchorOffset?: never;
359
+ } | {
360
+ readonly placement?: never;
361
+ readonly hostClipEntityId: string;
362
+ readonly anchorOffset: number;
363
+ });
364
+ type VisualMediaAssetFact = ImageMediaAssetFact | VideoMediaAssetFact;
365
+ interface InsertMediaClipInput {
366
+ readonly timelineEntityId: string;
367
+ readonly clipEntityId?: string;
368
+ readonly media: VisualMediaAssetFact;
369
+ /** Source/display window in whole milliseconds. Images use this as their finite display span. */
370
+ readonly sourceRange: SequenceRange<number>;
371
+ readonly placement: ClipPlacement;
372
+ readonly volume?: number;
373
+ }
374
+ interface ReplaceMediaClipInput {
375
+ readonly clipEntityId: string;
376
+ readonly media: VisualMediaAssetFact;
377
+ readonly sourceRange: SequenceRange<number>;
378
+ }
379
+ interface ReplacementMediaClipInput {
380
+ readonly clipEntityId?: string;
381
+ readonly media: VisualMediaAssetFact;
382
+ readonly sourceRange: SequenceRange<number>;
383
+ readonly volume?: number;
384
+ }
385
+ type MediaClipInsertion = {
386
+ readonly kind: 'before';
387
+ readonly clipEntityId: string;
388
+ } | {
389
+ readonly kind: 'after';
390
+ readonly clipEntityId: string;
391
+ } | {
392
+ readonly kind: 'firstStart';
393
+ readonly startMs: number;
394
+ };
395
+ interface InsertMediaClipsInput {
396
+ readonly timelineEntityId: string;
397
+ readonly clips: readonly ReplacementMediaClipInput[];
398
+ /** One placement decision for the whole input-ordered block. */
399
+ readonly insertion: MediaClipInsertion;
400
+ }
401
+ interface ReplaceSequentialClipsInput {
402
+ readonly timelineEntityId: string;
403
+ readonly oldClipEntityIds: readonly string[];
404
+ readonly newClips: readonly ReplacementMediaClipInput[];
405
+ readonly onAnchored: 'remap' | 'cascade';
406
+ }
407
+ interface SetClipVolumeInput {
408
+ readonly clipEntityId: string;
409
+ /** Playback gain in decibels. */
410
+ readonly volume: number;
411
+ }
412
+ interface LinearClipSpeed {
413
+ readonly kind: 'linear';
414
+ readonly rate: number;
415
+ readonly mode?: string;
416
+ }
417
+ interface SetClipSpeedInput {
418
+ readonly clipEntityId: string;
419
+ readonly timeRemapping: LinearClipSpeed | null;
420
+ }
421
+ interface TrimClipInput {
422
+ readonly clipEntityId: string;
423
+ readonly sourceRange: SequenceRange<number>;
424
+ }
425
+ interface VoiceoverTakeResult {
426
+ readonly voiceoverClipEntityId: string;
427
+ readonly voiceEntityId: string;
428
+ /** The pronunciation variant the Voice was rendered from. */
429
+ readonly phoneticScriptEntityId: string;
430
+ /** The base-text owner resolved along the phonetic composition Relation. */
431
+ readonly audioScriptEntityId: string;
432
+ readonly captionClipEntityIds: readonly string[];
433
+ }
434
+ interface MoveVoiceoverInput {
435
+ readonly voiceoverClipEntityId: string;
436
+ /** Absolute requested timeline start; MEngine resolves and persists the host relation. */
437
+ readonly newStartMs: number;
438
+ }
439
+ interface DeleteVoiceoverInput {
440
+ readonly voiceoverClipEntityIds: readonly string[];
441
+ }
442
+ interface SetBgmInput {
443
+ readonly timelineEntityId: string;
444
+ readonly bgmClipEntityId: string;
445
+ readonly media: AudioMediaAssetFact;
446
+ readonly volume: number;
447
+ }
448
+ interface DeleteBgmInput {
449
+ readonly timelineEntityId: string;
450
+ }
451
+ interface SetCaptionVisibilityInput {
452
+ readonly timelineEntityId: string;
453
+ readonly hidden: boolean;
454
+ }
455
+ interface PatchCaptionStyleInput {
456
+ readonly timelineEntityId: string;
457
+ readonly style: CaptionStyleFields;
458
+ }
459
+ interface InsertCaptionClipInput {
460
+ readonly timelineEntityId: string;
461
+ /** Stable placed caption identity, distinct from the Caption content identity. */
462
+ readonly captionClipEntityId?: string;
463
+ /** Existing base-text owner; the Caption composes it instead of storing text. */
464
+ readonly audioScriptEntityId: string;
465
+ /** Ordered selection of the AudioScript segments this Caption displays. */
466
+ readonly selections: readonly CaptionSegmentSelection[];
467
+ /** Intrinsic cue length of the Caption entity itself; display comes from the placement. */
468
+ readonly durationMs: number;
469
+ readonly style?: CaptionStyleFields;
470
+ readonly placement: ClipPlacement;
471
+ }
472
+ interface InsertClipInput {
473
+ readonly trackEntityId: string;
474
+ /** Existing Sequence media Entity id. Asset ids and URLs are not content ids. */
475
+ readonly contentEntityId: string;
476
+ readonly sourceRange: SequenceRange<number>;
477
+ readonly duration: SequenceDuration<number>;
478
+ readonly targetRange?: SequenceRange<number>;
479
+ readonly clipPayload?: JsonObject;
480
+ }
481
+ interface UpdateClipMarkerInput {
482
+ readonly clipEntityId: string;
483
+ readonly sourceRange?: SequenceRange<number>;
484
+ /** Passing `undefined` explicitly removes the optional target range. */
485
+ readonly targetRange?: SequenceRange<number> | undefined;
486
+ readonly duration?: SequenceDuration<number>;
487
+ /** Passing `undefined` explicitly removes the optional remapping value. */
488
+ readonly timeRemapping?: JsonValue | undefined;
489
+ }
490
+ interface MoveClipInput {
491
+ readonly clipEntityId: string;
492
+ readonly trackEntityId: string;
493
+ }
494
+ interface ReplaceClipContentInput {
495
+ readonly clipEntityId: string;
496
+ /** Existing Sequence media Entity id. Asset ids and URLs are not content ids. */
497
+ readonly contentEntityId: string;
498
+ readonly sourceRange: SequenceRange<number>;
499
+ readonly duration: SequenceDuration<number>;
500
+ readonly targetRange?: SequenceRange<number>;
501
+ readonly timeRemapping?: JsonValue;
502
+ }
503
+ interface DeleteClipInput {
504
+ readonly clipEntityId: string;
505
+ }
506
+ interface UpdateClipInput {
507
+ readonly clipEntityId: string;
508
+ /** Complete replacement for the Clip-owned payload. */
509
+ readonly payload: JsonObject;
510
+ }
511
+ type ClipEntityId = EntityId;
512
+ //#endregion
513
+ //#region src/entity-editor/entity-timeline-editor.d.ts
514
+ /**
515
+ * Graph-native timeline authoring over authoritative Medeo Entity and Relation rows.
516
+ *
517
+ * Each mutation is applied to a detached graph, validated as a complete DSL set,
518
+ * and committed only after validation succeeds.
519
+ */
520
+ declare class EntityTimelineEditor {
521
+ private readonly idFactory;
522
+ private state;
523
+ constructor(initialRows: EntityRelationRows, idFactory?: EntityTimelineIdFactory);
524
+ rows(): EntityRelationRows;
525
+ insertClip(input: InsertClipInput): ClipEntityId;
526
+ insertPlacedClip(input: InsertPlacedClipInput): ClipEntityId;
527
+ updateClipMarker(input: UpdateClipMarkerInput): void;
528
+ setClipPlacement(input: SetClipPlacementInput): void;
529
+ moveSequentialClips(input: MoveSequentialClipsInput): void;
530
+ moveClipsToStarts(input: MoveClipsToStartsInput): void;
531
+ moveClip(input: MoveClipInput): void;
532
+ replaceClipContent(input: ReplaceClipContentInput): void;
533
+ insertMediaClip(input: InsertMediaClipInput): ClipEntityId;
534
+ insertMediaClips(input: InsertMediaClipsInput): readonly ClipEntityId[];
535
+ replaceMediaClip(input: ReplaceMediaClipInput): void;
536
+ setClipVolume(input: SetClipVolumeInput): void;
537
+ setClipSpeed(input: SetClipSpeedInput): void;
538
+ trimClip(input: TrimClipInput): void;
539
+ replaceSequentialClips(input: ReplaceSequentialClipsInput): readonly ClipEntityId[];
540
+ deleteClip(input: DeleteClipInput): void;
541
+ deleteClipTree(input: DeleteClipTreeInput): void;
542
+ updateClip(input: UpdateClipInput): void;
543
+ upsertVoiceoverTake(input: VoiceoverTakeInput): VoiceoverTakeResult;
544
+ moveVoiceover(input: MoveVoiceoverInput): void;
545
+ deleteVoiceover(input: DeleteVoiceoverInput): void;
546
+ setBgm(input: SetBgmInput): ClipEntityId;
547
+ deleteBgm(input: DeleteBgmInput): void;
548
+ setCaptionVisibility(input: SetCaptionVisibilityInput): void;
549
+ patchCaptionStyle(input: PatchCaptionStyleInput): void;
550
+ /**
551
+ * Place a Caption as a composed variant of an existing AudioScript: the
552
+ * entity stores only its selection, style, and inherent cue-bounded
553
+ * Sequence — never text. The Clip and its display Marker describe this use;
554
+ * moving or stretching the returned Clip later changes the Clip/Marker,
555
+ * never the Caption entity or the AudioScript.
556
+ */
557
+ insertCaptionClip(input: InsertCaptionClipInput): ClipEntityId;
558
+ private insertPlacedClipIntoDraft;
559
+ private ensureRoleTrack;
560
+ /** The existing pronunciation variant a Voice consumes; composition is required. */
561
+ private requireComposedPhoneticScript;
562
+ /** Preserve the factual synthesis input, regardless of persisted endpoint positions. */
563
+ private ensurePhoneticRender;
564
+ private reconcileVoiceoverCaptions;
565
+ private ensureRoleTrackForClip;
566
+ private replaceCaptionSemanticRelations;
567
+ /**
568
+ * Remove one placed Caption use. The composed AudioScript outlives the
569
+ * caption: it may anchor further captions and remains the text owner.
570
+ */
571
+ private removeCaptionClipGraph;
572
+ private replaceAnchorHost;
573
+ /** Rebuild the legacy edit baseline from current visual order before a high-level cascade. */
574
+ private normalizeMainSequential;
575
+ private resolveOneVoiceoverOverlap;
576
+ private applyClipPlacement;
577
+ private reanchorAtAbsolute;
578
+ private removeAnchoredDescendants;
579
+ private removeClipGraph;
580
+ private transact;
581
+ private mintEntityId;
582
+ private createRelation;
583
+ private relinkRelation;
584
+ private mintRelationId;
585
+ }
586
+ //#endregion
587
+ //#region src/entity-editor/editor-resources.d.ts
588
+ declare const roleOrder: {
589
+ readonly caption: 0;
590
+ readonly video_clip: 1;
591
+ readonly speech: 2;
592
+ readonly bgm: 3;
593
+ };
594
+ type EditorTrackRole = keyof typeof roleOrder;
595
+ interface EditorFoundation {
596
+ readonly rows: EntityRelationRows;
597
+ readonly timelineEntityId: string;
598
+ readonly trackEntityIds: Readonly<Record<EditorTrackRole, string>>;
599
+ }
600
+ /**
601
+ * MEngine editor policy, not a cardinality restriction on the general-purpose DSL.
183
602
  *
184
- * The authoritative online producers — agent-harness (`@harness/shared`
185
- * `genObjId`) and director.v2 (`common/obj_id.py` `gen_obj_id`) — both mint part
186
- * ids as `` `${prefix}_${ulid()}` ``, and real captured drafts use exactly that
187
- * shape (`clip_…` / `spe_…` / `cap_…` / `bgm_…`, each a 26-char ULID). The engine
188
- * previously emitted `vc_<base36 timestamp><6 random>`, a different prefix AND a
189
- * different encoding — the sole cross-repo id divergence. This module removes it
190
- * by emitting the same `<prefix>_<ULID>` bytes.
603
+ * Media variants share one entity identity with their Asset: every
604
+ * Image/Video/Audio/Voice Entity must carry its own external locator, every
605
+ * external asset id has exactly one claimant, and no media variant may be
606
+ * bound through a legacy `physical-asset` Relation. Dual-entity media graphs
607
+ * are rejected, not migrated. Caption composes AudioScript text and has no physical text Asset.
608
+ */
609
+ declare function assertCanonicalEditorResources(rows: EntityRelationRows): void;
610
+ /**
611
+ * Commit-transition policy shared by the editor, the HTTP commit boundary, the
612
+ * host tool, and the entity stores. It compares the authoritative before and
613
+ * after rows of one CAS commit and enforces the single-identity write rules
614
+ * on the complete after state, with no exemption for historical graphs:
191
615
  *
192
- * The ULID is generated inline (Crockford Base32, 48-bit time + 80-bit random)
193
- * rather than pulling the `ulid` npm package: the randomness class matches the
194
- * old generator (both `Math.random`-based) and it keeps `@mengine/medeo-client`
195
- * dependency-free for a purely mechanical id string. Part ids only need to be
196
- * unique and lexicographically time-sortable, which this satisfies.
616
+ * 1. every Image/Video/Audio/Voice Entity carries its own Asset `external`
617
+ * identity;
618
+ * 2. no `physical-asset` Relation may bind a media variant or Caption;
619
+ * 3. a self-carried media identity is immutable — it cannot be rewritten to
620
+ * another asset id.
621
+ *
622
+ * Dual-entity media graphs are rejected instead of being migrated or merged
623
+ * implicitly. Deleting media is explicit and allowed.
197
624
  */
625
+ declare function assertMediaAssetWritePolicy(before: EntityRelationRows, after: EntityRelationRows): void;
626
+ /** Add only missing editor structure; existing identities and owned settings are never replaced. */
627
+ declare function ensureEditorFoundation(initial: EntityRelationRows, idFactory?: EntityTimelineIdFactory, timelinePayload?: EntityRow['payload']): EditorFoundation;
628
+ //#endregion
629
+ //#region src/entity-editor/media-asset-import.d.ts
630
+ interface ImportedMediaAsset {
631
+ readonly rows: EntityRelationRows;
632
+ /** The single media variant identity for this asset id; it is its own Asset. */
633
+ readonly contentEntityId: string;
634
+ }
635
+ /**
636
+ * Import at the editor boundary, not at asset generation time. Existing
637
+ * provenance is retained.
638
+ *
639
+ * A media variant is a logical facet of its Asset and shares one entity
640
+ * identity: the import mints exactly one entity of the media kind that carries
641
+ * the external locator itself, and deduplicates only against existing variants
642
+ * that already carry the same `(system, key)`. Legacy dual-entity graphs
643
+ * (`asset` row plus a `physical-asset` binding) are not reused and are
644
+ * rejected by the canonical resource policy instead of being migrated.
645
+ */
646
+ declare function importMediaAsset(initial: EntityRelationRows, fact: MediaAssetFact, idFactory?: EntityTimelineIdFactory): ImportedMediaAsset;
647
+ //#endregion
648
+ //#region src/entity-editor/legacy-entity-migration.d.ts
649
+ /** One-time import only. Ordinary editor operations must never reverse-diff a legacy document. */
650
+ declare function migrateLegacyTimelineToEntities(legacy: VideoDocument, assetFacts: readonly MediaAssetFact[], initial?: EntityRelationRows, idFactory?: EntityTimelineIdFactory): EntityRelationRows;
651
+ /** Server gate: a cutover may change representation, never the existing render facts. */
652
+ declare function assertEntityProjectionPreservesLegacy(legacy: VideoDocument, projection: VideoDocument, rows: EntityRelationRows): void;
653
+ //#endregion
654
+ //#region src/editor/journal.d.ts
655
+ /**
656
+ * Wire a plain-memory adapter + editor that share a recording id factory, so
657
+ * every mutating transact lands in `journal` with ordered `generated_ids`.
658
+ */
659
+ declare function createEditSandbox(document: VideoDocument, options?: PlainMemoryAdapterOptions): {
660
+ adapter: PlainMemoryAdapter;
661
+ editor: SemanticEditor;
662
+ journal: readonly JournalEntry[];
663
+ };
198
664
  /**
199
- * Online part-id semantic prefixes. `clip` (video clip) is the only value the
200
- * engine currently mints (see `addVideoClips`); the rest are declared so the
201
- * type documents the shared vocabulary and guards against reintroducing the old
202
- * `vc`/`sp`/`cp`/`bg` names. Speech/caption/bgm ids arrive pre-minted in op
203
- * payloads, so the engine never generates them itself.
665
+ * Re-drive `doc` from a recorded journal, forcing each entry's `generated_ids`
666
+ * through a queue-backed id factory. Never mints fresh ids: an empty queue on
667
+ * demand throws `unrecorded id`; leftover ids after an entry throws
668
+ * `unconsumed ids`. Legacy entries without `generated_ids` are treated as `[]`.
204
669
  */
205
- type PartIdPrefix = 'clip' | 'spe' | 'cap' | 'bgm' | 'ti';
206
- declare function generatePartId(prefix: PartIdPrefix): string;
670
+ declare function replayJournal(doc: SemanticDocumentAdapter, journal: readonly JournalEntry[]): Promise<void>;
207
671
  //#endregion
208
672
  //#region src/editor/snapshot-utils.d.ts
209
673
  /** Main-track item identity read from a raw snapshot (only `part_id` is needed). */
@@ -296,9 +760,7 @@ type PushResultKind = 'ack' | 'duplicate' | 'rejected' | 'failed' | 'nothing_to_
296
760
  */
297
761
  interface PushResult {
298
762
  kind: PushResultKind;
299
- /** Server document sequence observed after a successful `ack` or `duplicate`. */
300
- mengineUpdateSeq?: number | undefined;
301
- /** @deprecated Ack-only sequence retained until consumers adopt `mengineUpdateSeq`. */
763
+ /** Server-allocated sequence number; only present for `ack`. */
302
764
  updateSeq?: number | undefined;
303
765
  /** Whether the server held ops the local document lacked. See above. */
304
766
  collaborated: boolean;
@@ -424,6 +886,16 @@ declare class ManualSyncDoc {
424
886
  editorPeerId(): PeerID;
425
887
  /** Current document projected to the legacy `VideoDraft` read shape. */
426
888
  draft(): VideoDraft;
889
+ /**
890
+ * Replay a deterministic sandbox journal into this document.
891
+ *
892
+ * The adapter stays private so callers cannot bypass the manual-sync
893
+ * lifecycle; journal replay is the one host-side operation that needs the
894
+ * adapter's transaction boundary and recorded id queue. Durability is still
895
+ * explicit: call {@link push} after replay and report success only from its
896
+ * verdict.
897
+ */
898
+ replayJournal(journal: readonly JournalEntry[]): Promise<void>;
427
899
  /**
428
900
  * Mark the document state the caller has just observed, for a later
429
901
  * {@link hasChangedSince}.
@@ -577,9 +1049,6 @@ declare class MedeoHttpDocStorage implements DocStorage {
577
1049
  * tool-level ack wait) subscribe here.
578
1050
  */
579
1051
  subscribePushOutcome(callback: (outcome: PushOutcome) => void): () => void;
580
- /** Authoritative HTTP reads and accepted pushes, never inferred from SSE bytes. */
581
- subscribeServerVersion(callback: (version: Uint8Array) => void): () => void;
582
- private reportServerVersion;
583
1052
  deleteDoc(_docId: string): Promise<void>;
584
1053
  subscribeDocUpdate(callback: (update: DocUpdate, origin: unknown) => void): () => void;
585
1054
  private assertDocId;
@@ -628,14 +1097,6 @@ interface WaitForServerAckOptions {
628
1097
  /** Deadline in ms. Rejects with reason `timeout` when it elapses. */
629
1098
  timeoutMs?: number;
630
1099
  }
631
- /** Document-level confirmation is independent of local operation completion. */
632
- interface MengineDocSyncState {
633
- /** Remote-only imports do not create a new local confirmation obligation. */
634
- readonly confirmation: 'unknown' | 'pending' | 'confirmed';
635
- /** Transport/activity phase. Idle does not imply confirmation; failure details
636
- * remain available through push outcomes and confirmation wait errors. */
637
- readonly phase: 'connecting' | 'idle' | 'syncing' | 'offline' | 'failed';
638
- }
639
1100
  interface MengineDocSessionOptions {
640
1101
  docId: string;
641
1102
  client: MengineHttpClient;
@@ -646,6 +1107,11 @@ interface MengineDocSessionOptions {
646
1107
  */
647
1108
  localStorage?: DocStorageLike;
648
1109
  sseReconnectDelayMs?: number;
1110
+ /**
1111
+ * Keep remote synchronization read-only: pull snapshot/diffs and subscribe to
1112
+ * SSE updates, but never POST local Loro updates to the server.
1113
+ */
1114
+ readonlyMode?: boolean;
649
1115
  }
650
1116
  /**
651
1117
  * A live editing session for one Medeo document — the single entry point clients
@@ -681,14 +1147,8 @@ declare class MengineDocSession {
681
1147
  private adapterValue;
682
1148
  private editorValue;
683
1149
  private started;
684
- private destroyed;
685
- private lifetime;
686
- private hasConnected;
687
- private initialVersionValue;
688
- private localVersionValue;
689
- private pushErrorValue;
690
1150
  /**
691
- * Latest server oplog version seen on an authoritative HTTP response. Lets `waitForServerAck`
1151
+ * Latest server oplog version seen on a push outcome. Lets `waitForServerAck`
692
1152
  * return without waiting when the server is already known to cover the local
693
1153
  * doc (e.g. nothing was edited since the last confirmed push).
694
1154
  */
@@ -703,14 +1163,14 @@ declare class MengineDocSession {
703
1163
  */
704
1164
  subscribePushOutcome(callback: (outcome: PushOutcome) => void): () => void;
705
1165
  /**
706
- * Resolve once the server has durably accepted the local commits as of
1166
+ * Resolve once the server has durably accepted the local document state as of
707
1167
  * *now* — the capability an Agent tool needs to answer "did my edit land?"
708
1168
  * before reporting success.
709
1169
  *
710
1170
  * Call it right after the editor ops whose durability matters. It snapshots the
711
- * latest local commit's version (or the loaded baseline before any edit) and
712
- * resolves when an authoritative server version covers it. Remote-only
713
- * imports do not extend this target, matching the displayed confirmation state.
1171
+ * local doc's current version and resolves on the first push outcome whose
1172
+ * `serverVV` covers that version, i.e. the server log is at least as advanced as
1173
+ * the local doc was when this was called.
714
1174
  *
715
1175
  * Version coverage, not byte identity, is the acceptance test — for two reasons:
716
1176
  * the ops may reach the server inside a merged blob rather than as the exact
@@ -732,6 +1192,18 @@ declare class MengineDocSession {
732
1192
  * step. The committed change drives DocManager's local-update push.
733
1193
  */
734
1194
  get editor(): SemanticEditor;
1195
+ /**
1196
+ * Opaque version token of the local oplog (base64 `VersionVector.encode`).
1197
+ * Equality-comparable only: equal means no observed change (local or
1198
+ * remote-arrived) since the token was taken. Throws when not started.
1199
+ */
1200
+ version(): string;
1201
+ /**
1202
+ * The live document adapter, exposed for journal replay (commit channel).
1203
+ * Replaying through it still goes SemanticEditor → Loro → mengine-server —
1204
+ * no write bypass. Typed by the narrow interface on purpose.
1205
+ */
1206
+ get documentAdapter(): SemanticDocumentAdapter;
735
1207
  /** Current document snapshot (read model). */
736
1208
  snapshot(): VideoDocument;
737
1209
  /**
@@ -742,11 +1214,6 @@ declare class MengineDocSession {
742
1214
  * surfaces through `subscribe`.
743
1215
  */
744
1216
  start(): Promise<VideoDocument>;
745
- getSyncState(): MengineDocSyncState;
746
- private confirmationTarget;
747
- /** Immediately supplies current state; unsubscribe when the host changes docs. */
748
- subscribeSyncState(cb: (state: MengineDocSyncState) => void): () => void;
749
- private emitSyncState;
750
1217
  subscribe(cb: (event: MengineDocSessionUpdateEvent) => void): () => void;
751
1218
  onStateChange(cb: (state: DocState) => void): () => void;
752
1219
  getState(): DocState;
@@ -1088,4 +1555,4 @@ declare function hostForAbsMs(ranges: MainClipRange[], absMs: number): MainClipR
1088
1555
  */
1089
1556
  declare function relativePositionForAbs(ranges: MainClipRange[], absMs: number): TrackItemTimePosition;
1090
1557
  //#endregion
1091
- export { type Aggregation, type Attachment, type BgmPart, type CaptionPart, type CaptionStyle, type CommitOptions, DEFAULT_UNIT_TIME_MS, type DerivedItemPosition, type DocStorageLike, type DocVersionMark, IMPLEMENTED_SEMANTIC_OP_KINDS, type ImplementedSemanticOpKind, type InitialDocumentFacts, LANE_KINDS_IN_STACK_ORDER, type LaneKind, type MainClipRange, type MakeEmptyPart, ManualSyncDoc, type ManualSyncDocOptions, MedeoHttpDocStorage, type MedeoHttpDocStorageOptions, MemoryDocStorage, MengineAckFailedError, type MengineAuditEntry, type MengineAuditResponse, MengineDocSession, type MengineDocSessionOptions, type MengineDocSessionUpdateEvent, type MengineDocSyncState, type MengineDocumentVersion, type MengineEventStreamOptions, MengineHttpClient, type MengineHttpClientOptions, MengineHttpRequestError, MenginePushRejectedError, type MenginePushResponse, type MenginePushUpdateResponse, type MengineRejectedResponse, type MengineSnapshotResponse, type MengineSseUpdateEvent, type MengineSyncResponse, type MengineUpdateMeta, MirrorVideoDocumentAdapter, type MirrorVideoDocumentOptions, type OpActor, type PartAggregation, type PartKind, type PartUnion, type PlannedSemanticOpKind, type PullFailureReason, type PullResult, type PushOutcome, type PushOutcomeKind, type PushResult, type PushResultKind, SchemaValidator, type SemanticDocumentAdapter, SemanticEditor, type SemanticOpInput, type SemanticOpKind, type SemanticOpName, type SnapshotReadable, type SolvedVideoDocument, type SpeechHostMap, type SpeechPart, type SpeedShift, TIMELINE_SKELETON_DURATION_MS, type Timeline, type TimelineDoc, type TimelineItem, type Track, type TrackDraft, type TrackItem, type TrackItemDraft, type TrackItemTimePosition, type TransactAudit, VIDEO_DOCUMENT_SCHEMA_VERSION, ValidationError, type VideoClipPart, type VideoDocument, type VideoDocumentDraft, type VideoDocumentMirrorSchema, type VideoDocumentSchemaVersion, VideoDocumentValidationError, type VideoDocumentValidationIssue, type VideoDocumentValidationIssueCode, type VideoDraft, type CaptionPart$1 as VideoDraftCaptionPart, type VideoDraftPartUnion, type Timeline$1 as VideoDraftTimeline, type Track$1 as VideoDraftTrack, type TrackItem$1 as VideoDraftTrackItem, type WaitForServerAckOptions, arrangeMainTrackSeamlessly, assertValidVideoDocument, base64ToBytes, buildInitialVideoDocument, buildSpeechHostMap, bytesToBase64, cascadeAfterVideoClipChanges, createMirrorVideoDocument, createMirrorVideoDocumentAdapter, decodeDocVersionMark, derivePositionFromAbs, encodeDocVersionMark, ensureLaneTrack, fillMainTrackTimeGaps, findLaneTrack, fromVideoDocument, generatePartId, getAt, hostForAbsMs, isEmptyVideoClip, isImplementedSemanticOpKind, isMap, laneTrackId, mainTrackRanges, partDurationMs, partUnionSchema, readMainTrackItems, readMengineEventStream, readPart, readPartDurationMs, readVideoDocumentFromDraft, reassignSpeechesToVideoClipsByTime, recalculateTimelineDuration, relativePositionForAbs, resolveAllSpeechOverlaps, resolveSpeechOverlapByShiftingVideos, safeDurationMs, index_d_exports as schemas, snapshotToPlain, solveVideoDocument, syncAggregatedClipsTimePosition, toVideoDocument, validateVideoDocument, videoDocumentMirrorSchema, videoDocumentSchema };
1558
+ export { type Aggregation, type AssembledCaptionContent, type AssembledPhoneticScriptContent, type Attachment, type AudioMediaAssetFact, type BgmPart, type CaptionPart, type CaptionSegmentSelection, type CaptionStyle, type ClipEntityId, type ClipPlacement, type CommitOptions, DEFAULT_UNIT_TIME_MS, type DeleteBgmInput, type DeleteClipInput, type DeleteClipTreeInput, type DeleteVoiceoverInput, type DerivedItemPosition, type DocStorageLike, type DocVersionMark, ENTITY_TIMELINE_PROJECTION_SCHEMA_VERSION, type EditorFoundation, type EntityGraphCommitOptions, EntityGraphHttpClient, type EntityGraphState, EntityTimelineEditor, type EntityTimelineIdFactory, EntityTimelineProjectionError, type EntityTimelineTrackRole, IMPLEMENTED_SEMANTIC_OP_KINDS, type ImageMediaAssetFact, type ImplementedSemanticOpKind, type ImportedMediaAsset, type InitialDocumentFacts, type InsertCaptionClipInput, type InsertClipInput, type InsertMediaClipInput, type InsertMediaClipsInput, type InsertPlacedClipInput, type JournalEntry, LANE_KINDS_IN_STACK_ORDER, type LaneKind, type LinearClipSpeed, type MainClipRange, type MakeEmptyPart, ManualSyncDoc, type ManualSyncDocOptions, MedeoHttpDocStorage, type MedeoHttpDocStorageOptions, type MediaAssetFact, type MediaClipInsertion, MemoryDocStorage, MengineAckFailedError, type MengineAuditEntry, type MengineAuditResponse, MengineDocSession, type MengineDocSessionOptions, type MengineDocSessionUpdateEvent, type MengineDocumentVersion, type MengineEventStreamOptions, MengineHttpClient, type MengineHttpClientOptions, MengineHttpRequestError, MenginePushRejectedError, type MenginePushResponse, type MenginePushUpdateResponse, type MengineRejectedResponse, type MengineSnapshotResponse, type MengineSseUpdateEvent, type MengineSyncResponse, type MengineUpdateMeta, MirrorVideoDocumentAdapter, type MirrorVideoDocumentOptions, type MoveClipInput, type MoveClipsToStartsInput, type MoveSequentialClipsInput, type MoveVoiceoverInput, type OpActor, type PartAggregation, type PartIdFactory, type PartKind, type PartUnion, type PatchCaptionStyleInput, PlainMemoryAdapter, type PlainMemoryAdapterOptions, type PlannedSemanticOpKind, type PullFailureReason, type PullResult, type PushOutcome, type PushOutcomeKind, type PushResult, type PushResultKind, type ReplaceClipContentInput, type ReplaceMediaClipInput, type ReplaceSequentialClipsInput, type ReplacementMediaClipInput, type ResolvedEntityClipPlacement, type ResolvedEntityTimelineLayout, type ResolvedEntityTrack, SchemaValidator, ScriptCompositionError, type SemanticDocumentAdapter, SemanticEditor, type SemanticOpInput, type SemanticOpKind, type SemanticOpName, type SequentialClipAnchor, type SetBgmInput, type SetCaptionVisibilityInput, type SetClipPlacementInput, type SetClipSpeedInput, type SetClipVolumeInput, type SnapshotReadable, type SolvedVideoDocument, type SpeechHostMap, type SpeechPart, type SpeedShift, TIMELINE_SKELETON_DURATION_MS, type Timeline, type TimelineDoc, type TimelineItem, type Track, type TrackDraft, type TrackItem, type TrackItemDraft, type TrackItemTimePosition, type TransactAudit, type TrimClipInput, type UpdateClipInput, type UpdateClipMarkerInput, VIDEO_DOCUMENT_SCHEMA_VERSION, ValidationError, type VideoClipPart, type VideoDocument, type VideoDocumentDraft, type VideoDocumentMirrorSchema, type VideoDocumentSchemaVersion, VideoDocumentValidationError, type VideoDocumentValidationIssue, type VideoDocumentValidationIssueCode, type VideoDraft, type CaptionPart$1 as VideoDraftCaptionPart, type VideoDraftPartUnion, type Timeline$1 as VideoDraftTimeline, type Track$1 as VideoDraftTrack, type TrackItem$1 as VideoDraftTrackItem, type VideoMediaAssetFact, type VisualMediaAssetFact, type VoiceMediaAssetFact, type VoiceoverCaptionFact, type VoiceoverTakeInput, type VoiceoverTakeResult, type WaitForServerAckOptions, applyEntityTimelineProjection, arrangeMainTrackSeamlessly, assembleCaptionContent, assemblePhoneticScriptContent, assembleScriptText, assertCanonicalEditorResources, assertEntityProjectionPreservesLegacy, assertMediaAssetWritePolicy, assertValidVideoDocument, base64ToBytes, buildInitialVideoDocument, buildSpeechHostMap, bytesToBase64, cascadeAfterVideoClipChanges, createEditSandbox, createMirrorVideoDocument, createMirrorVideoDocumentAdapter, createPlainMemoryAdapter, decodeDocVersionMark, derivePositionFromAbs, effectiveVideoClipDurationMs, encodeDocVersionMark, ensureEditorFoundation, ensureLaneTrack, fillMainTrackTimeGaps, findComposedAudioScript, findLaneTrack, fromVideoDocument, generatePartId, getAt, hostForAbsMs, importMediaAsset, isEmptyVideoClip, isImplementedSemanticOpKind, isMap, laneTrackId, mainTrackRanges, migrateLegacyTimelineToEntities, partDurationMs, partUnionSchema, projectEntityTimeline, readMainTrackItems, readMengineEventStream, readPart, readPartDurationMs, readVideoDocumentFromDraft, reassignSpeechesToVideoClipsByTime, recalculateTimelineDuration, relativePositionForAbs, replayJournal, resolveAllSpeechOverlaps, resolveEntityTimelineLayout, resolveSpeechOverlapByShiftingVideos, safeDurationMs, index_d_exports as schemas, selectAudioScriptSegments, snapshotToPlain, solveVideoDocument, speedOf, syncAggregatedClipsTimePosition, toVideoDocument, validateVideoDocument, videoDocumentMirrorSchema, videoDocumentSchema, writeVideoDocumentToDraft };