@mengine/medeo-tool 1.3.1-alpha.8 → 1.4.1-alpha.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.
package/README.md CHANGED
@@ -16,7 +16,7 @@ A host supplies only environment facts: Mengine HTTP origin, optional request
16
16
  identity headers, `fetch`, and a stable agent peer id.
17
17
 
18
18
  ```ts
19
- import { createMedeoTool } from '@mengine/medeo-tool';
19
+ import { materializeResources, createMedeoTool } from '@mengine/medeo-tool';
20
20
 
21
21
  const medeo = createMedeoTool({
22
22
  httpOrigin: process.env.MENGINE_HTTP_ORIGIN!,
@@ -38,53 +38,39 @@ const commit = await medeo.handle({
38
38
  plan_id: run.plan_id,
39
39
  });
40
40
 
41
- // Media facts are recalled by the host and passed into the sandbox.
42
- // This example is text-to-image: there is no invented input-media entity.
41
+ // Only the host imports resource facts. Model inputs contain domain identities.
42
+ const [contentEntityId] = await materializeResources({ docId, httpOrigin }, [
43
+ { assetId: 'asset-from-host', kind: 'image' },
44
+ ]);
43
45
  const entityRun = await medeo.handle({
44
46
  op: 'run-edit-script',
45
47
  doc_id: docId,
46
- inputs: { output_asset_id: 'asset-from-host', track_entity_id: existingTrackEntityId },
47
- script: `
48
- if (typeof inputs.output_asset_id !== 'string' || typeof inputs.track_entity_id !== 'string') {
49
- throw new Error('missing recalled generation facts');
50
- }
51
- const { contentEntityId: output } = entities.ensureMedia({
52
- assetId: inputs.output_asset_id,
53
- kind: 'image',
54
- });
55
- edit.insertClip({
56
- trackEntityId: inputs.track_entity_id,
57
- contentEntityId: output,
58
- sourceRange: { start: 0, end: 1 },
59
- duration: { mode: 'fixed', value: 5000 },
60
- targetRange: { start: 0, end: 5000 },
61
- });
62
- `,
48
+ inputs: { content_entity_id: contentEntityId, track_entity_id: existingTrackEntityId },
49
+ script: `edit.insertClip({
50
+ trackEntityId: inputs.track_entity_id,
51
+ contentEntityId: inputs.content_entity_id,
52
+ sourceRange: { start: 0, end: 1 }, duration: { mode: 'fixed', value: 5000 },
53
+ targetRange: { start: 0, end: 5000 },
54
+ });`,
63
55
  });
64
56
 
65
57
  await medeo.close();
66
58
  ```
67
59
 
68
- The sandbox has no network, storage, clock, or generation access. Materialize
69
- or recall speech/media side effects in the host first and pass stable facts
70
- through `inputs`. There is no automatic Asset→Entity projection: the model
71
- selects when to bring a recalled asset into the editor through `entities.ensureMedia`.
72
- The resolver gets or creates one typed Asset by external `(system, key)` within
73
- the document. Image/Video/Audio/Voice are logical Asset variants: the typed row
74
- directly owns `external`, `storageKey` and its media fields, and its Asset ID is
75
- also its content Entity ID. Imports create no separate physical-only Asset
76
- row and no `physical-asset` relation. Raw typed resource creation also reuses
77
- an existing identity; prefer `ensureMedia` with the recalled media kind.
78
- `findByAssetId` includes Voice (`memota-speech`) variants. There is no separate
79
- `importAsset` API.
80
- Generation facts currently carry bare asset IDs. If a returned fact matches
81
- both media and speech namespaces, synchronization fails explicitly without
82
- writing ambiguous lineage edges.
83
- Conflicting facts or duplicate candidates fail explicitly; no automatic
84
- merge or deletion occurs. This is the MEngine editor profile, not a global DSL
85
- cardinality rule. Separate Asset+media graphs are invalid: every media variant
86
- must directly own its external identity, with no read fallback or migration.
87
- Inline caption Assets without external identity are not deduplicated.
60
+ The model has only business Entity/Relation operations. No Asset lookup,
61
+ read, create, update, delete, import, binding or locator API is exposed in the
62
+ sandbox or through another model tool. `ensureMedia`, `findByAssetId` and
63
+ Asset-based editor shortcuts are host-only. Generic entity writes reject
64
+ `external` and `storageKey`, and cannot access physical Asset rows or bindings.
65
+
66
+ `materializeResources` is a host API. It creates media entities from factual
67
+ resources, or Caption with composed AudioScript text, ASR annotation markers
68
+ and an optional physical-asset binding. It publishes a native Loro update
69
+ before returning domain Entity IDs. Text edits through Caption version its
70
+ AudioScript base and rewire composition; Caption's own ID stays unchanged.
71
+ Repeated materialization reuses the persisted resource binding. Generation
72
+ facts, when supplied, are resolved before the same commit so resource import
73
+ and ordered provenance are atomic.
88
74
 
89
75
  Before model context/snapshot/editing, the host ensures one Timeline and the four
90
76
  fixed Tracks (`video_clip`, `speech`, `caption`, `bgm`). Existing IDs, settings and
@@ -138,7 +138,10 @@ interface SandboxRelation {
138
138
  trace: JsonObject;
139
139
  }
140
140
  interface EntityStoreSnapshot {
141
+ /** Causal compiler baseline; required for publishing edits. */
142
+ loroSnapshot?: string;
141
143
  revision: number;
144
+ /** Current AudioScript version attached to the project; initialized projects always attach a script, possibly empty. */
142
145
  audioScriptEntityId: string | null;
143
146
  entities: SandboxEntity[];
144
147
  relations: SandboxRelation[];
@@ -206,9 +209,6 @@ interface UnlinkRelationInput {
206
209
  relation_id: string;
207
210
  }
208
211
  type EntityCommand = {
209
- kind: 'set-document-audio-script';
210
- audioScriptEntityId: string | null;
211
- } | {
212
212
  kind: 'create-entity';
213
213
  entity: SandboxEntity;
214
214
  } | {
@@ -273,4 +273,4 @@ interface RelationFacade {
273
273
  }
274
274
  //#endregion
275
275
  export { SandboxEntity as _, EntityFacade as a, UpdateEntityInput as b, JsonObject as c, KnownEntityKind as d, KnownRelationKind as f, ResourceEntityKind as g, RelationFacade as h, EntityCommand as i, JsonPrimitive as l, LinkRelationInput as m, CreateEntityInput as n, EntityPlanState as o, LinkGeneratedRelationInput as p, DeleteEntityInput as r, EntityStoreSnapshot as s, AuthorableRelationKind as t, JsonValue as u, SandboxRelation as v, UnlinkRelationInput as y };
276
- //# sourceMappingURL=entity-contract-Dm3AMEC9.d.mts.map
276
+ //# sourceMappingURL=entity-contract-DHasvrhq.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as SandboxEntity, a as EntityFacade, b as UpdateEntityInput, c as JsonObject, d as KnownEntityKind, f as KnownRelationKind, g as ResourceEntityKind, h as RelationFacade, i as EntityCommand, l as JsonPrimitive, m as LinkRelationInput, n as CreateEntityInput, o as EntityPlanState, p as LinkGeneratedRelationInput, r as DeleteEntityInput, s as EntityStoreSnapshot, t as AuthorableRelationKind, u as JsonValue, v as SandboxRelation, y as UnlinkRelationInput } from "./entity-contract-Dm3AMEC9.mjs";
1
+ import { _ as SandboxEntity, a as EntityFacade, b as UpdateEntityInput, c as JsonObject, d as KnownEntityKind, f as KnownRelationKind, g as ResourceEntityKind, h as RelationFacade, i as EntityCommand, l as JsonPrimitive, m as LinkRelationInput, n as CreateEntityInput, o as EntityPlanState, p as LinkGeneratedRelationInput, r as DeleteEntityInput, s as EntityStoreSnapshot, t as AuthorableRelationKind, u as JsonValue, v as SandboxRelation, y as UnlinkRelationInput } from "./entity-contract-DHasvrhq.mjs";
2
2
  import { JournalEntry, ManualSyncDoc, MediaAssetFact, PartIdFactory, SemanticOpName, VideoDocument, VideoDraft, fromVideoDocument } from "@mengine/medeo-client";
3
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";
4
4
 
@@ -49,6 +49,8 @@ interface SandboxCheckpoint {
49
49
  readonly index: number;
50
50
  }
51
51
  interface ChangePlan {
52
+ /** Native operations compiled against the causal sandbox baseline. */
53
+ loro_update?: string;
52
54
  readonly plan_kind: 'timeline' | 'entities';
53
55
  doc_id: string;
54
56
  base_version: string;
@@ -209,6 +211,29 @@ type EditScriptResult = {
209
211
  /** Run `script` against a forked document snapshot; always resolves (never rejects). */
210
212
  declare function runEditScript(options: RunEditScriptOptions): Promise<EditScriptResult>;
211
213
  //#endregion
214
+ //#region src/entity/entity-http-client.d.ts
215
+ interface EntityHttpClientOptions {
216
+ docId: string;
217
+ httpOrigin: string;
218
+ authToken?: string | (() => string | undefined);
219
+ userId?: string | (() => string | undefined);
220
+ fetchImpl?: typeof fetch;
221
+ }
222
+ //#endregion
223
+ //#region src/entity/caption-asset-assembly.d.ts
224
+ /** Optional physical artifact registered for one immutable Caption identity. */
225
+ interface CaptionAssetFact {
226
+ readonly captionEntityId: string;
227
+ readonly assetId: string;
228
+ readonly storageKey: string;
229
+ }
230
+ /** Host-only lookup. Missing facts mean the Caption has no physical artifact. */
231
+ type CaptionAssetsLoader = (docId: string, captionEntityIds: readonly string[]) => Promise<readonly CaptionAssetFact[]>;
232
+ interface CaptionAssetAssemblyOutcome {
233
+ readonly status: 'applied' | 'current' | 'failed';
234
+ readonly message?: string;
235
+ }
236
+ //#endregion
212
237
  //#region src/entity/generation-sync.d.ts
213
238
  /** Factual generation lineage for recalled Memota assets, supplied by the host. */
214
239
  interface AssetGenerationFact {
@@ -246,7 +271,7 @@ declare const MEDEO_TOOL_DESCRIPTION: string;
246
271
  //#endregion
247
272
  //#region src/schema.d.ts
248
273
  declare const MEDEO_TOOL_NAME = "medeo";
249
- type MedeoToolOp = 'snapshot' | 'migrate-legacy' | 'run-edit-script' | 'commit-plan';
274
+ type MedeoToolOp = 'snapshot' | 'run-edit-script' | 'commit-plan';
250
275
  /**
251
276
  * JSON Schema for the host-facing `medeo` tool surface.
252
277
  *
@@ -262,7 +287,7 @@ declare const MEDEO_TOOL_PARAMETERS: {
262
287
  readonly properties: {
263
288
  readonly op: {
264
289
  readonly type: "string";
265
- readonly enum: readonly ["snapshot", "migrate-legacy", "run-edit-script", "commit-plan"];
290
+ readonly enum: readonly ["snapshot", "run-edit-script", "commit-plan"];
266
291
  readonly description: "Which Medeo document operation to run.";
267
292
  };
268
293
  readonly doc_id: {
@@ -279,110 +304,6 @@ declare const MEDEO_TOOL_PARAMETERS: {
279
304
  readonly type: "object";
280
305
  readonly description: "Pre-materialized, side-effect-free values passed into the script, including recalled asset facts. Generation history is never an input: the host queries lineage itself and syncs generated Relations after each commit. Generation and network IO must happen in the host before this call.";
281
306
  };
282
- readonly asset_facts: {
283
- readonly type: "array";
284
- 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.";
285
- readonly items: {
286
- readonly oneOf: readonly [{
287
- readonly type: "object";
288
- readonly additionalProperties: false;
289
- readonly required: readonly ["assetId", "kind"];
290
- readonly properties: {
291
- readonly assetId: {
292
- readonly type: "string";
293
- readonly minLength: 1;
294
- };
295
- readonly kind: {
296
- readonly const: "image";
297
- };
298
- readonly storageKey: {
299
- readonly type: "string";
300
- readonly minLength: 1;
301
- };
302
- };
303
- }, {
304
- readonly type: "object";
305
- readonly additionalProperties: false;
306
- readonly required: readonly ["assetId", "kind", "durationMs"];
307
- readonly properties: {
308
- readonly assetId: {
309
- readonly type: "string";
310
- readonly minLength: 1;
311
- };
312
- readonly kind: {
313
- readonly const: "video";
314
- };
315
- readonly durationMs: {
316
- readonly type: "integer";
317
- readonly minimum: 1;
318
- };
319
- readonly storageKey: {
320
- readonly type: "string";
321
- readonly minLength: 1;
322
- };
323
- };
324
- }, {
325
- readonly type: "object";
326
- readonly additionalProperties: false;
327
- readonly required: readonly ["assetId", "kind", "durationMs", "storageKey"];
328
- readonly properties: {
329
- readonly assetId: {
330
- readonly type: "string";
331
- readonly minLength: 1;
332
- };
333
- readonly kind: {
334
- readonly const: "audio";
335
- };
336
- readonly durationMs: {
337
- readonly type: "integer";
338
- readonly minimum: 1;
339
- };
340
- readonly storageKey: {
341
- readonly type: "string";
342
- readonly minLength: 1;
343
- };
344
- };
345
- }, {
346
- readonly type: "object";
347
- readonly additionalProperties: false;
348
- readonly required: readonly ["assetId", "kind", "durationMs", "storageKey", "voice"];
349
- readonly properties: {
350
- readonly kind: {
351
- readonly const: "voice";
352
- };
353
- readonly assetId: {
354
- readonly type: "string";
355
- readonly minLength: 1;
356
- };
357
- readonly durationMs: {
358
- readonly type: "integer";
359
- readonly minimum: 1;
360
- };
361
- readonly storageKey: {
362
- readonly type: "string";
363
- readonly minLength: 1;
364
- };
365
- readonly voice: {
366
- readonly type: "object";
367
- readonly additionalProperties: false;
368
- readonly required: readonly ["system", "key"];
369
- readonly properties: {
370
- readonly system: {
371
- readonly const: "voice-library";
372
- };
373
- readonly key: {
374
- readonly type: "string";
375
- readonly minLength: 1;
376
- };
377
- readonly name: {
378
- readonly type: "string";
379
- };
380
- };
381
- };
382
- };
383
- }];
384
- };
385
- };
386
307
  readonly timeout_ms: {
387
308
  readonly type: "integer";
388
309
  readonly minimum: 1;
@@ -404,25 +325,11 @@ declare const MEDEO_TOOL_PARAMETERS: {
404
325
  };
405
326
  readonly validation: {
406
327
  readonly type: "string";
407
- readonly enum: readonly ["version"];
408
- readonly description: "Commit with Entity revision CAS; reject concurrent changes.";
328
+ readonly enum: readonly ["preflight"];
329
+ readonly description: "Publish the native update already validated on its causal Loro fork.";
409
330
  };
410
331
  };
411
332
  readonly oneOf: readonly [{
412
- readonly required: readonly ["op", "doc_id", "asset_facts"];
413
- readonly properties: {
414
- readonly op: {
415
- readonly const: "migrate-legacy";
416
- };
417
- readonly doc_id: {
418
- readonly $ref: "#/properties/doc_id";
419
- };
420
- readonly asset_facts: {
421
- readonly $ref: "#/properties/asset_facts";
422
- };
423
- };
424
- readonly additionalProperties: false;
425
- }, {
426
333
  readonly required: readonly ["op", "doc_id"];
427
334
  readonly properties: {
428
335
  readonly op: {
@@ -571,6 +478,8 @@ interface CreateMedeoToolOptions {
571
478
  * names entities, relations, or endpoints.
572
479
  */
573
480
  loadGenerationFacts?: GenerationFactsLoader;
481
+ /** Assemble optional Caption artifacts by immutable entity ID; never exposed to scripts. */
482
+ loadCaptionAssets?: CaptionAssetsLoader;
574
483
  fetchImpl?: typeof fetch;
575
484
  /** @deprecated ManualSyncDoc has no SSE or reconnect loop. */
576
485
  sseReconnectDelayMs?: number;
@@ -599,10 +508,6 @@ interface MedeoModelContext {
599
508
  type MedeoToolInput = {
600
509
  op: 'snapshot';
601
510
  doc_id: string;
602
- } | {
603
- op: 'migrate-legacy';
604
- doc_id: string;
605
- asset_facts: readonly MediaAssetFact[];
606
511
  } | {
607
512
  op: 'run-edit-script';
608
513
  doc_id: string;
@@ -615,9 +520,12 @@ type MedeoToolInput = {
615
520
  op: 'commit-plan';
616
521
  doc_id: string;
617
522
  plan_id: string;
618
- validation?: 'version' | 'preflight';
523
+ validation?: 'preflight';
619
524
  };
620
525
  type MedeoToolWarning = {
526
+ kind: 'asset_assembly_failed';
527
+ message: string;
528
+ } | {
621
529
  kind: 'pull_failed';
622
530
  message: string;
623
531
  } | {
@@ -625,22 +533,23 @@ type MedeoToolWarning = {
625
533
  message: string;
626
534
  };
627
535
  type EntityCommitResult = {
536
+ kind: 'conflicted';
537
+ accepted: true;
538
+ entity_revision: number;
539
+ message: string;
540
+ } | {
628
541
  kind: 'committed';
629
542
  ops_applied: number;
630
- collaborated: false;
543
+ collaborated: boolean;
631
544
  entity_revision: number; /** Present only when the host supplies loadGenerationFacts. */
632
545
  generation_sync?: GenerationSyncOutcome;
546
+ asset_assembly?: CaptionAssetAssemblyOutcome;
633
547
  warnings?: MedeoToolWarning[];
634
548
  } | {
635
549
  kind: 'unconfirmed';
636
550
  reason: 'push_failed';
637
551
  ops_applied: number;
638
552
  message: string;
639
- } | {
640
- kind: 'rejected';
641
- reason: 'entity_revision_mismatch';
642
- expected: number;
643
- actual: number;
644
553
  } | {
645
554
  kind: 'rejected';
646
555
  reason: 'entity_state_rejected';
@@ -649,13 +558,6 @@ type EntityCommitResult = {
649
558
  };
650
559
  type MedeoCommitResult = CommitPlanResult | EntityCommitResult;
651
560
  type MedeoToolResult = {
652
- ok: true;
653
- op: 'migrate-legacy';
654
- doc_id: string;
655
- migration_status: 'committed' | 'already_entity';
656
- entity_revision: number;
657
- next_action: 'snapshot';
658
- } | {
659
561
  ok: true;
660
562
  op: 'snapshot';
661
563
  doc_id: string;
@@ -728,5 +630,27 @@ type MedeoInitialDraft = VideoDraft;
728
630
  */
729
631
  declare function createMedeoTool(options: CreateMedeoToolOptions): MedeoTool;
730
632
  //#endregion
731
- export { type AssetGenerationFact, 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 GenerationFactsLoader, type GenerationSyncOutcome, 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 ResourceEntityKind, type RunEditScriptOptions, type SandboxCheckpoint, type SandboxEntity, type SandboxRelation, type TimelineClipDescriptor, type TimelineFacade, type TimelinePartDescriptor, type UnlinkRelationInput, type UpdateEntityInput, collectAffectedPartIds, commitPlan, createMedeoTool, renderCompactProjection, renderPreview, runEditScript };
633
+ //#region src/entity/materialize-resources.d.ts
634
+ /** Host facts only. This contract is never included in the model's sandbox API. */
635
+ type GeneratedResource = MediaAssetFact | {
636
+ kind: 'caption';
637
+ assetId: string;
638
+ storageKey: string;
639
+ segments: readonly {
640
+ text: string;
641
+ startMs: number;
642
+ endMs: number; /** ASR word timing is available as an annotation for model segmentation. */
643
+ words?: readonly {
644
+ text: string;
645
+ startMs: number;
646
+ endMs: number;
647
+ }[];
648
+ }[];
649
+ };
650
+ /** Persist resources before model consumption. The host serializes repeated imports of the same generation task. */
651
+ declare function materializeResources(options: EntityHttpClientOptions & {
652
+ loadGenerationFacts?: GenerationFactsLoader;
653
+ }, resources: readonly GeneratedResource[]): Promise<readonly string[]>;
654
+ //#endregion
655
+ export { type AssetGenerationFact, type AuthorableRelationKind, type CaptionAssetAssemblyOutcome, type CaptionAssetFact, type CaptionAssetsLoader, 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 GeneratedResource, type GenerationFactsLoader, type GenerationSyncOutcome, 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 ResourceEntityKind, type RunEditScriptOptions, type SandboxCheckpoint, type SandboxEntity, type SandboxRelation, type TimelineClipDescriptor, type TimelineFacade, type TimelinePartDescriptor, type UnlinkRelationInput, type UpdateEntityInput, collectAffectedPartIds, commitPlan, createMedeoTool, materializeResources, renderCompactProjection, renderPreview, runEditScript };
732
656
  //# sourceMappingURL=index.d.mts.map