@mengine/medeo-tool 1.2.1-alpha.0 → 1.2.1-alpha.8

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.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { JournalEntry, MengineDocSession, PartIdFactory, SemanticOpName, VideoDocument, VideoDraft, fromVideoDocument } from "@mengine/medeo-client";
1
+ import { _ as SandboxEntity, a as EntityFacade, b as UpdateEntityInput, c as ImportAssetInput, d as JsonValue, f as KnownEntityKind, g as RelationFacade, h as LinkRelationInput, i as EntityCommand, l as JsonObject, m as LinkGeneratedRelationInput, n as CreateEntityInput, o as EntityPlanState, p as KnownRelationKind, r as DeleteEntityInput, s as EntityStoreSnapshot, t as AuthorableRelationKind, u as JsonPrimitive, v as SandboxRelation, y as UnlinkRelationInput } from "./entity-contract-DycLxdQ5.mjs";
2
+ import { JournalEntry, ManualSyncDoc, MediaAssetFact, PartIdFactory, SemanticOpName, VideoDocument, VideoDraft, fromVideoDocument } from "@mengine/medeo-client";
2
3
  import { AddSpeechesInput, AddVideoClipsInput, AdjustBgmVolumeInput, AdjustSpeechVolumeInput, AdjustVideoClipDurationInput, AdjustVideoClipVolumeInput, ChangeSpeechScriptInput, ChangeSpeechVoiceInput, DeleteBgmInput, DeleteSpeechesInput, DeleteVideoClipsInput, MoveSpeechesInput, MoveVideoClipsByAnchorInput, MoveVideoClipsInput, ReplaceVideoClipContentInput, ReplaceVideoClipSequenceInput, SetBgmInput, SetCaptionStyleInput, SetCaptionVisibilityInput, SetVideoClipSpeedShiftInput } from "@mengine/medeo-client/schemas";
3
4
 
4
5
  //#region src/document/compact-projection.d.ts
@@ -32,6 +33,9 @@ declare function collectAffectedPartIds(journal: readonly JournalEntry[]): Set<s
32
33
  */
33
34
  declare function renderPreview(document: VideoDocument, journal: readonly JournalEntry[]): string;
34
35
  //#endregion
36
+ //#region src/entity/entity-sandbox.d.ts
37
+ type DomainIdFactory = (prefix: 'entity' | 'relation') => string;
38
+ //#endregion
35
39
  //#region src/sandbox/script-session.d.ts
36
40
  /**
37
41
  * Runtime-neutral edit-sandbox session: `edit.*` / `timeline.*` / checkpoint
@@ -45,9 +49,15 @@ interface SandboxCheckpoint {
45
49
  readonly index: number;
46
50
  }
47
51
  interface ChangePlan {
52
+ readonly plan_kind: 'timeline' | 'entities';
48
53
  doc_id: string;
49
54
  base_version: string;
50
55
  ops: readonly JournalEntry[];
56
+ entity_base_revision: number;
57
+ entity_commands: readonly EntityCommand[];
58
+ entity_rows?: EntityStoreSnapshot;
59
+ deleted_entity_ids?: readonly string[];
60
+ deleted_relation_ids?: readonly string[];
51
61
  preview: string;
52
62
  logs: string[];
53
63
  }
@@ -57,6 +67,10 @@ interface EditSandboxSessionOptions {
57
67
  onLog?: (line: string) => void;
58
68
  /** Notify host that the streamed journal was truncated to `index` (rollback). */
59
69
  onTruncate?: (index: number) => void;
70
+ entityState?: EntityStoreSnapshot;
71
+ domainIdFactory?: DomainIdFactory;
72
+ onEntityCommand?: (command: EntityCommand) => void;
73
+ onEntityTruncate?: (index: number) => void;
60
74
  }
61
75
  interface TimelineClipDescriptor {
62
76
  id: string;
@@ -83,6 +97,7 @@ declare class EditSandboxSession {
83
97
  private readonly onEntry;
84
98
  private readonly onLog;
85
99
  private readonly onTruncate;
100
+ private readonly entitySandbox;
86
101
  private current;
87
102
  /** Adapter journal length already accounted for — new slices are real commits. */
88
103
  private adapterJournalSeen;
@@ -92,6 +107,8 @@ declare class EditSandboxSession {
92
107
  private logCapped;
93
108
  readonly edit: EditFacade;
94
109
  readonly timeline: TimelineFacade;
110
+ readonly entities: EntityFacade;
111
+ readonly relations: RelationFacade;
95
112
  readonly console: ConsoleShim;
96
113
  readonly checkpoint: () => SandboxCheckpoint;
97
114
  readonly rollbackTo: (cp: SandboxCheckpoint) => void;
@@ -123,8 +140,8 @@ interface EditFacade {
123
140
  deleteSpeeches: (input: DeleteSpeechesInput) => Promise<void>;
124
141
  deleteVideoClips: (input: DeleteVideoClipsInput) => Promise<void>;
125
142
  moveSpeeches: (input: MoveSpeechesInput) => Promise<void>;
126
- moveVideoClipsByAnchor: (input: MoveVideoClipsByAnchorInput) => Promise<void>;
127
143
  moveVideoClips: (input: MoveVideoClipsInput) => Promise<void>;
144
+ moveVideoClipsByAnchor: (input: MoveVideoClipsByAnchorInput) => Promise<void>;
128
145
  replaceVideoClipContent: (input: ReplaceVideoClipContentInput) => Promise<void>;
129
146
  replaceVideoClipSequence: (input: ReplaceVideoClipSequenceInput) => Promise<void>;
130
147
  setBgm: (input: SetBgmInput) => Promise<void>;
@@ -157,8 +174,12 @@ interface RunEditScriptOptions {
157
174
  baseVersion: string;
158
175
  script: string;
159
176
  inputs?: Record<string, unknown>;
177
+ /** Authoritative entity/relation rows and revision fetched for this document. */
178
+ entityState?: EntityStoreSnapshot;
160
179
  /** Deterministic id mint label for tests; omit to use the default ULID factory. */
161
180
  idLabel?: string;
181
+ /** @internal Select the graph-native Entity session used by the production host. */
182
+ entityOnly?: boolean;
162
183
  /** Hard wall-clock timeout; default 2000 ms. */
163
184
  timeoutMs?: number;
164
185
  /** V8 old-generation ceiling for the worker; default 256 MB. */
@@ -181,6 +202,7 @@ type EditScriptResult = {
181
202
  };
182
203
  partial: {
183
204
  ops: readonly JournalEntry[];
205
+ entityCommands: readonly EntityCommand[];
184
206
  logs: string[];
185
207
  };
186
208
  };
@@ -192,9 +214,9 @@ declare const MEDEO_TOOL_DESCRIPTION: string;
192
214
  //#endregion
193
215
  //#region src/schema.d.ts
194
216
  declare const MEDEO_TOOL_NAME = "medeo";
195
- type MedeoToolOp = 'snapshot' | 'run-edit-script' | 'commit-plan';
217
+ type MedeoToolOp = 'snapshot' | 'migrate-legacy' | 'run-edit-script' | 'commit-plan';
196
218
  /**
197
- * JSON Schema for the host-facing three-op `medeo` tool surface.
219
+ * JSON Schema for the host-facing `medeo` tool surface.
198
220
  *
199
221
  * The schema intentionally does not return or accept the full op journal:
200
222
  * journals stay in the tool process and are referenced by `plan_id`. This keeps
@@ -208,7 +230,7 @@ declare const MEDEO_TOOL_PARAMETERS: {
208
230
  readonly properties: {
209
231
  readonly op: {
210
232
  readonly type: 'string';
211
- readonly enum: readonly ['snapshot', 'run-edit-script', 'commit-plan'];
233
+ readonly enum: readonly ['snapshot', 'migrate-legacy', 'run-edit-script', 'commit-plan'];
212
234
  readonly description: 'Which Medeo document operation to run.';
213
235
  };
214
236
  readonly doc_id: {
@@ -219,11 +241,115 @@ declare const MEDEO_TOOL_PARAMETERS: {
219
241
  readonly script: {
220
242
  readonly type: 'string';
221
243
  readonly minLength: 1;
222
- readonly description: 'JavaScript body for run-edit-script. It receives edit, timeline, checkpoint, rollbackTo, inputs, and console; perform all calculations in the script.';
244
+ readonly description: 'JavaScript body for run-edit-script. Use edit, timeline, entities, relations, checkpoint, rollbackTo, inputs, and console. Asset import, media relations, and timeline entity edits share one entity plan.';
223
245
  };
224
246
  readonly inputs: {
225
247
  readonly type: 'object';
226
- readonly description: 'Pre-materialized, side-effect-free values passed into the script. Generation and network IO must happen in the host before this call.';
248
+ readonly description: 'Pre-materialized, side-effect-free values passed into the script, including recalled generation lineage and asset facts. Generation and network IO must happen in the host before this call.';
249
+ };
250
+ readonly asset_facts: {
251
+ readonly type: 'array';
252
+ readonly description: 'Factual asset metadata recalled by the host for migrate-legacy only. The package reads the canonical legacy snapshot and version itself; never supply a clip trim window as media duration.';
253
+ readonly items: {
254
+ readonly oneOf: readonly [{
255
+ readonly type: 'object';
256
+ readonly additionalProperties: false;
257
+ readonly required: readonly ['assetId', 'kind'];
258
+ readonly properties: {
259
+ readonly assetId: {
260
+ readonly type: 'string';
261
+ readonly minLength: 1;
262
+ };
263
+ readonly kind: {
264
+ readonly const: 'image';
265
+ };
266
+ readonly storageKey: {
267
+ readonly type: 'string';
268
+ readonly minLength: 1;
269
+ };
270
+ };
271
+ }, {
272
+ readonly type: 'object';
273
+ readonly additionalProperties: false;
274
+ readonly required: readonly ['assetId', 'kind', 'durationMs'];
275
+ readonly properties: {
276
+ readonly assetId: {
277
+ readonly type: 'string';
278
+ readonly minLength: 1;
279
+ };
280
+ readonly kind: {
281
+ readonly const: 'video';
282
+ };
283
+ readonly durationMs: {
284
+ readonly type: 'integer';
285
+ readonly minimum: 1;
286
+ };
287
+ readonly storageKey: {
288
+ readonly type: 'string';
289
+ readonly minLength: 1;
290
+ };
291
+ };
292
+ }, {
293
+ readonly type: 'object';
294
+ readonly additionalProperties: false;
295
+ readonly required: readonly ['assetId', 'kind', 'durationMs', 'storageKey'];
296
+ readonly properties: {
297
+ readonly assetId: {
298
+ readonly type: 'string';
299
+ readonly minLength: 1;
300
+ };
301
+ readonly kind: {
302
+ readonly const: 'audio';
303
+ };
304
+ readonly durationMs: {
305
+ readonly type: 'integer';
306
+ readonly minimum: 1;
307
+ };
308
+ readonly storageKey: {
309
+ readonly type: 'string';
310
+ readonly minLength: 1;
311
+ };
312
+ };
313
+ }, {
314
+ readonly type: 'object';
315
+ readonly additionalProperties: false;
316
+ readonly required: readonly ['assetId', 'kind', 'durationMs', 'storageKey', 'voice'];
317
+ readonly properties: {
318
+ readonly assetId: {
319
+ readonly type: 'string';
320
+ readonly minLength: 1;
321
+ };
322
+ readonly durationMs: {
323
+ readonly type: 'integer';
324
+ readonly minimum: 1;
325
+ };
326
+ readonly storageKey: {
327
+ readonly type: 'string';
328
+ readonly minLength: 1;
329
+ };
330
+ readonly voice: {
331
+ readonly type: 'object';
332
+ readonly additionalProperties: false;
333
+ readonly required: readonly ['system', 'key'];
334
+ readonly properties: {
335
+ readonly system: {
336
+ readonly const: 'voice-library';
337
+ };
338
+ readonly key: {
339
+ readonly type: 'string';
340
+ readonly minLength: 1;
341
+ };
342
+ readonly name: {
343
+ readonly type: 'string';
344
+ };
345
+ };
346
+ };
347
+ readonly kind: {
348
+ readonly const: 'voice';
349
+ };
350
+ };
351
+ }];
352
+ };
227
353
  };
228
354
  readonly timeout_ms: {
229
355
  readonly type: 'integer';
@@ -246,11 +372,25 @@ declare const MEDEO_TOOL_PARAMETERS: {
246
372
  };
247
373
  readonly validation: {
248
374
  readonly type: 'string';
249
- readonly enum: readonly ['version', 'preflight'];
250
- readonly description: 'commit-plan mode: version rejects any concurrent change; preflight revalidates each op against the current snapshot.';
375
+ readonly enum: readonly ['version'];
376
+ readonly description: 'Commit with Entity revision CAS; reject concurrent changes.';
251
377
  };
252
378
  };
253
379
  readonly oneOf: readonly [{
380
+ readonly required: readonly ['op', 'doc_id', 'asset_facts'];
381
+ readonly properties: {
382
+ readonly op: {
383
+ readonly const: 'migrate-legacy';
384
+ };
385
+ readonly doc_id: {
386
+ readonly $ref: '#/properties/doc_id';
387
+ };
388
+ readonly asset_facts: {
389
+ readonly $ref: '#/properties/asset_facts';
390
+ };
391
+ };
392
+ readonly additionalProperties: false;
393
+ }, {
254
394
  readonly required: readonly ['op', 'doc_id'];
255
395
  readonly properties: {
256
396
  readonly op: {
@@ -310,23 +450,39 @@ declare const MEDEO_TOOL_PARAMETERS: {
310
450
  //#region src/session/commit-plan.d.ts
311
451
  /**
312
452
  * A sandbox journal plus the opaque version token taken at fork time.
313
- * `commitPlan` rejects the whole plan when the live session has moved on
453
+ * `commitPlan` rejects the whole plan when the live document has moved on
314
454
  * (phase-1 version gate), or localizes a business conflict to a journal
315
455
  * entry under `{ validation: 'preflight' }`.
316
456
  */
317
457
  interface CommitPlan {
318
- /** `session.version()` at the moment the sandbox was forked. */
458
+ /** Encoded `ManualSyncDoc.versionMark()` from when the sandbox was forked. */
319
459
  base_version: string;
320
460
  ops: readonly JournalEntry[];
321
461
  }
462
+ interface CommitPlanWarning {
463
+ kind: 'pull_failed';
464
+ message: string;
465
+ }
322
466
  type CommitPlanResult = {
323
467
  kind: 'committed';
324
468
  ops_applied: number;
469
+ collaborated: boolean;
470
+ warnings?: CommitPlanWarning[];
471
+ } | {
472
+ kind: 'unconfirmed';
473
+ reason: 'push_failed';
474
+ ops_applied: number;
475
+ message: string;
325
476
  } | {
326
477
  kind: 'rejected';
327
478
  reason: 'version_mismatch';
328
479
  expected: string;
329
480
  actual: string;
481
+ } | {
482
+ kind: 'rejected';
483
+ reason: 'push_rejected';
484
+ code?: string;
485
+ message: string;
330
486
  } | {
331
487
  kind: 'rejected';
332
488
  reason: 'op_conflict'; /** Failing entry index in the journal — agent rerun anchor. */
@@ -339,18 +495,18 @@ interface CommitPlanOptions {
339
495
  validation?: 'version' | 'preflight';
340
496
  }
341
497
  /**
342
- * Replay a sandbox journal into a live session through its document adapter
343
- * (SemanticEditor Loro mengine-server).
498
+ * Replay a sandbox journal into a manually-synchronized document and push the
499
+ * whole plan as one causally complete update.
344
500
  *
345
- * - Default / `{ validation: 'version' }`: if `session.version()`
346
- * `plan.base_version`, reject with zero writes.
501
+ * - Default / `{ validation: 'version' }`: if the current document mark differs
502
+ * from `plan.base_version`, reject with zero writes.
347
503
  * - `{ validation: 'preflight' }`: skip the version gate; revalidate each op
348
504
  * against a PlainMemoryAdapter seeded from the current live snapshot, then
349
505
  * replay for real. A SchemaValidator failure becomes `op_conflict` with the
350
506
  * failing entry's index. Journal integrity errors (unrecorded/unconsumed
351
507
  * ids) still propagate as throws in both modes.
352
508
  */
353
- declare function commitPlan(session: MengineDocSession, plan: CommitPlan, options?: CommitPlanOptions): Promise<CommitPlanResult>;
509
+ declare function commitPlan(doc: ManualSyncDoc, plan: CommitPlan, options?: CommitPlanOptions): Promise<CommitPlanResult>;
354
510
  //#endregion
355
511
  //#region src/host-tool.d.ts
356
512
  type ContextualValue<T> = T | ((docId: string) => T | undefined);
@@ -358,7 +514,7 @@ interface CreateMedeoToolOptions {
358
514
  /**
359
515
  * Mengine HTTP origin for a document. The host owns environment routing
360
516
  * (local/stg/prd/lane) and may return a different origin per document.
361
- * Sessions cache by doc id, so the origin must remain stable for that doc.
517
+ * Documents cache by doc id, so the origin must remain stable for that doc.
362
518
  */
363
519
  httpOrigin: ContextualValue<string>;
364
520
  /** Optional bearer token, evaluated for each HTTP request. */
@@ -375,6 +531,7 @@ interface CreateMedeoToolOptions {
375
531
  */
376
532
  loadInitialDraft?: (docId: string) => Promise<VideoDraft>;
377
533
  fetchImpl?: typeof fetch;
534
+ /** @deprecated ManualSyncDoc has no SSE or reconnect loop. */
378
535
  sseReconnectDelayMs?: number;
379
536
  /** Defaults passed to runEditScript; each call may override them. */
380
537
  sandbox?: {
@@ -401,6 +558,10 @@ interface MedeoModelContext {
401
558
  type MedeoToolInput = {
402
559
  op: 'snapshot';
403
560
  doc_id: string;
561
+ } | {
562
+ op: 'migrate-legacy';
563
+ doc_id: string;
564
+ asset_facts: readonly MediaAssetFact[];
404
565
  } | {
405
566
  op: 'run-edit-script';
406
567
  doc_id: string;
@@ -415,24 +576,63 @@ type MedeoToolInput = {
415
576
  plan_id: string;
416
577
  validation?: 'version' | 'preflight';
417
578
  };
579
+ interface MedeoToolWarning {
580
+ kind: 'pull_failed';
581
+ message: string;
582
+ }
583
+ type EntityCommitResult = {
584
+ kind: 'committed';
585
+ ops_applied: number;
586
+ collaborated: false;
587
+ entity_revision: number;
588
+ } | {
589
+ kind: 'unconfirmed';
590
+ reason: 'push_failed';
591
+ ops_applied: number;
592
+ message: string;
593
+ } | {
594
+ kind: 'rejected';
595
+ reason: 'entity_revision_mismatch';
596
+ expected: number;
597
+ actual: number;
598
+ } | {
599
+ kind: 'rejected';
600
+ reason: 'entity_state_rejected';
601
+ status: number;
602
+ message: string;
603
+ };
604
+ type MedeoCommitResult = CommitPlanResult | EntityCommitResult;
418
605
  type MedeoToolResult = {
606
+ ok: true;
607
+ op: 'migrate-legacy';
608
+ doc_id: string;
609
+ migration_status: 'committed' | 'already_entity';
610
+ entity_revision: number;
611
+ next_action: 'snapshot';
612
+ } | {
419
613
  ok: true;
420
614
  op: 'snapshot';
421
615
  doc_id: string;
422
616
  version: string;
423
617
  preview: string;
618
+ collaborated?: boolean;
619
+ warnings?: MedeoToolWarning[];
424
620
  } | {
425
621
  ok: true;
426
622
  op: 'run-edit-script';
427
623
  doc_id: string;
428
624
  plan_id: string;
625
+ plan_kind: 'timeline' | 'entities';
429
626
  base_version: string;
627
+ entity_base_revision: number;
430
628
  ops_count: number;
431
629
  preview: string;
432
630
  logs: string[];
433
631
  duration_ms: number;
434
632
  committed?: boolean;
435
- commit_result?: CommitPlanResult;
633
+ commit_result?: MedeoCommitResult;
634
+ collaborated?: boolean;
635
+ warnings?: MedeoToolWarning[];
436
636
  } | {
437
637
  ok: false;
438
638
  op: 'run-edit-script';
@@ -453,8 +653,11 @@ type MedeoToolResult = {
453
653
  op: 'commit-plan';
454
654
  doc_id: string;
455
655
  plan_id: string;
656
+ plan_kind: 'timeline' | 'entities';
456
657
  committed: boolean;
457
- result: CommitPlanResult;
658
+ result: MedeoCommitResult;
659
+ collaborated?: boolean;
660
+ warnings?: MedeoToolWarning[];
458
661
  } | {
459
662
  ok: false;
460
663
  op: MedeoToolOp;
@@ -472,12 +675,12 @@ type MedeoInitialDraft = VideoDraft;
472
675
  /**
473
676
  * Create the self-contained Medeo LLM tool.
474
677
  *
475
- * The package owns session construction, compact projection, sandbox execution,
678
+ * The package owns document construction, compact projection, sandbox execution,
476
679
  * plan caching, commit, document get-or-create, and shutdown. The host supplies
477
680
  * environment facts plus the authoritative legacy draft loader used only when
478
681
  * Mengine has no document yet.
479
682
  */
480
683
  declare function createMedeoTool(options: CreateMedeoToolOptions): MedeoTool;
481
684
  //#endregion
482
- export { type ChangePlan, type CommitPlan, type CommitPlanOptions, type CommitPlanResult, type CompactProjectionOptions, type ConsoleShim, type CreateMedeoToolOptions, type EditFacade, EditSandboxSession, type EditSandboxSessionOptions, type EditScriptResult, MEDEO_TOOL_DESCRIPTION, MEDEO_TOOL_NAME, MEDEO_TOOL_PARAMETERS, type MedeoInitialDraft, type MedeoModelContext, type MedeoModelContextInput, type MedeoTool, type MedeoToolInput, type MedeoToolOp, type MedeoToolResult, type RunEditScriptOptions, type SandboxCheckpoint, type TimelineClipDescriptor, type TimelineFacade, type TimelinePartDescriptor, collectAffectedPartIds, commitPlan, createMedeoTool, renderCompactProjection, renderPreview, runEditScript };
685
+ export { type AuthorableRelationKind, type ChangePlan, type CommitPlan, type CommitPlanOptions, type CommitPlanResult, type CompactProjectionOptions, type ConsoleShim, type CreateEntityInput, type CreateMedeoToolOptions, type DeleteEntityInput, type EditFacade, EditSandboxSession, type EditSandboxSessionOptions, type EditScriptResult, type EntityCommand, type EntityCommitResult, type EntityFacade, type EntityPlanState, type EntityStoreSnapshot, type ImportAssetInput, type JsonObject, type JsonPrimitive, type JsonValue, type KnownEntityKind, type KnownRelationKind, type LinkGeneratedRelationInput, type LinkRelationInput, MEDEO_TOOL_DESCRIPTION, MEDEO_TOOL_NAME, MEDEO_TOOL_PARAMETERS, type MedeoCommitResult, type MedeoInitialDraft, type MedeoModelContext, type MedeoModelContextInput, type MedeoTool, type MedeoToolInput, type MedeoToolOp, type MedeoToolResult, type RelationFacade, type RunEditScriptOptions, type SandboxCheckpoint, type SandboxEntity, type SandboxRelation, type TimelineClipDescriptor, type TimelineFacade, type TimelinePartDescriptor, type UnlinkRelationInput, type UpdateEntityInput, collectAffectedPartIds, commitPlan, createMedeoTool, renderCompactProjection, renderPreview, runEditScript };
483
686
  //# sourceMappingURL=index.d.mts.map