@mengine/medeo-client 2.0.1-alpha.4 → 2.0.1-alpha.6

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,6 +1,7 @@
1
- import { $ as VideoDraft, A as assertValidVideoDocument, B as CaptionPart, C as index_d_exports, D as VideoDocumentMirrorSchema, E as VideoDocumentDraft, F as buildSpeechHostMap, G as Timeline, H as PartKind, I as derivePositionFromAbs, J as TrackItemTimePosition, K as Track, L as fromVideoDocument, M as buildInitialVideoDocument, N as DerivedItemPosition, O as videoDocumentMirrorSchema, P as SpeechHostMap, Q as VideoDocumentValidationIssueCode, R as toVideoDocument, S as ValidationError, T as TrackItemDraft, U as PartUnion, V as DEFAULT_UNIT_TIME_MS, W as SpeechPart, X as VideoDocument, Y as VideoClipPart, Z as VideoDocumentValidationIssue, _ as PlannedSemanticOpKind, a as MirrorVideoDocumentOptions, at as PartAggregation, b as SchemaValidator, c as CommitOptions, ct as Track$1, d as SemanticEditor, et as VideoDraftContent, f as SemanticOpInput, g as ImplementedSemanticOpKind, h as IMPLEMENTED_SEMANTIC_OP_KINDS, i as MirrorVideoDocumentAdapter, it as CaptionStyle, j as validateVideoDocument, k as VideoDocumentValidationError, l as OpActor, lt as TrackItem$1, m as TransactAudit, n as videoDocumentSchema, nt as Attachment, o as createMirrorVideoDocument, ot as SpeedShift, p as SemanticOpName, q as TrackItem, r as readVideoDocumentFromDraft, rt as CaptionPart$1, s as createMirrorVideoDocumentAdapter, st as Timeline$1, t as partUnionSchema, tt as VideoDraftPartUnion, u as SemanticDocumentAdapter, v as SemanticOpKind, w as TrackDraft, x as SnapshotReadable, y as isImplementedSemanticOpKind, z as BgmPart } from "./index-CnZ9l3rb.js";
1
+ import { t as index_d_exports } from "./index-CMa6ZCtX.js";
2
+ import { $ as SequenceRange, A as generatePartId, At as VideoDraft, B as ResolvedEntityClipPlacement, Bt as Track$1, C as PlannedSemanticOpKind, Ct as TrackItemTimePosition, D as SnapshotReadable, Dt as VideoDocumentSchemaVersion, E as SchemaValidator, Et as VideoDocument, F as videoDocumentMirrorSchema, Ft as CaptionPart$1, G as EntityTimelineProjectionError, H as ResolvedEntityTrack, I as VideoDocumentValidationError, It as CaptionStyle, J as RelationRow, K as EntityRelationRows, L as assertValidVideoDocument, Lt as PartAggregation, M as TrackItemDraft, Mt as effectiveVideoClipDurationMs, N as VideoDocumentDraft, Nt as speedOf, O as ValidationError, Ot as VideoDocumentValidationIssue, P as VideoDocumentMirrorSchema, Pt as Attachment, Q as SequenceDuration, R as validateVideoDocument, Rt as SpeedShift, S as ImplementedSemanticOpKind, St as TrackItem, T as isImplementedSemanticOpKind, Tt as VideoClipPart, U as resolveEntityTimelineLayout, V as ResolvedEntityTimelineLayout, Vt as TrackItem$1, W as projectEntityTimeline, X as CaptionStyleFields, Y as CaptionSegmentSelection, Z as ScriptTextSegment, _ as SemanticEditor, _t as PartKind, a as PlainMemoryAdapter, at as buildInitialVideoDocument, b as TransactAudit, bt as Timeline, c as MirrorVideoDocumentAdapter, ct as buildSpeechHostMap, d as createMirrorVideoDocument, dt as toVideoDocument, et as VoiceDescriptor, f as createMirrorVideoDocumentAdapter, ft as BgmPart, g as SemanticDocumentAdapter, gt as ENTITY_TIMELINE_PROJECTION_SCHEMA_VERSION, h as OpActor, ht as DEFAULT_UNIT_TIME_MS, i as JournalEntry, it as InitialDocumentFacts, j as TrackDraft, jt as VideoDraftPartUnion, k as PartIdFactory, kt as VideoDocumentValidationIssueCode, l as MirrorVideoDocumentOptions, lt as derivePositionFromAbs, m as CommitOptions, mt as CaptionPart, n as videoDocumentSchema, nt as JsonValue, o as PlainMemoryAdapterOptions, ot as DerivedItemPosition, p as writeVideoDocumentToDraft, pt as CaptionDisplayCue, q as EntityRow, r as readVideoDocumentFromDraft, rt as EntityId, s as createPlainMemoryAdapter, st as SpeechHostMap, t as partUnionSchema, tt as JsonObject, u as applyEntityTimelineProjection, ut as fromVideoDocument, v as SemanticOpInput, vt as PartUnion, w as SemanticOpKind, wt as VIDEO_DOCUMENT_SCHEMA_VERSION, x as IMPLEMENTED_SEMANTIC_OP_KINDS, xt as Track, y as SemanticOpName, yt as SpeechPart, z as EntityTimelineTrackRole, zt as Timeline$1 } from "./index-B31KeDzA.js";
2
3
  import { LoroDoc, PeerID } from "loro-crdt";
3
- import { DocState, LocalSaveState } from "@mengine/sync";
4
+ import { DocState } from "@mengine/sync";
4
5
  import { BaseDocStorage, Connection, DocDiff, DocPushReceipt, DocSnapshotRecord, DocStorage, DocStorageOptions, DocUpdate, DocUpdateRecord } from "@mengine/storage";
5
6
 
6
7
  //#region src/client/base64.d.ts
@@ -133,6 +134,7 @@ declare class MengineHttpClient {
133
134
  private readonly fetchImpl;
134
135
  constructor(options: MengineHttpClientOptions);
135
136
  fetchSnapshot(): Promise<MengineSnapshotResponse>;
137
+ bootstrapSnapshot(snapshot: Uint8Array): Promise<MengineSnapshotResponse>;
136
138
  /**
137
139
  * Loro VV-diff pull: send the caller's oplog `VersionVector.encode` as `from`
138
140
  * (omit for a full pull) and receive exactly the updates it is missing plus
@@ -173,38 +175,692 @@ interface MengineEventStreamOptions {
173
175
  /** Fired once the stream response is established (HTTP ok, body readable). */
174
176
  onOpen?(): void;
175
177
  onUpdate(event: MengineSseUpdateEvent): void;
176
- /** A committed update omitted from live transport; fetch the missing operations by VV. */
177
- onResync?(): void;
178
178
  }
179
179
  declare function readMengineEventStream(options: MengineEventStreamOptions): Promise<void>;
180
180
  //#endregion
181
- //#region src/editor/id-gen.d.ts
181
+ //#region ../medeo-dsl/src/composition.d.ts
182
+ type ScriptCompositionIssueCode = 'field_conflict' | 'composition_cycle' | 'invalid_bases' | 'composition_missing' | 'composition_ambiguous' | 'composition_dangling' | 'unknown_segment' | 'empty_selection' | 'invalid_script' | 'invalid_selection';
183
+ /** Assembly fails explicitly when declared bases cannot provide valid, unambiguous content. */
184
+ declare class ScriptCompositionError extends Error {
185
+ readonly code: ScriptCompositionIssueCode;
186
+ readonly entityId: EntityId;
187
+ constructor(code: ScriptCompositionIssueCode, entityId: EntityId, message: string);
188
+ }
189
+ interface AssembledCaptionContent {
190
+ readonly caption: EntityRow<'caption'>;
191
+ readonly audioScript: EntityRow<'audio-script'>;
192
+ /** Selected AudioScript segments in Caption selection order. */
193
+ readonly segments: readonly ScriptTextSegment[];
194
+ /** Complete display text: the selected segments' text joined in order. */
195
+ readonly text: string;
196
+ }
197
+ interface AssembledPhoneticScriptContent {
198
+ readonly phoneticScript: EntityRow<'phonetic-script'>;
199
+ readonly audioScript: EntityRow<'audio-script'>;
200
+ /** All AudioScript segments in script order; the pronunciation variant never reorders text. */
201
+ readonly segments: readonly ScriptTextSegment[];
202
+ /** Complete base text owned by the AudioScript. */
203
+ readonly text: string;
204
+ }
205
+ /** Validate all base providers before applying explicit own fields; ordering cannot resolve ambiguity. */
206
+ declare function assembleEntityContent(rows: EntityRelationRows, entityId: EntityId): EntityRow;
207
+ /** Find the actual AudioScript text owner through direct variant bases. */
208
+ declare function findComposedAudioScript(rows: EntityRelationRows, variantEntityId: EntityId, variantKind: 'caption' | 'phonetic-script'): EntityRow<'audio-script'>;
209
+ /** Join the whole AudioScript text in segment order. */
210
+ declare function assembleScriptText(script: EntityRow<'audio-script'>): string;
211
+ /** Assemble selected text after base-field validation and explicit variant overrides. */
212
+ declare function assembleCaptionContent(rows: EntityRelationRows, captionEntityId: EntityId): AssembledCaptionContent;
213
+ /**
214
+ * Assemble the complete Phonetic Script content for TTS: the composed
215
+ * AudioScript's base text plus the variant's own phoneme and prosody fields.
216
+ */
217
+ declare function assemblePhoneticScriptContent(rows: EntityRelationRows, phoneticScriptEntityId: EntityId): AssembledPhoneticScriptContent;
218
+ /** Select source text without creating another authoritative text field. */
219
+ declare function selectAudioScriptSegment(script: EntityRow<'audio-script'>, selection: CaptionSegmentSelection): ScriptTextSegment;
220
+ //#endregion
221
+ //#region src/entity-editor/entity-graph-http-client.d.ts
222
+ /** One authenticated revision of the authoritative Medeo Entity graph. */
223
+ interface EntityGraphState {
224
+ /** Current AudioScript content version attached to the project. */
225
+ readonly audioScriptEntityId: string;
226
+ readonly revision: number;
227
+ readonly loroSnapshot: string;
228
+ readonly rows: EntityRelationRows;
229
+ }
230
+ interface EntityGraphCommitOptions {
231
+ /** Server version vector proving the explicit legacy-to-Entity migration baseline. */
232
+ readonly migrationBaseVv?: string;
233
+ }
234
+ /** Browser-safe authenticated Loro client for a document's Entity graph. */
235
+ declare class EntityGraphHttpClient {
236
+ private readonly options;
237
+ private readonly transport;
238
+ private readonly endpoint;
239
+ constructor(options: MengineHttpClientOptions);
240
+ fetchState(): Promise<EntityGraphState>;
241
+ /**
242
+ * Compile edits against the original causal snapshot and publish native Loro operations.
243
+ *
244
+ * Deletion intent is derived from baseline IDs omitted from `nextRows`, so a
245
+ * transient create-then-remove never becomes a request to delete unknown
246
+ * persisted data.
247
+ */
248
+ commit(baseState: Pick<EntityGraphState, 'revision' | 'rows' | 'loroSnapshot'>, nextRows: EntityRelationRows, options?: EntityGraphCommitOptions): Promise<EntityGraphState>;
249
+ /** Send the same prepared bytes on retry; never recompile an unconfirmed edit. */
250
+ commitUpdate(update: string): Promise<EntityGraphState>;
251
+ private request;
252
+ }
253
+ //#endregion
254
+ //#region src/entity-editor/types.d.ts
255
+ /** Injectable domain-id mint shared by Entity and Relation authoring surfaces. */
256
+ type EntityTimelineIdFactory = (prefix: 'entity' | 'relation') => string;
257
+ interface ImageMediaAssetFact {
258
+ readonly assetId: string;
259
+ readonly kind: 'image';
260
+ readonly storageKey?: string;
261
+ }
262
+ interface VideoMediaAssetFact {
263
+ readonly assetId: string;
264
+ readonly kind: 'video';
265
+ readonly durationMs: number;
266
+ readonly storageKey?: string;
267
+ }
268
+ interface AudioMediaAssetFact {
269
+ readonly assetId: string;
270
+ readonly kind: 'audio';
271
+ readonly durationMs: number;
272
+ readonly storageKey: string;
273
+ }
274
+ interface VoiceMediaAssetFact {
275
+ /** Stable external speech result id, independent of the placed Clip id. */
276
+ readonly assetId: string;
277
+ readonly kind: 'voice';
278
+ readonly durationMs: number;
279
+ readonly storageKey: string;
280
+ /** Present for synthesized voice, absent for original recorded audio. */
281
+ readonly voice?: VoiceDescriptor;
282
+ }
283
+ /** Facts resolved from media storage. A trim window never substitutes for intrinsic duration. */
284
+ type MediaAssetFact = ImageMediaAssetFact | VideoMediaAssetFact | AudioMediaAssetFact | VoiceMediaAssetFact;
285
+ type ClipPlacement = {
286
+ readonly kind: 'sequential';
287
+ readonly order: number;
288
+ } | {
289
+ readonly kind: 'absolute';
290
+ readonly targetRange: SequenceRange<number>;
291
+ } | {
292
+ readonly kind: 'anchored';
293
+ readonly hostClipEntityId: string;
294
+ readonly anchorOffset: number;
295
+ };
296
+ interface InsertPlacedClipInput {
297
+ readonly trackEntityId: string;
298
+ readonly contentEntityId: string;
299
+ readonly sourceRange: SequenceRange<number>;
300
+ readonly duration: SequenceDuration<number>;
301
+ readonly placement: ClipPlacement;
302
+ readonly clipPayload?: JsonObject;
303
+ /** Stable caller-owned placement identity, when one already exists outside the graph. */
304
+ readonly clipEntityId?: string;
305
+ }
306
+ interface SetClipPlacementInput {
307
+ readonly clipEntityId: string;
308
+ readonly placement: ClipPlacement;
309
+ }
310
+ type SequentialClipAnchor = {
311
+ readonly position: 'before' | 'after';
312
+ readonly clipEntityId: string;
313
+ } | {
314
+ readonly position: 'trackStart';
315
+ };
316
+ interface MoveSequentialClipsInput {
317
+ readonly clipEntityIds: readonly string[];
318
+ readonly anchor: SequentialClipAnchor;
319
+ readonly onAnchored: 'follow' | 'keepAbsolute';
320
+ }
321
+ interface MoveClipsToStartsInput {
322
+ readonly moves: readonly {
323
+ readonly clipEntityId: string;
324
+ readonly newStartMs: number;
325
+ }[];
326
+ /** Absolute-time drags preserve every voiceover's current visible landing. */
327
+ readonly onAnchored: 'keepAbsolute';
328
+ }
329
+ interface DeleteClipTreeInput {
330
+ readonly clipEntityIds: readonly string[];
331
+ readonly onAnchored: 'cascade' | 'detach';
332
+ }
333
+ interface VoiceoverCaptionFact {
334
+ /** Stable placed caption identity supplied by the materialized side effect. */
335
+ readonly captionClipEntityId: string;
336
+ /** Directly held bases; includes the AudioScript used by the Voice. */
337
+ readonly baseEntityIds: readonly string[];
338
+ /** Ordered selection of AudioScript segments; caption text is never passed inline. */
339
+ readonly selection: CaptionSegmentSelection;
340
+ readonly startMs: number;
341
+ readonly durationMs: number;
342
+ readonly style?: CaptionStyleFields;
343
+ }
344
+ type VoiceoverTakeInput = {
345
+ readonly timelineEntityId: string; /** Stable placed speech identity, distinct from media.assetId. */
346
+ readonly voiceoverClipEntityId: string;
347
+ readonly media: VoiceMediaAssetFact; /** Existing pronunciation variant; its composed AudioScript stays the text owner. */
348
+ readonly phoneticScriptEntityId: string;
349
+ readonly volume: number;
350
+ readonly captions: readonly VoiceoverCaptionFact[];
351
+ } & ({
352
+ readonly placement: ClipPlacement;
353
+ readonly hostClipEntityId?: never;
354
+ readonly anchorOffset?: never;
355
+ } | {
356
+ readonly placement?: never;
357
+ readonly hostClipEntityId: string;
358
+ readonly anchorOffset: number;
359
+ });
360
+ type VisualMediaAssetFact = ImageMediaAssetFact | VideoMediaAssetFact;
361
+ interface InsertMediaClipInput {
362
+ readonly timelineEntityId: string;
363
+ readonly clipEntityId?: string;
364
+ readonly media: VisualMediaAssetFact;
365
+ /** Source/display window in whole milliseconds. Images use this as their finite display span. */
366
+ readonly sourceRange: SequenceRange<number>;
367
+ readonly placement: ClipPlacement;
368
+ readonly volume?: number;
369
+ }
370
+ interface ReplaceMediaClipInput {
371
+ readonly clipEntityId: string;
372
+ readonly media: VisualMediaAssetFact;
373
+ readonly sourceRange: SequenceRange<number>;
374
+ }
375
+ interface ReplacementMediaClipInput {
376
+ readonly clipEntityId?: string;
377
+ readonly media: VisualMediaAssetFact;
378
+ readonly sourceRange: SequenceRange<number>;
379
+ readonly volume?: number;
380
+ }
381
+ type MediaClipInsertion = {
382
+ readonly kind: 'before';
383
+ readonly clipEntityId: string;
384
+ } | {
385
+ readonly kind: 'after';
386
+ readonly clipEntityId: string;
387
+ } | {
388
+ readonly kind: 'firstStart';
389
+ readonly startMs: number;
390
+ };
391
+ interface InsertMediaClipsInput {
392
+ readonly timelineEntityId: string;
393
+ readonly clips: readonly ReplacementMediaClipInput[];
394
+ /** One placement decision for the whole input-ordered block. */
395
+ readonly insertion: MediaClipInsertion;
396
+ }
397
+ interface ReplaceSequentialClipsInput {
398
+ readonly timelineEntityId: string;
399
+ readonly oldClipEntityIds: readonly string[];
400
+ readonly newClips: readonly ReplacementMediaClipInput[];
401
+ readonly onAnchored: 'remap' | 'cascade';
402
+ }
403
+ interface SetClipVolumeInput {
404
+ readonly clipEntityId: string;
405
+ /** Playback gain in decibels. */
406
+ readonly volume: number;
407
+ }
408
+ interface LinearClipSpeed {
409
+ readonly kind: 'linear';
410
+ readonly rate: number;
411
+ readonly mode?: string;
412
+ }
413
+ interface SetClipSpeedInput {
414
+ readonly clipEntityId: string;
415
+ readonly timeRemapping: LinearClipSpeed | null;
416
+ }
417
+ interface TrimClipInput {
418
+ readonly clipEntityId: string;
419
+ readonly sourceRange: SequenceRange<number>;
420
+ }
421
+ interface VoiceoverTakeResult {
422
+ readonly voiceoverClipEntityId: string;
423
+ readonly voiceEntityId: string;
424
+ /** The pronunciation variant the Voice was rendered from. */
425
+ readonly phoneticScriptEntityId: string;
426
+ /** The base-text owner resolved from the PhoneticScript baseEntityIds. */
427
+ readonly audioScriptEntityId: string;
428
+ readonly captionClipEntityIds: readonly string[];
429
+ }
430
+ interface MoveVoiceoverInput {
431
+ readonly voiceoverClipEntityId: string;
432
+ /** Absolute requested timeline start; MEngine resolves and persists the host relation. */
433
+ readonly newStartMs: number;
434
+ }
435
+ interface DeleteVoiceoverInput {
436
+ readonly voiceoverClipEntityIds: readonly string[];
437
+ }
438
+ interface SetBgmInput {
439
+ readonly timelineEntityId: string;
440
+ readonly bgmClipEntityId: string;
441
+ readonly media: AudioMediaAssetFact;
442
+ readonly volume: number;
443
+ }
444
+ interface DeleteBgmInput {
445
+ readonly timelineEntityId: string;
446
+ }
447
+ interface SetCaptionVisibilityInput {
448
+ readonly timelineEntityId: string;
449
+ readonly hidden: boolean;
450
+ }
451
+ interface PatchCaptionStyleInput {
452
+ readonly timelineEntityId: string;
453
+ readonly style: CaptionStyleFields;
454
+ }
455
+ interface InsertCaptionClipInput {
456
+ readonly timelineEntityId: string;
457
+ /** Existing generation identity for newly materialized Caption content, distinct from its Clip. */
458
+ readonly captionEntityId?: string;
459
+ /** Stable placed caption identity, distinct from the Caption content identity. */
460
+ readonly captionClipEntityId?: string;
461
+ /** Existing bases composed by this variant; includes an AudioScript text owner. */
462
+ readonly baseEntityIds: readonly string[];
463
+ /** Ordered selection of the AudioScript segments this Caption displays. */
464
+ readonly selection: CaptionSegmentSelection;
465
+ /** Intrinsic cue length of the Caption entity itself; display comes from the placement. */
466
+ readonly durationMs: number;
467
+ readonly style?: CaptionStyleFields;
468
+ readonly placement: ClipPlacement;
469
+ }
470
+ interface InsertClipInput {
471
+ readonly trackEntityId: string;
472
+ /** Existing Sequence media Entity id. Asset ids and URLs are not content ids. */
473
+ readonly contentEntityId: string;
474
+ readonly sourceRange: SequenceRange<number>;
475
+ readonly duration: SequenceDuration<number>;
476
+ readonly targetRange?: SequenceRange<number>;
477
+ readonly clipPayload?: JsonObject;
478
+ }
479
+ interface UpdateClipMarkerInput {
480
+ readonly clipEntityId: string;
481
+ readonly sourceRange?: SequenceRange<number>;
482
+ /** Passing `undefined` explicitly removes the optional target range. */
483
+ readonly targetRange?: SequenceRange<number> | undefined;
484
+ readonly duration?: SequenceDuration<number>;
485
+ /** Passing `undefined` explicitly removes the optional remapping value. */
486
+ readonly timeRemapping?: JsonValue | undefined;
487
+ }
488
+ interface MoveClipInput {
489
+ readonly clipEntityId: string;
490
+ readonly trackEntityId: string;
491
+ }
492
+ interface ReplaceClipContentInput {
493
+ readonly clipEntityId: string;
494
+ /** Existing Sequence media Entity id. Asset ids and URLs are not content ids. */
495
+ readonly contentEntityId: string;
496
+ readonly sourceRange: SequenceRange<number>;
497
+ readonly duration: SequenceDuration<number>;
498
+ readonly targetRange?: SequenceRange<number>;
499
+ readonly timeRemapping?: JsonValue;
500
+ }
501
+ interface DeleteClipInput {
502
+ readonly clipEntityId: string;
503
+ }
504
+ interface UpdateClipInput {
505
+ readonly clipEntityId: string;
506
+ /** Complete replacement for the Clip-owned payload. */
507
+ readonly payload: JsonObject;
508
+ }
509
+ type ClipEntityId = EntityId;
510
+ //#endregion
511
+ //#region src/entity-editor/entity-timeline-editor.d.ts
182
512
  /**
183
- * Part-id generation, aligned with the online ecosystem.
513
+ * Graph-native timeline authoring over authoritative Medeo Entity and Relation rows.
184
514
  *
185
- * The authoritative online producers — agent-harness (`@harness/shared`
186
- * `genObjId`) and director.v2 (`common/obj_id.py` `gen_obj_id`) — both mint part
187
- * ids as `` `${prefix}_${ulid()}` ``, and real captured drafts use exactly that
188
- * shape (`clip_…` / `spe_…` / `cap_…` / `bgm_…`, each a 26-char ULID). The engine
189
- * previously emitted `vc_<base36 timestamp><6 random>`, a different prefix AND a
190
- * different encoding — the sole cross-repo id divergence. This module removes it
191
- * by emitting the same `<prefix>_<ULID>` bytes.
515
+ * Each mutation is applied to a detached graph, validated as a complete DSL set,
516
+ * and committed only after validation succeeds.
517
+ */
518
+ declare class EntityTimelineEditor {
519
+ private readonly idFactory;
520
+ private state;
521
+ constructor(initialRows: EntityRelationRows, idFactory?: EntityTimelineIdFactory);
522
+ rows(): EntityRelationRows;
523
+ insertClip(input: InsertClipInput): ClipEntityId;
524
+ insertPlacedClip(input: InsertPlacedClipInput): ClipEntityId;
525
+ updateClipMarker(input: UpdateClipMarkerInput): void;
526
+ setClipPlacement(input: SetClipPlacementInput): void;
527
+ moveSequentialClips(input: MoveSequentialClipsInput): void;
528
+ moveClipsToStarts(input: MoveClipsToStartsInput): void;
529
+ moveClip(input: MoveClipInput): void;
530
+ replaceClipContent(input: ReplaceClipContentInput): void;
531
+ insertMediaClip(input: InsertMediaClipInput): ClipEntityId;
532
+ insertMediaClips(input: InsertMediaClipsInput): readonly ClipEntityId[];
533
+ replaceMediaClip(input: ReplaceMediaClipInput): void;
534
+ setClipVolume(input: SetClipVolumeInput): void;
535
+ setClipSpeed(input: SetClipSpeedInput): void;
536
+ trimClip(input: TrimClipInput): void;
537
+ replaceSequentialClips(input: ReplaceSequentialClipsInput): readonly ClipEntityId[];
538
+ deleteClip(input: DeleteClipInput): void;
539
+ deleteClipTree(input: DeleteClipTreeInput): void;
540
+ updateClip(input: UpdateClipInput): void;
541
+ upsertVoiceoverTake(input: VoiceoverTakeInput): VoiceoverTakeResult;
542
+ moveVoiceover(input: MoveVoiceoverInput): void;
543
+ deleteVoiceover(input: DeleteVoiceoverInput): void;
544
+ setBgm(input: SetBgmInput): ClipEntityId;
545
+ deleteBgm(input: DeleteBgmInput): void;
546
+ setCaptionVisibility(input: SetCaptionVisibilityInput): void;
547
+ patchCaptionStyle(input: PatchCaptionStyleInput): void;
548
+ /**
549
+ * Place a Caption as a composed variant of an existing AudioScript: the
550
+ * entity stores baseEntityIds, selection, optional style, and inherent cue-bounded
551
+ * Sequence. This helper does not copy base text. The Clip and its display Marker describe this use;
552
+ * moving or stretching the returned Clip later changes the Clip/Marker,
553
+ * never the Caption entity or the AudioScript.
554
+ */
555
+ insertCaptionClip(input: InsertCaptionClipInput): ClipEntityId;
556
+ private insertPlacedClipIntoDraft;
557
+ private ensureRoleTrack;
558
+ /** The existing pronunciation variant a Voice consumes; composition is required. */
559
+ private requireComposedPhoneticScript;
560
+ /** Preserve the factual synthesis input, regardless of persisted endpoint positions. */
561
+ private ensurePhoneticRender;
562
+ private reconcileVoiceoverCaptions;
563
+ private ensureRoleTrackForClip;
564
+ private replaceCaptionAlignment;
565
+ /**
566
+ * Remove one placed Caption use. The composed AudioScript outlives the
567
+ * caption: it may anchor further captions and remains the text owner.
568
+ */
569
+ private removeCaptionClipGraph;
570
+ private replaceAnchorHost;
571
+ /** Rebuild the legacy edit baseline from current visual order before a high-level cascade. */
572
+ private normalizeMainSequential;
573
+ private resolveOneVoiceoverOverlap;
574
+ private applyClipPlacement;
575
+ private reanchorAtAbsolute;
576
+ private removeAnchoredDescendants;
577
+ private removeClipGraph;
578
+ private transact;
579
+ private mintEntityId;
580
+ private createRelation;
581
+ private relinkRelation;
582
+ private mintRelationId;
583
+ }
584
+ //#endregion
585
+ //#region src/entity-editor/editor-resources.d.ts
586
+ declare const roleOrder: {
587
+ readonly caption: 0;
588
+ readonly video_clip: 1;
589
+ readonly speech: 2;
590
+ readonly bgm: 3;
591
+ };
592
+ type EditorTrackRole = keyof typeof roleOrder;
593
+ interface EditorFoundation {
594
+ readonly rows: EntityRelationRows;
595
+ readonly timelineEntityId: string;
596
+ readonly trackEntityIds: Readonly<Record<EditorTrackRole, string>>;
597
+ /** Initial or current AudioScript content ID selected by the foundation. */
598
+ readonly audioScriptEntityId: string;
599
+ }
600
+ /**
601
+ * MEngine editor policy, not a cardinality restriction on the general-purpose DSL.
192
602
  *
193
- * The ULID is generated inline (Crockford Base32, 48-bit time + 80-bit random)
194
- * rather than pulling the `ulid` npm package: the randomness class matches the
195
- * old generator (both `Math.random`-based) and it keeps `@mengine/medeo-client`
196
- * dependency-free for a purely mechanical id string. Part ids only need to be
197
- * unique and lexicographically time-sortable, which this satisfies.
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 may associate with a physical text Asset.
198
608
  */
609
+ declare function assertCanonicalEditorResources(rows: EntityRelationRows): void;
199
610
  /**
200
- * Online part-id semantic prefixes. `clip` (video clip) is the only value the
201
- * engine currently mints (see `addVideoClips`); the rest are declared so the
202
- * type documents the shared vocabulary and guards against reintroducing the old
203
- * `vc`/`sp`/`cp`/`bg` names. Speech/caption/bgm ids arrive pre-minted in op
204
- * payloads, so the engine never generates them itself.
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:
615
+ *
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;
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.
205
624
  */
206
- type PartIdPrefix = 'clip' | 'spe' | 'cap' | 'bgm' | 'ti';
207
- declare function generatePartId(prefix: PartIdPrefix): string;
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'], selectedAudioScriptEntityId?: string | null): 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/entity-editor/caption-content.d.ts
655
+ interface CaptionContentInput {
656
+ readonly contentEntityId: string;
657
+ readonly audioScriptEntityId: string;
658
+ readonly text: string;
659
+ readonly selection?: CaptionSegmentSelection;
660
+ readonly durationMs: number;
661
+ }
662
+ /** Author Caption content from semantic intent; callers never reconcile variant bases or assembled fields. */
663
+ declare function prepareCaptionContent(rows: EntityRelationRows, input: CaptionContentInput): EntityRow<'caption'>;
664
+ //#endregion
665
+ //#region src/entity-editor/document-audio-script.d.ts
666
+ interface DocumentAudioScript {
667
+ readonly entityId: string;
668
+ readonly segments: readonly (ScriptTextSegment & Readonly<Record<string, unknown>>)[];
669
+ }
670
+ /** State exposing the current AudioScript content version attached to the project. */
671
+ interface DocumentAudioScriptState {
672
+ readonly rows: EntityRelationRows;
673
+ /** Current attachment; initialized projects point to a real script, including an empty one. */
674
+ readonly audioScriptEntityId: string | null;
675
+ }
676
+ /** Read only the attached version and preserve every segment; never aggregate other scripts. */
677
+ declare function readDocumentAudioScript(state: DocumentAudioScriptState): DocumentAudioScript;
678
+ //#endregion
679
+ //#region src/entity-crdt/field-changes.d.ts
680
+ /** List members are addressed by identity, never a transient array offset. */
681
+ type FieldPath = readonly (string | {
682
+ elementId: string;
683
+ })[];
684
+ type FieldChange = {
685
+ op: 'set';
686
+ path: FieldPath;
687
+ value: JsonValue;
688
+ } | {
689
+ op: 'unset';
690
+ path: FieldPath;
691
+ } | {
692
+ op: 'text.splice';
693
+ path: FieldPath;
694
+ index: number;
695
+ deleteCount: number;
696
+ text: string;
697
+ } | {
698
+ op: 'list.insert';
699
+ path: FieldPath;
700
+ value: JsonValue;
701
+ beforeElementId: string | null;
702
+ } | {
703
+ op: 'list.move';
704
+ path: FieldPath;
705
+ elementId: string;
706
+ beforeElementId: string | null;
707
+ } | {
708
+ op: 'list.remove';
709
+ path: FieldPath;
710
+ elementId: string;
711
+ };
712
+ declare function assertFieldChanges(changes: readonly FieldChange[]): void;
713
+ /** Resolve against the sequential causal view; the numeric path never crosses the API boundary. */
714
+ declare function resolveFieldPath(payload: JsonObject, path: FieldPath): (string | number)[];
715
+ /** Detached plan evaluation. Native compilation replays the original operations, not this snapshot. */
716
+ declare function applyFieldChanges(payload: JsonObject, changes: readonly FieldChange[]): JsonObject;
717
+ //#endregion
718
+ //#region src/entity-crdt/entity-document.d.ts
719
+ declare const LORO_ENTITY_SCHEMA = "medeo.entities.loro.v1";
720
+ interface EntityDocumentState {
721
+ readonly rows: EntityRelationRows;
722
+ readonly project: Readonly<Record<string, string>>;
723
+ }
724
+ type Command = {
725
+ type: 'create';
726
+ row: EntityRow;
727
+ } | {
728
+ type: 'selection-baseline';
729
+ root: string;
730
+ fingerprint: string;
731
+ } | {
732
+ type: 'order';
733
+ group: string;
734
+ roots: string[];
735
+ token: string;
736
+ } | {
737
+ type: 'write';
738
+ root: string;
739
+ payload: JsonObject;
740
+ token: string;
741
+ } | {
742
+ type: 'text';
743
+ root: string;
744
+ path: readonly (string | number)[];
745
+ start: number;
746
+ deleteCount: number;
747
+ text: string;
748
+ token: string;
749
+ } | {
750
+ type: 'field';
751
+ root: string;
752
+ path: (string | number)[];
753
+ change: FieldChange;
754
+ token: string;
755
+ } | {
756
+ type: 'relation-field';
757
+ root: string;
758
+ path: (string | number)[];
759
+ change: FieldChange;
760
+ } | {
761
+ type: 'delete';
762
+ root: string;
763
+ } | {
764
+ type: 'relation';
765
+ row: RelationRow;
766
+ } | {
767
+ type: 'relation-fields';
768
+ root: string;
769
+ metadata: JsonObject;
770
+ trace: JsonObject;
771
+ } | {
772
+ type: 'unlink';
773
+ root: string;
774
+ } | {
775
+ type: 'attach';
776
+ slot: string;
777
+ entityId: string;
778
+ };
779
+ /** Plain domain objects assembled from native Loro state, never a second writable authority. */
780
+ declare function readEntityDocument(doc: LoroDoc, allowSelectionConflicts?: boolean): EntityDocumentState;
781
+ /** Native editing containers survive domain version changes and merge independently. */
782
+ declare class LoroEntityDocument {
783
+ readonly doc: LoroDoc;
784
+ private readonly validate?;
785
+ private readonly undoManager;
786
+ constructor(doc: LoroDoc, validate?: ((state: EntityDocumentState) => void) | undefined);
787
+ /** Open a causal snapshot using the same Loro runtime as the compiler. */
788
+ static fromSnapshot(snapshot: Uint8Array, validate?: (state: EntityDocumentState) => void): LoroEntityDocument;
789
+ static create(rows: EntityRelationRows, project?: Readonly<Record<string, string>>, peerId?: PeerID): LoroEntityDocument;
790
+ snapshot(): EntityDocumentState;
791
+ relationsOf(entityId: string): readonly RelationRow[];
792
+ /** Resolve a queued edit target through its native identity without changing history. */
793
+ resolveCurrentEntityId(id: string): string;
794
+ getVersion(id: string): EntityRow | undefined;
795
+ /** The callback and every domain validation execute on a causally complete fork first. */
796
+ transact(edit: (draft: LoroEntityDraft) => void): Uint8Array;
797
+ /** Import preserves native operation identities; projection errors never discard remote operations. */
798
+ import(update: Uint8Array): void;
799
+ /** Bind a saved snapshot without rewriting text operations or resolving selection conflicts. */
800
+ bindAudioScriptAsset(entityId: string, assetId: string, expectedContentHash: string): Uint8Array;
801
+ canUndo(): boolean;
802
+ canRedo(): boolean;
803
+ undo(): boolean;
804
+ redo(): boolean;
805
+ private historyEdit;
806
+ }
807
+ declare class LoroEntityDraft {
808
+ private readonly doc;
809
+ readonly commands: Command[];
810
+ private readonly selectedRoots;
811
+ private readonly relationAliases;
812
+ constructor(doc: LoroDoc);
813
+ snapshot(): EntityDocumentState;
814
+ order(groupId: string, entityIds: readonly string[]): void;
815
+ /** Project the final scalar placement intents onto the existing native ordering containers. */
816
+ reconcileOrder(rows: EntityRelationRows): void;
817
+ create(row: EntityRow): void;
818
+ delete(entityId: string): void;
819
+ attach(slot: string, entityId: string): void;
820
+ link(row: RelationRow): void;
821
+ patchRelation(relationId: string, metadata: JsonObject, trace: JsonObject): void;
822
+ unlink(relationId: string): void;
823
+ private relationRoot;
824
+ update(entityId: string, fields: JsonObject): void;
825
+ declare(entityId: string, fields: JsonObject): void;
826
+ replaceOwned(entityId: string, payload: JsonObject): void;
827
+ editText(entityId: string, path: readonly (string | number)[], start: number, deleteCount: number, text: string): void;
828
+ /** Generic assembled-field edit compiled at the author's causal position. */
829
+ change(entityId: string, changes: readonly FieldChange[]): void;
830
+ changeRelation(relationId: string, changes: readonly FieldChange[]): void;
831
+ captureSelectionBaselines(): void;
832
+ private record;
833
+ }
834
+ //#endregion
835
+ //#region src/entity-crdt/compile-rows.d.ts
836
+ /** Lower a detached ordinary-object edit against its actual causal Loro baseline. */
837
+ declare function compileEntityRows(snapshot: Uint8Array, rows: EntityRelationRows, validate?: (state: EntityDocumentState) => void): {
838
+ update: Uint8Array;
839
+ state: EntityDocumentState;
840
+ };
841
+ /** Compile an edit on an existing peer, retaining its native local undo history. */
842
+ declare function applyEntityRows(editor: LoroEntityDocument, rows: EntityRelationRows): {
843
+ update: Uint8Array;
844
+ state: EntityDocumentState;
845
+ };
846
+ //#endregion
847
+ //#region src/editor/journal.d.ts
848
+ /**
849
+ * Wire a plain-memory adapter + editor that share a recording id factory, so
850
+ * every mutating transact lands in `journal` with ordered `generated_ids`.
851
+ */
852
+ declare function createEditSandbox(document: VideoDocument, options?: PlainMemoryAdapterOptions): {
853
+ adapter: PlainMemoryAdapter;
854
+ editor: SemanticEditor;
855
+ journal: readonly JournalEntry[];
856
+ };
857
+ /**
858
+ * Re-drive `doc` from a recorded journal, forcing each entry's `generated_ids`
859
+ * through a queue-backed id factory. Never mints fresh ids: an empty queue on
860
+ * demand throws `unrecorded id`; leftover ids after an entry throws
861
+ * `unconsumed ids`. Legacy entries without `generated_ids` are treated as `[]`.
862
+ */
863
+ declare function replayJournal(doc: SemanticDocumentAdapter, journal: readonly JournalEntry[]): Promise<void>;
208
864
  //#endregion
209
865
  //#region src/editor/snapshot-utils.d.ts
210
866
  /** Main-track item identity read from a raw snapshot (only `part_id` is needed). */
@@ -297,9 +953,7 @@ type PushResultKind = 'ack' | 'duplicate' | 'rejected' | 'failed' | 'nothing_to_
297
953
  */
298
954
  interface PushResult {
299
955
  kind: PushResultKind;
300
- /** Server document sequence observed after a successful `ack` or `duplicate`. */
301
- mengineUpdateSeq?: number | undefined;
302
- /** @deprecated Ack-only sequence retained until consumers adopt `mengineUpdateSeq`. */
956
+ /** Server-allocated sequence number; only present for `ack`. */
303
957
  updateSeq?: number | undefined;
304
958
  /** Whether the server held ops the local document lacked. See above. */
305
959
  collaborated: boolean;
@@ -406,7 +1060,8 @@ declare class ManualSyncDoc {
406
1060
  * Fetches the snapshot up front rather than starting empty and converging: the
407
1061
  * agent's first act is to read the document, so there is no useful state before
408
1062
  * the snapshot lands. This also fails fast and loudly on a document that does
409
- * not exist or whose first snapshot is incomplete or invalid.
1063
+ * not exist, instead of `MengineDocSession.waitForContent()`'s behavior of
1064
+ * waiting forever for content that will never arrive.
410
1065
  */
411
1066
  static open(options: ManualSyncDocOptions): Promise<ManualSyncDoc>;
412
1067
  /** Current document read model (authoritative shape). */
@@ -422,16 +1077,27 @@ declare class ManualSyncDoc {
422
1077
  * was passed to the constructor.
423
1078
  */
424
1079
  editorPeerId(): PeerID;
425
- /** Current content projected into the compatible track and part read shape. */
426
- content(): VideoDraftContent;
1080
+ /** Current document projected to the legacy `VideoDraft` read shape. */
1081
+ draft(): VideoDraft;
1082
+ /**
1083
+ * Replay a deterministic sandbox journal into this document.
1084
+ *
1085
+ * The adapter stays private so callers cannot bypass the manual-sync
1086
+ * lifecycle; journal replay is the one host-side operation that needs the
1087
+ * adapter's transaction boundary and recorded id queue. Durability is still
1088
+ * explicit: call {@link push} after replay and report success only from its
1089
+ * verdict.
1090
+ */
1091
+ replayJournal(journal: readonly JournalEntry[]): Promise<void>;
427
1092
  /**
428
1093
  * Mark the document state the caller has just observed, for a later
429
1094
  * {@link hasChangedSince}.
430
1095
  *
431
1096
  * This pair replaces the legacy integer-version comparison that
432
1097
  * `DraftVersionDetector` used to tell the LLM "the draft was modified
433
- * externally, reload before editing". Comparing Loro version vectors covers
434
- * all collaborative edits without a business revision field in the document.
1098
+ * externally, reload before editing". Under mengine `meta.version` never
1099
+ * changes, so that detector would go permanently silent; comparing version
1100
+ * vectors restores the same capability.
435
1101
  *
436
1102
  * Same capability, not a stronger one: like the legacy detector, this only
437
1103
  * reports what changed between two moments the caller chose to sample.
@@ -576,24 +1242,12 @@ declare class MedeoHttpDocStorage implements DocStorage {
576
1242
  * tool-level ack wait) subscribe here.
577
1243
  */
578
1244
  subscribePushOutcome(callback: (outcome: PushOutcome) => void): () => void;
579
- /** Observe live hints that require VV catch-up without replacing the SSE connection. */
580
- subscribeResync(callback: () => void): () => void;
581
- /** Authoritative HTTP reads and accepted pushes, never inferred from SSE bytes. */
582
- subscribeServerVersion(callback: (version: Uint8Array) => void): () => void;
583
- private reportServerVersion;
584
1245
  deleteDoc(_docId: string): Promise<void>;
585
1246
  subscribeDocUpdate(callback: (update: DocUpdate, origin: unknown) => void): () => void;
586
1247
  private assertDocId;
587
1248
  private emitUpdate;
588
1249
  }
589
1250
  //#endregion
590
- //#region src/session/document-undo-manager.d.ts
591
- /** Availability for this document's current editing session, not server revisions. */
592
- interface MengineUndoState {
593
- readonly canUndo: boolean;
594
- readonly canRedo: boolean;
595
- }
596
- //#endregion
597
1251
  //#region src/session/types.d.ts
598
1252
  /**
599
1253
  * Local storage contract the runtime depends on. Aliased to the engine
@@ -632,23 +1286,10 @@ declare class MengineAckFailedError extends Error {
632
1286
  readonly cause: Error | undefined;
633
1287
  constructor(reason: 'timeout' | 'rejected' | 'failed', code: string | undefined, cause: Error | undefined, message: string);
634
1288
  }
635
- type MengineLocalSaveState = LocalSaveState;
636
- interface WaitForLocalSaveOptions {
637
- /** Only limits waiting, never cancels persistence. */
638
- timeoutMs?: number;
639
- }
640
1289
  interface WaitForServerAckOptions {
641
1290
  /** Deadline in ms. Rejects with reason `timeout` when it elapses. */
642
1291
  timeoutMs?: number;
643
1292
  }
644
- /** Document-level confirmation is independent of local operation completion. */
645
- interface MengineDocSyncState {
646
- /** Server-originated imports do not create a new local confirmation obligation. */
647
- readonly confirmation: 'unknown' | 'pending' | 'confirmed';
648
- /** Transport/activity phase. Idle does not imply confirmation; failure details
649
- * remain available through push outcomes and confirmation wait errors. */
650
- readonly phase: 'connecting' | 'idle' | 'syncing' | 'offline' | 'failed';
651
- }
652
1293
  interface MengineDocSessionOptions {
653
1294
  docId: string;
654
1295
  client: MengineHttpClient;
@@ -658,18 +1299,24 @@ interface MengineDocSessionOptions {
658
1299
  * Browsers should pass an `IndexedDBDocStorage` for refresh/cross-tab support.
659
1300
  */
660
1301
  localStorage?: DocStorageLike;
661
- /** A freshly fetched remote snapshot to merge into storage before loading.
662
- * Existing local changes are retained; the host owns any online startup gate. */
663
- initialSnapshot?: Uint8Array;
664
1302
  sseReconnectDelayMs?: number;
1303
+ /**
1304
+ * Keep remote synchronization read-only: pull snapshot/diffs and subscribe to
1305
+ * SSE updates, but never POST local Loro updates to the server.
1306
+ */
1307
+ readonlyMode?: boolean;
665
1308
  }
666
1309
  /**
667
1310
  * A live editing session for one Medeo document — the single entry point clients
668
1311
  * (FE draft driver, Agent, embeds) use to open, edit, and observe a document.
669
1312
  *
670
- * SemanticEditor writes through MirrorVideoDocumentAdapter directly, while
671
- * DocumentUndoManager observes the same LoroDoc independently. Both mutation
672
- * paths use the session's DocumentMutationGuard, closed before teardown.
1313
+ * It assembles the engine sync stack around one Medeo document:
1314
+ *
1315
+ * local DocStorage ─┐
1316
+ * ├─ ClientServerSynchronizer ── DocManager ── LoroDoc
1317
+ * MedeoHttpDocStorage┘ │
1318
+ * (remote = Rust mengine-server) ▼
1319
+ * MirrorVideoDocumentAdapter + SemanticEditor
673
1320
  *
674
1321
  * `DocManager` owns the `LoroDoc`: local edits committed on the adapter are
675
1322
  * picked up via `subscribeLocalUpdates`, saved to local storage, then pushed to
@@ -690,21 +1337,11 @@ declare class MengineDocSession {
690
1337
  private readonly manager;
691
1338
  private readonly events;
692
1339
  private readonly disposables;
693
- private readonly mutationGuard;
694
1340
  private adapterValue;
695
1341
  private editorValue;
696
- private undoManagerValue;
697
1342
  private started;
698
- private startTask;
699
- private destroyed;
700
- private closeTask;
701
- private lifetime;
702
- private hasConnected;
703
- private initialVersionValue;
704
- private localVersionValue;
705
- private pushErrorValue;
706
1343
  /**
707
- * Latest server oplog version seen on an authoritative HTTP response. Lets `waitForServerAck`
1344
+ * Latest server oplog version seen on a push outcome. Lets `waitForServerAck`
708
1345
  * return without waiting when the server is already known to cover the local
709
1346
  * doc (e.g. nothing was edited since the last confirmed push).
710
1347
  */
@@ -719,14 +1356,14 @@ declare class MengineDocSession {
719
1356
  */
720
1357
  subscribePushOutcome(callback: (outcome: PushOutcome) => void): () => void;
721
1358
  /**
722
- * Resolve once the server has durably accepted the local commits as of
1359
+ * Resolve once the server has durably accepted the local document state as of
723
1360
  * *now* — the capability an Agent tool needs to answer "did my edit land?"
724
1361
  * before reporting success.
725
1362
  *
726
1363
  * Call it right after the editor ops whose durability matters. It snapshots the
727
- * latest local commit's version (or the loaded baseline before any edit) and
728
- * resolves when an authoritative server version covers it. Remote-only
729
- * imports do not extend this target, matching the displayed confirmation state.
1364
+ * local doc's current version and resolves on the first push outcome whose
1365
+ * `serverVV` covers that version, i.e. the server log is at least as advanced as
1366
+ * the local doc was when this was called.
730
1367
  *
731
1368
  * Version coverage, not byte identity, is the acceptance test — for two reasons:
732
1369
  * the ops may reach the server inside a merged blob rather than as the exact
@@ -748,70 +1385,43 @@ declare class MengineDocSession {
748
1385
  * step. The committed change drives DocManager's local-update push.
749
1386
  */
750
1387
  get editor(): SemanticEditor;
751
- /** Current document snapshot (read model). */
752
- snapshot(): VideoDocument;
753
- /** Current-session undo/redo availability. Loading and closed sessions report false. */
754
- getUndoState(): MengineUndoState;
755
- /**
756
- * Supplies current availability immediately, then coalesces stack changes in a
757
- * microtask. Session teardown publishes empty availability synchronously.
758
- */
759
- subscribeUndoState(cb: (state: MengineUndoState) => void): () => void;
760
1388
  /**
761
- * Undo a local edit immediately; server confirmation remains asynchronous.
762
- * On a shared LWW field this writes its prior value, potentially overwriting a
763
- * later remote edit to that same field. Returns false if no update is produced.
1389
+ * Opaque version token of the local oplog (base64 `VersionVector.encode`).
1390
+ * Equality-comparable only: equal means no observed change (local or
1391
+ * remote-arrived) since the token was taken. Throws when not started.
764
1392
  */
765
- undo(options?: CommitOptions): boolean;
1393
+ version(): string;
766
1394
  /**
767
- * Restore the state visible before undo without rerunning external side effects.
768
- * Returns false if no update is produced; durable confirmation is separate.
1395
+ * The live document adapter, exposed for journal replay (commit channel).
1396
+ * Replaying through it still goes SemanticEditor → Loro → mengine-server —
1397
+ * no write bypass. Typed by the narrow interface on purpose.
769
1398
  */
770
- redo(options?: CommitOptions): boolean;
771
- /**
772
- * Combine existing semantic operations (e.g. trim a clip and adjust its volume)
773
- * or repeated commits during one drag gesture into a single undo step. A gesture
774
- * that only previews locally and commits once on release needs no group.
775
- * Each commit is immediately visible locally and enters sync independently;
776
- * a later failure does not roll it back.
777
- * Always pair with endUndoGroup in a finally block. Conflicting remote imports
778
- * can end/split the group early, and unrelated local edits would join it.
779
- * Complete asynchronous asset preparation before opening the group.
780
- */
781
- beginUndoGroup(): void;
782
- /** End a gesture, including one already split by a conflicting remote import. */
783
- endUndoGroup(): void;
1399
+ get documentAdapter(): SemanticDocumentAdapter;
1400
+ /** Current document snapshot (read model). */
1401
+ snapshot(): VideoDocument;
784
1402
  /**
785
1403
  * Start the sync stack and connect the document.
786
1404
  *
787
- * Returns after DocManager loads a local snapshot, or after the first remote
788
- * sync when no local snapshot exists. A valid empty document is ready too.
789
- * Cached documents can open before SSE connects; subsequent remote changes
790
- * surface through `subscribe`.
1405
+ * Returns once the local snapshot has loaded into the Loro doc so callers can
1406
+ * read an initial snapshot. Remote convergence continues in the background and
1407
+ * surfaces through `subscribe`.
791
1408
  */
792
1409
  start(): Promise<VideoDocument>;
793
- private open;
794
- getLocalSaveState(): MengineLocalSaveState;
795
- /** Immediately reports local transaction state; independent of server confirmation. */
796
- subscribeLocalSaveState(cb: (state: MengineLocalSaveState) => void): () => void;
797
- /** Waits for commits present now to reach local storage. Does not wait for the network. */
798
- waitForLocalSave(options?: WaitForLocalSaveOptions): Promise<void>;
799
- /** Stop accepting edits and drain local persistence before releasing resources.
800
- * A failed local write keeps retrying, even after the host has unmounted.
801
- * Hosts should use this for normal teardown; destroy() is immediate cancellation. */
802
- close(): Promise<void>;
803
- getSyncState(): MengineDocSyncState;
804
- private trackLocalVersion;
805
- private confirmationTarget;
806
- /** Immediately supplies current state; unsubscribe when the host changes docs. */
807
- subscribeSyncState(cb: (state: MengineDocSyncState) => void): () => void;
808
- private emitSyncState;
809
1410
  subscribe(cb: (event: MengineDocSessionUpdateEvent) => void): () => void;
810
1411
  onStateChange(cb: (state: DocState) => void): () => void;
811
1412
  getState(): DocState;
812
1413
  destroy(): void;
813
- /** Local absence needs a remote sync; empty business content does not. */
814
- private waitForInitialLoad;
1414
+ /**
1415
+ * Resolve once the Loro doc holds the document root.
1416
+ *
1417
+ * `DocManager` loads from local storage, which starts empty for a fresh
1418
+ * client; the server snapshot arrives asynchronously via the first sync job.
1419
+ * `loaded` only means the local load ran, so we wait for actual content
1420
+ * (populated schema roots) instead, surfaced by the doc subscription set up
1421
+ * in `start()`.
1422
+ */
1423
+ private waitForContent;
1424
+ private hasContent;
815
1425
  }
816
1426
  //#endregion
817
1427
  //#region src/storage/memory-doc-storage.d.ts
@@ -1138,4 +1748,12 @@ declare function hostForAbsMs(ranges: MainClipRange[], absMs: number): MainClipR
1138
1748
  */
1139
1749
  declare function relativePositionForAbs(ranges: MainClipRange[], absMs: number): TrackItemTimePosition;
1140
1750
  //#endregion
1141
- 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, 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, type MengineLocalSaveState, MenginePushRejectedError, type MenginePushResponse, type MenginePushUpdateResponse, type MengineRejectedResponse, type MengineSnapshotResponse, type MengineSseUpdateEvent, type MengineSyncResponse, type MengineUndoState, 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, ValidationError, type VideoClipPart, type VideoDocument, type VideoDocumentDraft, type VideoDocumentMirrorSchema, VideoDocumentValidationError, type VideoDocumentValidationIssue, type VideoDocumentValidationIssueCode, type VideoDraft, type CaptionPart$1 as VideoDraftCaptionPart, type VideoDraftContent, type VideoDraftPartUnion, type Timeline$1 as VideoDraftTimeline, type Track$1 as VideoDraftTrack, type TrackItem$1 as VideoDraftTrackItem, type WaitForLocalSaveOptions, 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 };
1751
+ //#region src/entity-crdt/audio-script-assets.d.ts
1752
+ /** A resource is a snapshot of text; the native Loro text remains the editing authority. */
1753
+ declare function audioScriptAssetContent(payload: JsonObject): JsonObject;
1754
+ declare function audioScriptAssetHash(payload: JsonObject): string;
1755
+ declare function hasAudioScriptAsset(payload: JsonObject): boolean;
1756
+ /** Internal fingerprint prevents a resource from silently describing an older text revision. */
1757
+ declare function audioScriptAssetFields(payload: JsonObject, assetId: string): JsonObject;
1758
+ //#endregion
1759
+ export { type Aggregation, type AssembledCaptionContent, type AssembledPhoneticScriptContent, type Attachment, type AudioMediaAssetFact, type BgmPart, type CaptionContentInput, type CaptionDisplayCue, 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, type DocumentAudioScript, type DocumentAudioScriptState, ENTITY_TIMELINE_PROJECTION_SCHEMA_VERSION, type EditorFoundation, EntityDocumentState, type EntityGraphCommitOptions, EntityGraphHttpClient, type EntityGraphState, EntityTimelineEditor, type EntityTimelineIdFactory, EntityTimelineProjectionError, type EntityTimelineTrackRole, type FieldChange, type FieldPath, 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, LORO_ENTITY_SCHEMA, type LaneKind, type LinearClipSpeed, LoroEntityDocument, LoroEntityDraft, 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, applyEntityRows, applyEntityTimelineProjection, applyFieldChanges, arrangeMainTrackSeamlessly, assembleCaptionContent, assembleEntityContent, assemblePhoneticScriptContent, assembleScriptText, assertCanonicalEditorResources, assertEntityProjectionPreservesLegacy, assertFieldChanges, assertMediaAssetWritePolicy, assertValidVideoDocument, audioScriptAssetContent, audioScriptAssetFields, audioScriptAssetHash, base64ToBytes, buildInitialVideoDocument, buildSpeechHostMap, bytesToBase64, cascadeAfterVideoClipChanges, compileEntityRows, createEditSandbox, createMirrorVideoDocument, createMirrorVideoDocumentAdapter, createPlainMemoryAdapter, decodeDocVersionMark, derivePositionFromAbs, effectiveVideoClipDurationMs, encodeDocVersionMark, ensureEditorFoundation, ensureLaneTrack, fillMainTrackTimeGaps, findComposedAudioScript, findLaneTrack, fromVideoDocument, generatePartId, getAt, hasAudioScriptAsset, hostForAbsMs, importMediaAsset, isEmptyVideoClip, isImplementedSemanticOpKind, isMap, laneTrackId, mainTrackRanges, migrateLegacyTimelineToEntities, partDurationMs, partUnionSchema, prepareCaptionContent, projectEntityTimeline, readDocumentAudioScript, readEntityDocument, readMainTrackItems, readMengineEventStream, readPart, readPartDurationMs, readVideoDocumentFromDraft, reassignSpeechesToVideoClipsByTime, recalculateTimelineDuration, relativePositionForAbs, replayJournal, resolveAllSpeechOverlaps, resolveEntityTimelineLayout, resolveFieldPath, resolveSpeechOverlapByShiftingVideos, safeDurationMs, index_d_exports as schemas, selectAudioScriptSegment, snapshotToPlain, solveVideoDocument, speedOf, syncAggregatedClipsTimePosition, toVideoDocument, validateVideoDocument, videoDocumentMirrorSchema, videoDocumentSchema, writeVideoDocumentToDraft };