@mengine/medeo-client 3.0.0 → 3.0.1-dsl.0

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.
@@ -0,0 +1,478 @@
1
+ import { z } from "zod";
2
+ //#region src/schemas/shared.ts
3
+ const clipIdSchema = z.string().min(1).describe("The clip part ID on the timeline");
4
+ const clipIdsSchema = z.array(clipIdSchema).min(1).refine((ids) => new Set(ids).size === ids.length, { message: "Duplicate clip IDs are not allowed" }).describe("List of clip part IDs (no duplicates allowed)");
5
+ const mediaIdSchema = z.string().min(1).describe("The media asset ID");
6
+ const speechIdSchema = z.string().min(1).describe("The speech part ID on the timeline");
7
+ const timelineMsSchema = z.number().int().min(0).describe("Time position in milliseconds on the timeline (>= 0)");
8
+ const positiveMsSchema = z.number().int().positive().describe("Duration in milliseconds (> 0)");
9
+ const volumeSchema = z.number().min(-60).max(20).describe("Volume in decibels (-60.0 to 20.0; 0.0 = original, -60 = mute, +20 = max)");
10
+ const speechIdsSchema = z.array(speechIdSchema).min(1).refine((ids) => new Set(ids).size === ids.length, { message: "Duplicate speech IDs are not allowed" }).describe("List of speech part IDs (no duplicates allowed)");
11
+ const tangentHandleSchema = z.object({
12
+ x: z.number().finite(),
13
+ y: z.number().finite()
14
+ }).describe("Bezier tangent handle (x, y)");
15
+ const speedKeyframeSchema = z.object({
16
+ position: z.number().min(0).max(1),
17
+ rate: z.number().min(0),
18
+ in_tangent: tangentHandleSchema.optional(),
19
+ out_tangent: tangentHandleSchema.optional()
20
+ }).describe("A speed keyframe: normalized position (0..1), rate, optional tangents");
21
+ /**
22
+ * A clip's playback-speed fact, the only thing `SetVideoClipSpeedShift` writes.
23
+ * Mirrors the IDL `SpeedShift`: `category` is `linear` | `curve`, and `config`
24
+ * is a discriminated union — `{ linear: { speed } }` for a constant multiplier
25
+ * (the multiplier projection reads at `config.linear.speed`) or `{ curve: {
26
+ * keyframes } }` for a Bezier-controlled variable speed (RFC 02 / `reference/16`
27
+ * §0). Exactly one of `linear` / `curve` is present.
28
+ */
29
+ const speedShiftSchema = z.object({
30
+ category: z.enum(["linear", "curve"]),
31
+ mode: z.string(),
32
+ config: z.union([z.object({ linear: z.object({ speed: z.number().finite().positive() }) }), z.object({ curve: z.object({ keyframes: z.array(speedKeyframeSchema).min(2) }) })])
33
+ }).describe("Speed shift: linear multiplier or Bezier curve, mirroring the IDL shape");
34
+ const voiceSchema = z.object({
35
+ id: z.string().min(1),
36
+ name: z.string()
37
+ }).describe("TTS voice summary attached to a speech");
38
+ //#endregion
39
+ //#region src/schemas/speech-assets.ts
40
+ /**
41
+ * The materialized TTS result shared by `AddSpeeches` / `ChangeSpeechScript` /
42
+ * `ChangeSpeechVoice` (see `results/phase-4-side-effect-payload-contract.md`
43
+ * §1/§2). The side effect (TTS/ASR + billing) runs upstream; the op receives the
44
+ * stable speech + caption parts and writes them as authoritative facts. No
45
+ * cascade runs on write — the projection derives absolute positions on read.
46
+ *
47
+ * Each speech carries the anchoring fact directly (RFC 02 §4): the host video
48
+ * clip `anchor_part_id` and the `offset_ms` within it. The upstream caller
49
+ * already knows which clip a speech attaches to, so the op writes
50
+ * `{ mode:'anchored', anchorPartId, offsetMs }` verbatim — no write-time
51
+ * host-picking. Captions anchor to their speech via the caption part's
52
+ * `start_ms` (offset within the speech).
53
+ */
54
+ const speechAssetSchema = z.object({
55
+ speech_id: speechIdSchema.describe("The speech part ID (= side-effect speech_parts[].id)"),
56
+ anchor_part_id: clipIdSchema.describe("Host video clip part ID the speech anchors to (RFC 02 §4)"),
57
+ offset_ms: timelineMsSchema.describe("Offset within the host clip (speech.abs = host.abs + offset_ms)"),
58
+ audio_storage_key: z.string().min(1),
59
+ duration_ms: positiveMsSchema,
60
+ audio_script: z.string(),
61
+ volume: volumeSchema,
62
+ voice: voiceSchema,
63
+ origin_speech_id: z.string().min(1),
64
+ caption_ids: z.array(z.string().min(1)).describe("Caption part IDs owned by this speech")
65
+ });
66
+ const captionAssetSchema = z.object({
67
+ caption_id: z.string().min(1).describe("The caption part ID (= side-effect created_caption_parts[].id)"),
68
+ speech_part_id: speechIdSchema.describe("The owning speech part ID"),
69
+ text: z.string(),
70
+ start_ms: timelineMsSchema.describe("Offset within the host speech (caption.abs = speech.abs + start_ms)"),
71
+ duration_ms: positiveMsSchema
72
+ });
73
+ /** A materialized speech-subtree write (speeches + their captions). */
74
+ const speechAssetsSchema = z.object({
75
+ speeches: z.array(speechAssetSchema).min(1).describe("Materialized speech parts to write"),
76
+ captions: z.array(captionAssetSchema).describe("Materialized caption parts owned by the speeches")
77
+ });
78
+ //#endregion
79
+ //#region src/schemas/add-speeches.ts
80
+ /**
81
+ * Add speeches (and their captions). TTS runs upstream; the stable speech /
82
+ * caption parts arrive materialized (see `speech-assets.ts`). The op writes the
83
+ * parts and each speech's `{ mode:'anchored', anchorPartId, offsetMs }` fact
84
+ * verbatim — no write-time host-picking, no cascade (RFC 02 §4). The projection
85
+ * derives absolute positions on read.
86
+ */
87
+ const addSpeechesInputSchema = speechAssetsSchema.describe("Materialized speeches + captions to add");
88
+ //#endregion
89
+ //#region src/schemas/add-video-clips.ts
90
+ /**
91
+ * Add video clips to a track. Each clip's duration facts are separated so a
92
+ * single number is never overloaded (RFC 02 / `reference/16` §0b):
93
+ *
94
+ * - `media_duration_ms` is the source media's intrinsic full length (a resource
95
+ * fact, written to the part);
96
+ * - `play_in` / `play_out` are the optional trim window into that media; when
97
+ * omitted the whole media is used (`play_in=0`, `play_out=media_duration_ms`).
98
+ *
99
+ * The clip's effective timeline duration is derived by the projection from the
100
+ * trim window and `speed_shift` — it is never an input here.
101
+ */
102
+ const addVideoClipsInputSchema = z.object({
103
+ clips: z.array(z.object({
104
+ media_id: mediaIdSchema.describe("The media asset ID for the video clip"),
105
+ start_ms: timelineMsSchema.optional().describe("Absolute start time in milliseconds on the timeline"),
106
+ media_duration_ms: positiveMsSchema.describe("The source media's intrinsic full length in ms"),
107
+ play_in: timelineMsSchema.optional().describe("Trim window start in the media (default 0)"),
108
+ play_out: positiveMsSchema.optional().describe("Trim window end in the media (default media_duration_ms)"),
109
+ track_id: z.string().min(1).optional().describe("Target track ID (optional, defaults to main track)")
110
+ })).min(1).describe("List of video clips to create"),
111
+ before_clip_id: z.string().min(1).optional().describe("Insert new clips before this clip ID"),
112
+ after_clip_id: z.string().min(1).optional().describe("Insert new clips after this clip ID")
113
+ }).superRefine((data, ctx) => {
114
+ if (data.before_clip_id != null && data.after_clip_id != null) {
115
+ ctx.addIssue({
116
+ code: z.ZodIssueCode.custom,
117
+ message: "Cannot provide both before_clip_id and after_clip_id"
118
+ });
119
+ return;
120
+ }
121
+ const hasRelative = data.before_clip_id != null || data.after_clip_id != null;
122
+ for (let i = 0; i < data.clips.length; i++) {
123
+ const clip = data.clips[i];
124
+ if (hasRelative && clip.start_ms != null) ctx.addIssue({
125
+ code: z.ZodIssueCode.custom,
126
+ message: `clips[${i}].start_ms must not be provided when using before_clip_id or after_clip_id`,
127
+ path: [
128
+ "clips",
129
+ i,
130
+ "start_ms"
131
+ ]
132
+ });
133
+ if (!hasRelative && clip.start_ms == null) ctx.addIssue({
134
+ code: z.ZodIssueCode.custom,
135
+ message: `clips[${i}].start_ms is required when not using relative positioning`,
136
+ path: [
137
+ "clips",
138
+ i,
139
+ "start_ms"
140
+ ]
141
+ });
142
+ const playIn = clip.play_in ?? 0;
143
+ const playOut = clip.play_out ?? clip.media_duration_ms;
144
+ if (playOut > clip.media_duration_ms) ctx.addIssue({
145
+ code: z.ZodIssueCode.custom,
146
+ message: `clips[${i}].play_out ${playOut}ms exceeds media_duration_ms ${clip.media_duration_ms}ms`,
147
+ path: [
148
+ "clips",
149
+ i,
150
+ "play_out"
151
+ ]
152
+ });
153
+ if (playIn >= playOut) ctx.addIssue({
154
+ code: z.ZodIssueCode.custom,
155
+ message: `clips[${i}].play_in ${playIn}ms must be less than play_out ${playOut}ms`,
156
+ path: [
157
+ "clips",
158
+ i,
159
+ "play_in"
160
+ ]
161
+ });
162
+ }
163
+ });
164
+ //#endregion
165
+ //#region src/schemas/adjust-bgm-volume.ts
166
+ const adjustBgmVolumeInputSchema = z.object({ bgm: z.array(z.object({
167
+ bgm_id: clipIdSchema.describe("The bgm part ID to adjust volume for"),
168
+ volume: volumeSchema.describe("Volume in decibels (-60.0 to 20.0; 0.0 = original)")
169
+ })).min(1).describe("List of bgm parts with their new volume settings") });
170
+ //#endregion
171
+ //#region src/schemas/adjust-speech-volume.ts
172
+ const adjustSpeechVolumeInputSchema = z.object({ speeches: z.array(z.object({
173
+ speech_id: speechIdSchema.describe("The speech part ID to adjust volume for"),
174
+ volume: volumeSchema.describe("Volume in decibels (-60.0 to 20.0; 0.0 = original)")
175
+ })).min(1).describe("List of speeches with their new volume settings") });
176
+ //#endregion
177
+ //#region src/schemas/adjust-video-clip-duration.ts
178
+ /**
179
+ * Re-trim existing video clips (the user-facing "adjust duration" gesture is a
180
+ * trim of the source window). The new `play_in` / `play_out` are the facts; the
181
+ * effective timeline duration is derived from them and the clip's `speed_shift`,
182
+ * and the change reflows downstream clips, speeches, and the timeline inside the
183
+ * op's transaction (no caller-materialized cascade).
184
+ */
185
+ const adjustVideoClipDurationInputSchema = z.object({ clips: z.array(z.object({
186
+ clip_id: clipIdSchema.describe("The video clip part ID to re-trim"),
187
+ play_in: timelineMsSchema.describe("New trim window start in the source media"),
188
+ play_out: positiveMsSchema.describe("New trim window end in the source media")
189
+ })).min(1).describe("Video clips with their new trim windows") });
190
+ //#endregion
191
+ //#region src/schemas/adjust-video-clip-volume.ts
192
+ const adjustVideoClipVolumeInputSchema = z.object({ clips: z.array(z.object({
193
+ clip_id: clipIdSchema.describe("The video clip part ID to adjust volume for"),
194
+ volume: volumeSchema.describe("Volume in decibels (-60.0 to 20.0; 0.0 = original)")
195
+ })).min(1).describe("List of video clips with their new volume settings") });
196
+ //#endregion
197
+ //#region src/schemas/change-speech.ts
198
+ /**
199
+ * Change a speech's script or voice. Both re-run TTS upstream and return the
200
+ * regenerated speech / caption parts in the same materialized shape as
201
+ * `AddSpeeches` (`speech-assets.ts`); the op upserts them by id (the speech part
202
+ * id is preserved across a re-TTS), re-seats at `start_ms`, and reflows. Old
203
+ * caption parts no longer owned by the speech are removed via `caption_ids`.
204
+ */
205
+ const changeSpeechScriptInputSchema = speechAssetsSchema.describe("Regenerated speeches + captions (new script)");
206
+ const changeSpeechVoiceInputSchema = speechAssetsSchema.describe("Regenerated speeches + captions (new voice)");
207
+ //#endregion
208
+ //#region src/schemas/delete-bgm.ts
209
+ /**
210
+ * Remove the document BGM. Pure document edit: clears the bgm lane and removes
211
+ * the bgm part. Takes no input (a document holds at most one bgm); an empty
212
+ * object keeps the op signature uniform with the rest.
213
+ */
214
+ const deleteBgmInputSchema = z.object({}).describe("Remove the document BGM (no parameters)");
215
+ //#endregion
216
+ //#region src/schemas/delete-speeches.ts
217
+ /**
218
+ * Delete speeches with their captions. Pure document edit (no side effect): the
219
+ * op removes each speech part, cascade-deletes the captions it owns (via
220
+ * `caption_ids` / `speech_part_id`), drops their track items, and reflows.
221
+ */
222
+ const deleteSpeechesInputSchema = z.object({ speech_ids: speechIdsSchema.describe("Speech part IDs to delete (their captions cascade-delete)") });
223
+ //#endregion
224
+ //#region src/schemas/delete-video-clips.ts
225
+ /**
226
+ * How a delete handles the anchored subtree (speeches anchored to a deleted clip,
227
+ * and their captions) — a delete-op policy, not a data-model field (reference/17
228
+ * §6). `cascade` (default) removes the subtree; `detach` keeps the direct
229
+ * anchored children, re-pinning them to `absolute` so they stay on the timeline.
230
+ */
231
+ const anchoredDeletePolicySchema = z.enum(["cascade", "detach"]);
232
+ const deleteVideoClipsInputSchema = z.object({
233
+ clip_ids: clipIdsSchema.describe("List of video clip part IDs to delete from the main track"),
234
+ on_anchored: anchoredDeletePolicySchema.optional().describe("How to treat anchored children (default cascade)")
235
+ });
236
+ //#endregion
237
+ //#region src/schemas/move-speeches.ts
238
+ /**
239
+ * Move speeches in time. Pure document edit: the op re-seats each speech at its
240
+ * new absolute `start_ms`; the cascade reassigns it to the host video clip,
241
+ * resolves overlaps, and reflows. Captions follow their speech.
242
+ */
243
+ const moveSpeechesInputSchema = z.object({ speeches: z.array(z.object({
244
+ speech_id: speechIdSchema.describe("The speech part ID to move"),
245
+ new_start_ms: timelineMsSchema.describe("New absolute start time on the timeline")
246
+ })).min(1).describe("Speeches to move to new positions") });
247
+ //#endregion
248
+ //#region src/schemas/move-video-clips-by-anchor.ts
249
+ /**
250
+ * Where the moved block lands on the main track.
251
+ *
252
+ * A discriminated union rather than two optional `before_clip_id` /
253
+ * `after_clip_id` fields (the shape `addVideoClips` had to use, because there the
254
+ * two modes share a whole clip description): here the alternatives carry nothing
255
+ * in common, so making them mutually exclusive *by type* removes three runtime
256
+ * `superRefine` checks that would otherwise have to be written and tested.
257
+ *
258
+ * `track_start` is an explicit member, not the absence of an anchor. The
259
+ * agent-harness mutation this maps from treats "neither anchor given" as
260
+ * "move to the front" (`applyBatchMoveVideoClips` falls back to `insertIndex = 0`),
261
+ * which is a default buried in a tool description. Requiring the caller to name
262
+ * that intent keeps a forgotten field from silently reordering the timeline.
263
+ */
264
+ const moveAnchorSchema = z.discriminatedUnion("position", [
265
+ z.object({
266
+ position: z.literal("before"),
267
+ clip_id: clipIdSchema.describe("The moved block lands immediately before this clip")
268
+ }),
269
+ z.object({
270
+ position: z.literal("after"),
271
+ clip_id: clipIdSchema.describe("The moved block lands immediately after this clip")
272
+ }),
273
+ z.object({ position: z.literal("track_start") })
274
+ ]).describe("Where the moved block lands: before/after a reference clip, or at the head of the track");
275
+ /**
276
+ * What happens to the speeches anchored to the clips being moved.
277
+ *
278
+ * - `follow` keeps each speech anchored where it is, so it travels with its clip
279
+ * to the new position. In the anchored model this is the *no-op* branch: a
280
+ * speech's authoritative fact is `{ anchorPartId, offsetMs }` and its absolute
281
+ * time is derived on read from the host's position, so moving the host moves
282
+ * the speech with no write to the speech at all.
283
+ * - `keep_absolute` preserves each speech's current absolute landing instead, then
284
+ * re-anchors it to whichever clip now covers that time (RFC 02 §9.1/§11.1). This
285
+ * is the branch that costs an extra pass, and the one the FE timeline uses.
286
+ *
287
+ * **Required, with no default**, matching `deleteVideoClips` and
288
+ * `replaceVideoClipSequence`. The two branches decide which picture the user's
289
+ * narration ends up over, which is too consequential to infer from a missing
290
+ * field — and neither branch is "safe enough" to be the implicit one.
291
+ */
292
+ const movedClipAnchoredPolicySchema = z.enum(["follow", "keep_absolute"]);
293
+ /**
294
+ * Reorder a set of main-track clips relative to a reference clip.
295
+ *
296
+ * Distinct from `moveVideoClips`, which positions clips by absolute time
297
+ * (`new_start_ms`) and is what the FE timeline dispatches after a drag. Main-track
298
+ * clips are `sequential`-positioned, so absolute time is not authoritative state
299
+ * there (RFC 02 §4/§7): `moveVideoClips` has to *guess* an index back out of the
300
+ * time it was handed, whereas an anchor already is the ordinal fact being changed.
301
+ * Keeping them separate also isolates blast radius — this method can diverge on
302
+ * speech policy without touching the FE path.
303
+ *
304
+ * `clip_ids` need not be contiguous. They move as one block, keeping their
305
+ * relative order, which is the agent-harness `batch_move_video_clips` contract.
306
+ */
307
+ const moveVideoClipsByAnchorInputSchema = z.object({
308
+ clip_ids: clipIdsSchema.describe("Clips to move as one block, keeping their relative order. Need not be contiguous on the track."),
309
+ anchor: moveAnchorSchema,
310
+ on_anchored: movedClipAnchoredPolicySchema.describe("What happens to speeches anchored to the moved clips (required — see the policy doc)")
311
+ });
312
+ //#endregion
313
+ //#region src/schemas/move-video-clips.ts
314
+ const moveVideoClipsInputSchema = z.object({ clips: z.array(z.object({
315
+ clip_id: clipIdSchema.describe("The video clip part ID to move"),
316
+ new_start_ms: timelineMsSchema.describe("New absolute start time in milliseconds on the timeline"),
317
+ new_track_id: z.string().min(1).optional().describe("Target track ID to move the clip to (optional)")
318
+ })).min(1).describe("List of video clips to move to new positions") });
319
+ //#endregion
320
+ //#region src/schemas/replace-video-clip-content.ts
321
+ /**
322
+ * Replace the media backing existing video clips. The media import runs upstream
323
+ * (Director); its stable result — the new media id, intrinsic length, and the
324
+ * reset trim window — arrives materialized (see
325
+ * `results/phase-4-side-effect-payload-contract.md` §4). Director resets
326
+ * `play_in=0` / `play_out=media_duration_ms` and clears `speed_shift` on
327
+ * replacement. The clip `part_id`s (hence their track items) are unchanged; the
328
+ * editor reflows the main track from the new effective durations.
329
+ */
330
+ const replaceVideoClipContentInputSchema = z.object({ clips: z.array(z.object({
331
+ clip_id: clipIdSchema.describe("Existing video clip part ID to re-point"),
332
+ origin_media_id: mediaIdSchema.describe("The new media asset ID"),
333
+ media_duration_ms: positiveMsSchema.describe("The new media's intrinsic full length"),
334
+ play_in: timelineMsSchema.describe("Trim window start in the new media (usually 0)"),
335
+ play_out: positiveMsSchema.describe("Trim window end in the new media (usually = media_duration_ms)"),
336
+ volume: volumeSchema
337
+ })).min(1).describe("Video clips whose media is being replaced") });
338
+ //#endregion
339
+ //#region src/schemas/replace-video-clip-sequence.ts
340
+ /**
341
+ * What happens to the speeches anchored to the clips being replaced.
342
+ *
343
+ * - `remap` re-anchors each surviving speech to the new clip in the SAME POSITION
344
+ * of the sequence, keeping its offset — old[i]'s children become new[i]'s
345
+ * children. An old clip with no counterpart (fewer new clips than old) has its
346
+ * subtree deleted, because there is nothing left to anchor to.
347
+ * - `cascade` deletes every anchored speech (and its captions) outright, like
348
+ * `deleteVideoClips`.
349
+ *
350
+ * **Required, with no default.** The two branches differ in whether the user's
351
+ * narration survives, and the agent tool that drives this op makes its
352
+ * `preserve_speeches` flag required for that reason. A default here would let a
353
+ * caller that forgot the field silently delete speech.
354
+ */
355
+ const anchoredReplacePolicySchema = z.enum(["remap", "cascade"]);
356
+ /**
357
+ * Replace a contiguous run of main-track clips with a new run.
358
+ *
359
+ * A composite of delete + insert that cannot be expressed as the two ops in
360
+ * sequence, because the anchored speeches have to survive *across* the swap: with
361
+ * `remap` they are re-anchored positionally, which needs both the old and the new
362
+ * ids in the same transaction (ADR 0009 — the cascade stays in the editor, callers
363
+ * never re-wire anchors themselves).
364
+ *
365
+ * Duration facts follow `addVideoClips`: `media_duration_ms` is the source's
366
+ * intrinsic length and the trim window defaults to the whole media. The effective
367
+ * timeline duration is derived by the projection, never an input.
368
+ *
369
+ * `media_id` is optional: omitting it creates a **deliberate empty placeholder
370
+ * clip** (`origin_media_id: ''`) — structure with no picture. This is the only op
371
+ * that can produce one, and it is authoritative state, unlike the gap fillers the
372
+ * read-side solve mints (which never enter the document).
373
+ */
374
+ const replaceVideoClipSequenceInputSchema = z.object({
375
+ old_clip_ids: clipIdsSchema.describe("The clips being replaced: a contiguous main-track run, listed in timeline order"),
376
+ new_clips: z.array(z.object({
377
+ media_id: mediaIdSchema.optional().describe("The replacement media asset ID. Omit to create an empty placeholder clip."),
378
+ media_duration_ms: positiveMsSchema.describe("The source media's intrinsic full length in ms"),
379
+ play_in: timelineMsSchema.optional().describe("Trim window start in the media (default 0)"),
380
+ play_out: positiveMsSchema.optional().describe("Trim window end in the media (default media_duration_ms)")
381
+ })).min(1).describe("The replacement clips, in the order they take on the track"),
382
+ on_anchored: anchoredReplacePolicySchema.describe("What happens to speeches anchored to the replaced clips (required — see the policy doc)")
383
+ }).superRefine((data, ctx) => {
384
+ for (let i = 0; i < data.new_clips.length; i++) {
385
+ const clip = data.new_clips[i];
386
+ const playIn = clip.play_in ?? 0;
387
+ const playOut = clip.play_out ?? clip.media_duration_ms;
388
+ if (playOut > clip.media_duration_ms) ctx.addIssue({
389
+ code: z.ZodIssueCode.custom,
390
+ message: `new_clips[${i}].play_out ${playOut}ms exceeds media_duration_ms ${clip.media_duration_ms}ms`,
391
+ path: [
392
+ "new_clips",
393
+ i,
394
+ "play_out"
395
+ ]
396
+ });
397
+ if (playIn >= playOut) ctx.addIssue({
398
+ code: z.ZodIssueCode.custom,
399
+ message: `new_clips[${i}].play_in ${playIn}ms must be less than play_out ${playOut}ms`,
400
+ path: [
401
+ "new_clips",
402
+ i,
403
+ "play_in"
404
+ ]
405
+ });
406
+ }
407
+ });
408
+ //#endregion
409
+ //#region src/schemas/set-bgm.ts
410
+ /**
411
+ * Set the document BGM. The media's stable result (storage key) arrives
412
+ * materialized from upstream (see
413
+ * `results/phase-4-side-effect-payload-contract.md` §3). The op upserts the bgm
414
+ * part and seats it on the bgm lane; its effective length is always the whole
415
+ * timeline, derived by the projection on read — so there is no `duration_ms`
416
+ * input or fact (RFC 02 / `reference/16` §0b). A `bgm_id` lets the op replace an
417
+ * existing bgm part by id.
418
+ */
419
+ const setBgmInputSchema = z.object({
420
+ bgm_id: z.string().min(1).describe("The bgm part ID to write"),
421
+ audio_storage_key: z.string().min(1),
422
+ origin_media_id: mediaIdSchema,
423
+ volume: volumeSchema
424
+ });
425
+ //#endregion
426
+ //#region src/schemas/set-caption-style.ts
427
+ /**
428
+ * Set the caption visual style. GLOBAL by design: the style applies to every
429
+ * caption part in the document — it carries NO `caption_id`. This mirrors the FE,
430
+ * whose caption-style store (`caption-style.ts:persistCaptionStylePatch`) iterates
431
+ * ALL captions and writes the same normalized style to each; the product has a
432
+ * single document-wide caption style, not per-caption styling.
433
+ *
434
+ * Every field is optional and maps to a `CaptionStyle` attribute (snake_case
435
+ * IDL). A field present in the input is written to every caption; a field ABSENT
436
+ * from the input is left untouched on each caption (the editor merges the patch
437
+ * onto each caption's existing style — this is a value edit, not a full-style
438
+ * replace, so a partial patch such as "recolor only" does not wipe font size).
439
+ *
440
+ * Pure document edit, no cascade — captions keep their positions; only the style
441
+ * sub-map of each caption part changes.
442
+ */
443
+ const setCaptionStyleInputSchema = z.object({
444
+ font_id: z.string().min(1).optional().describe("Font ID referencing a font from the font library"),
445
+ font_size: z.number().positive().optional().describe("Font size in points"),
446
+ font_color: z.string().min(1).optional().describe("Font color as hex string, e.g. \"#FFFFFF\""),
447
+ font_weight: z.number().int().optional().describe("Numeric font weight, e.g. 400 or 700"),
448
+ entrance_animation: z.string().optional().describe("Entrance animation preset ID, e.g. \"fade\" or \"none\""),
449
+ entrance_animation_duration_ms: z.number().min(0).optional().describe("Entrance animation duration in ms"),
450
+ stroke_color: z.string().min(1).optional().describe("Outline/stroke color as hex string, e.g. \"#000000\""),
451
+ stroke_width: z.number().min(0).optional().describe("Outline/stroke width in pixels"),
452
+ position_x: z.number().optional().describe("Caption center X as a fraction (0.0 to 1.0)"),
453
+ position_y: z.number().optional().describe("Caption center Y as a fraction (0.0 to 1.0)")
454
+ }).describe("Document-wide caption style patch (no caption_id; applies to every caption)");
455
+ //#endregion
456
+ //#region src/schemas/set-caption-visibility.ts
457
+ /**
458
+ * Toggle caption visibility (the caption track's `is_hidden` flag). Pure
459
+ * document edit, no cascade — captions keep their positions; only the lane's
460
+ * hidden flag changes.
461
+ */
462
+ const setCaptionVisibilityInputSchema = z.object({ is_hidden: z.boolean().describe("Whether the caption track is hidden") });
463
+ //#endregion
464
+ //#region src/schemas/set-video-clip-speed-shift.ts
465
+ /**
466
+ * Set the playback speed of existing video clips. Per the speed-shift decision
467
+ * (`reference/16` §0): the op writes only the `speed_shift` fact — it does NOT
468
+ * store an effective `duration_ms` (projection derives it from the trim window /
469
+ * speed) and does NOT scale anchored speeches' relative offsets (offsets stay
470
+ * put; the cascade reflows absolute positions). A `null` speed_shift clears the
471
+ * speed back to original (1×).
472
+ */
473
+ const setVideoClipSpeedShiftInputSchema = z.object({ clips: z.array(z.object({
474
+ clip_id: clipIdSchema.describe("The video clip part ID to set speed for"),
475
+ speed_shift: speedShiftSchema.nullable().describe("The new speed setting, or null to reset to 1×")
476
+ })).min(1).describe("Video clips with their new speed settings") });
477
+ //#endregion
478
+ export { addSpeechesInputSchema, addVideoClipsInputSchema, adjustBgmVolumeInputSchema, adjustSpeechVolumeInputSchema, adjustVideoClipDurationInputSchema, adjustVideoClipVolumeInputSchema, anchoredDeletePolicySchema, anchoredReplacePolicySchema, changeSpeechScriptInputSchema, changeSpeechVoiceInputSchema, clipIdSchema, clipIdsSchema, deleteBgmInputSchema, deleteSpeechesInputSchema, deleteVideoClipsInputSchema, mediaIdSchema, moveAnchorSchema, moveSpeechesInputSchema, moveVideoClipsByAnchorInputSchema, moveVideoClipsInputSchema, movedClipAnchoredPolicySchema, positiveMsSchema, replaceVideoClipContentInputSchema, replaceVideoClipSequenceInputSchema, setBgmInputSchema, setCaptionStyleInputSchema, setCaptionVisibilityInputSchema, setVideoClipSpeedShiftInputSchema, speechAssetsSchema, speechIdSchema, speechIdsSchema, speedShiftSchema, timelineMsSchema, voiceSchema, volumeSchema };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as MedeoDsl, d as VideoDraft } from "./index-DuM7I4Ku.js";
1
+ import { M as MedeoDsl, d as VideoDraft } from "./index-B1Lqm_Z1.js";
2
2
  import { LoroDoc } from "loro-crdt";
3
3
 
4
4
  //#region src/testing/in-memory-mengine-server.d.ts
@@ -18,6 +18,7 @@ declare class InMemoryMengineServer {
18
18
  private readonly subscribers;
19
19
  private seq;
20
20
  private hasSnapshot;
21
+ private readonly revisions;
21
22
  /**
22
23
  * Close every open SSE stream, simulating a network drop. Clients reconnect
23
24
  * (a fresh `/events`) and catch up via their next sync — used to exercise
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as bytesToBase64, t as base64ToBytes } from "./base64-D-jd-dr5.js";
2
- import { a as DslEditor, i as createInitialMedeoDsl, l as assertDslDocument, n as toVideoDraft, s as MedeoDsl, u as documentFormat } from "./dsl-Cpk8WxcZ.js";
2
+ import { _ as DslProjectionError, a as DslEditor, d as documentFormat, i as createInitialMedeoDsl, l as assertDslDocument, n as toVideoDraft, s as MedeoDsl, u as assertPhoneticBindingFormat } from "./dsl-BngbR2zr.js";
3
3
  import { t as classifyUpdate } from "./loro-relay-doc-Bi6JKqtQ.js";
4
4
  import { LoroDoc, VersionVector, encodeFrontiers } from "loro-crdt";
5
5
  //#region src/testing/in-memory-mengine-server.ts
@@ -19,6 +19,7 @@ var InMemoryMengineServer = class {
19
19
  subscribers = /* @__PURE__ */ new Set();
20
20
  seq = 0;
21
21
  hasSnapshot = false;
22
+ revisions = /* @__PURE__ */ new Map();
22
23
  /**
23
24
  * Close every open SSE stream, simulating a network drop. Clients reconnect
24
25
  * (a fresh `/events`) and catch up via their next sync — used to exercise
@@ -39,6 +40,7 @@ var InMemoryMengineServer = class {
39
40
  try {
40
41
  this.doc.import(dsl.doc.export({ mode: "snapshot" }));
41
42
  this.hasSnapshot = true;
43
+ this.revisions.set(this.seq, this.doc.export({ mode: "snapshot" }));
42
44
  return new Response(await this.handleSnapshot().text(), {
43
45
  status: 201,
44
46
  headers: { "content-type": "application/json" }
@@ -47,22 +49,33 @@ var InMemoryMengineServer = class {
47
49
  dsl.dispose();
48
50
  }
49
51
  }
50
- if (path === "draft" && method === "GET") {
52
+ const revision = /^revisions\/(\d+)\/draft$/.exec(path);
53
+ if ((path === "draft" || revision) && method === "GET") {
51
54
  if (!this.hasSnapshot) return this.handleSnapshot();
52
- assertDslDocument(this.doc);
53
- const dsl = new MedeoDsl(this.doc);
55
+ const seq = revision ? Number(revision[1]) : this.seq;
56
+ const snapshot = this.revisions.get(seq);
57
+ if (!snapshot) return Response.json({
58
+ code: "not_found",
59
+ message: "revision not found"
60
+ }, { status: 404 });
61
+ const attached = new LoroDoc();
62
+ attached.import(snapshot);
63
+ const dsl = new MedeoDsl(attached);
54
64
  try {
65
+ assertDslDocument(attached);
55
66
  return Response.json({
56
67
  ...toVideoDraft(dsl.getSnapshot()),
57
- version: this.version()
68
+ version: this.version(attached, seq)
58
69
  });
59
70
  } catch (error) {
60
- return Response.json({ error: {
61
- code: "projection_unsupported",
62
- message: String(error)
63
- } }, { status: 422 });
71
+ return Response.json({
72
+ code: revision ? "revision_unprojectable" : "projection_unsupported",
73
+ message: String(error),
74
+ ...error instanceof DslProjectionError ? { issues: error.issues } : {}
75
+ }, { status: 422 });
64
76
  } finally {
65
77
  dsl.dispose();
78
+ attached.free();
66
79
  }
67
80
  }
68
81
  if (/^\/internal\/mengine\/v1\/docs\/[^/]+\/bootstrap$/.test(new URL(url).pathname) && method === "POST") return this.handleBootstrap(init);
@@ -81,11 +94,11 @@ var InMemoryMengineServer = class {
81
94
  const afterDocId = url.slice(start + 21);
82
95
  return afterDocId.slice(afterDocId.indexOf("/") + 1);
83
96
  }
84
- version() {
97
+ version(doc = this.doc, seq = this.seq) {
85
98
  return {
86
- update_seq: this.seq,
87
- server_vv: bytesToBase64(this.doc.oplogVersion().encode()),
88
- frontiers: bytesToBase64(encodeFrontiers(this.doc.oplogFrontiers()))
99
+ update_seq: seq,
100
+ server_vv: bytesToBase64(doc.oplogVersion().encode()),
101
+ frontiers: bytesToBase64(encodeFrontiers(doc.oplogFrontiers()))
89
102
  };
90
103
  }
91
104
  handleSnapshot() {
@@ -104,6 +117,7 @@ var InMemoryMengineServer = class {
104
117
  if (body.snapshot != null && !this.hasSnapshot) {
105
118
  this.doc.import(base64ToBytes(body.snapshot));
106
119
  this.hasSnapshot = true;
120
+ this.revisions.set(this.seq, this.doc.export({ mode: "snapshot" }));
107
121
  }
108
122
  return this.handleSnapshot();
109
123
  }
@@ -167,7 +181,13 @@ var InMemoryMengineServer = class {
167
181
  probe.import(this.doc.export({ mode: "snapshot" }));
168
182
  probe.import(data);
169
183
  const format = documentFormat(probe);
170
- if (format === "legacy" || format === "mixed") return Response.json({
184
+ let unsupported = format === "legacy" || format === "mixed";
185
+ if (format === "dsl") try {
186
+ assertPhoneticBindingFormat(probe);
187
+ } catch {
188
+ unsupported = true;
189
+ }
190
+ if (unsupported) return Response.json({
171
191
  kind: "rejected",
172
192
  code: "unsupported_document_format",
173
193
  message: "Retired document content roots are not supported",
@@ -179,6 +199,7 @@ var InMemoryMengineServer = class {
179
199
  this.doc.import(data);
180
200
  this.hasSnapshot = true;
181
201
  this.seq += 1;
202
+ this.revisions.set(this.seq, this.doc.export({ mode: "snapshot" }));
182
203
  const meta = extractMeta(this.doc, baseVV);
183
204
  const stored = {
184
205
  updateSeq: this.seq,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mengine/medeo-client",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-dsl.0",
4
4
  "license": "UNLICENSED",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,6 +16,7 @@
16
16
  ".": "./dist/index.js",
17
17
  "./dsl": "./dist/dsl.js",
18
18
  "./relay": "./dist/relay.js",
19
+ "./schemas": "./dist/schemas.js",
19
20
  "./testing": "./dist/testing.js",
20
21
  "./package.json": "./package.json"
21
22
  },
@@ -25,24 +26,25 @@
25
26
  },
26
27
  "dependencies": {
27
28
  "@noble/hashes": "^2.4.0",
28
- "@mengine/storage": "3.0.0",
29
- "@mengine/sync": "3.0.0",
30
- "@mengine/utils": "3.0.0"
29
+ "zod": "^4.4.3",
30
+ "@mengine/storage": "3.0.1-dsl.0",
31
+ "@mengine/utils": "3.0.1-dsl.0",
32
+ "@mengine/sync": "3.0.1-dsl.0"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@types/node": "^25.9.1",
34
36
  "@typescript/native-preview": "7.0.0-dev.20260521.1",
35
- "loro-crdt": "^1.16.4",
37
+ "loro-crdt": "^1.16.1",
36
38
  "loro-mirror": "2.3.3",
37
39
  "tsx": "^4.22.3",
38
40
  "typescript": "^6.0.3",
39
41
  "vite-plugin-wasm": "^3.6.0",
40
42
  "vite-plus": "^0.1.23",
41
- "@mengine/medeo-dsl": "0.0.0",
42
- "@mengine/idl-codegen": "0.0.0"
43
+ "@mengine/idl-codegen": "0.0.0",
44
+ "@mengine/medeo-dsl": "0.0.0"
43
45
  },
44
46
  "peerDependencies": {
45
- "loro-crdt": "^1.16.4"
47
+ "loro-crdt": "^1.16.1"
46
48
  },
47
49
  "inlinedDependencies": {
48
50
  "immer": "10.2.0",