@mengine/medeo-tool 1.4.1-alpha.2 → 1.4.1-alpha.3
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 +67 -141
- package/dist/{entity-contract-Cpf3P69H.d.mts → entity-contract-DQ56Ihrh.d.mts} +36 -76
- package/dist/{script-session-lXpqmupK.mjs → entity-sandbox-BH-7F5C8.mjs} +126 -503
- package/dist/entity-sandbox-BH-7F5C8.mjs.map +1 -0
- package/dist/index.d.mts +3 -99
- package/dist/index.mjs +233 -343
- package/dist/index.mjs.map +1 -1
- package/dist/sandbox-api.d.mts +59 -293
- package/dist/worker-entry.d.mts +1 -2
- package/dist/worker-entry.mjs +70 -209
- package/dist/worker-entry.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/script-session-lXpqmupK.mjs.map +0 -1
package/dist/worker-entry.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { n as toDslRows, r as businessFacades, t as EntitySandbox } from "./entity-sandbox-BH-7F5C8.mjs";
|
|
2
|
+
import { LoroEntityDocument, assertCanonicalEditorResources, assertMediaAssetWritePolicy, base64ToBytes, bytesToBase64, projectEntityTimeline } from "@mengine/medeo-client";
|
|
3
3
|
import { parentPort, workerData } from "node:worker_threads";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import vm from "node:vm";
|
|
@@ -24,18 +24,10 @@ const LOG_LINE_CAP = 1e3;
|
|
|
24
24
|
const LOG_BYTE_CAP = 64 * 1024;
|
|
25
25
|
const TRUNCATE_MARK = "[truncated]";
|
|
26
26
|
const LOG_TRUNCATED = "[log truncated]";
|
|
27
|
-
/**
|
|
28
|
-
* Entity-only sandbox session used by the production model path.
|
|
29
|
-
*
|
|
30
|
-
* Native timeline operations execute against a detached graph editor and are
|
|
31
|
-
* then journaled as ordinary EntitySandbox commands. VideoDocument is retained
|
|
32
|
-
* only for the request's document identity; it is never edited or projected
|
|
33
|
-
* back into the graph.
|
|
34
|
-
*/
|
|
27
|
+
/** Entity/relation script session; compilation retains the ordered operation journal. */
|
|
35
28
|
var EntityEditSandboxSession = class {
|
|
36
29
|
document;
|
|
37
30
|
entitySandbox;
|
|
38
|
-
entityRevision;
|
|
39
31
|
baseRows;
|
|
40
32
|
domainIdFactory;
|
|
41
33
|
logs = [];
|
|
@@ -43,8 +35,6 @@ var EntityEditSandboxSession = class {
|
|
|
43
35
|
logBytes = 0;
|
|
44
36
|
resolvedCaptionAssets = /* @__PURE__ */ new Set();
|
|
45
37
|
logCapped = false;
|
|
46
|
-
edit;
|
|
47
|
-
timeline;
|
|
48
38
|
entities;
|
|
49
39
|
relations;
|
|
50
40
|
console;
|
|
@@ -52,7 +42,6 @@ var EntityEditSandboxSession = class {
|
|
|
52
42
|
rollbackTo;
|
|
53
43
|
constructor(document, options) {
|
|
54
44
|
this.document = structuredClone(document);
|
|
55
|
-
this.entityRevision = options?.entityState?.revision ?? 0;
|
|
56
45
|
this.baseRows = toDslRows(options?.entityState ?? {
|
|
57
46
|
revision: 0,
|
|
58
47
|
audioScriptEntityId: null,
|
|
@@ -69,14 +58,26 @@ var EntityEditSandboxSession = class {
|
|
|
69
58
|
onCommand: options?.onEntityCommand,
|
|
70
59
|
onTruncate: options?.onEntityTruncate
|
|
71
60
|
});
|
|
72
|
-
this.edit = this.buildEditFacade();
|
|
73
|
-
this.timeline = { snapshot: () => this.snapshot() };
|
|
74
61
|
const business = businessFacades(this.entitySandbox.entities, this.entitySandbox.relations);
|
|
75
62
|
this.entities = business.entities;
|
|
76
63
|
this.relations = business.relations;
|
|
77
64
|
this.console = this.buildConsoleShim();
|
|
78
|
-
|
|
79
|
-
this.
|
|
65
|
+
const checkpoints = /* @__PURE__ */ new Map();
|
|
66
|
+
this.checkpoint = () => {
|
|
67
|
+
const token = Object.freeze({});
|
|
68
|
+
checkpoints.set(token, this.entitySandbox.commandCount);
|
|
69
|
+
return token;
|
|
70
|
+
};
|
|
71
|
+
this.rollbackTo = (cp) => {
|
|
72
|
+
const index = checkpoints.get(cp);
|
|
73
|
+
if (index === void 0) throw new Error("Invalid or expired sandbox checkpoint");
|
|
74
|
+
this.entitySandbox.rollbackTo(index);
|
|
75
|
+
let later = false;
|
|
76
|
+
for (const token of checkpoints.keys()) {
|
|
77
|
+
if (later) checkpoints.delete(token);
|
|
78
|
+
if (token === cp) later = true;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
80
81
|
}
|
|
81
82
|
/** Resolve only the resource attached to this Entity; I/O remains in the parent host. */
|
|
82
83
|
async rgetAssetFromEntity(entityId, load) {
|
|
@@ -163,7 +164,7 @@ var EntityEditSandboxSession = class {
|
|
|
163
164
|
assertMediaAssetWritePolicy(this.baseRows, toDslRows(entityPlan.rows));
|
|
164
165
|
if (entityPlan.rows.loroSnapshot) projectEntityTimeline(toDslRows(entityPlan.rows), this.document.meta);
|
|
165
166
|
return {
|
|
166
|
-
...entityPlan.rows.loroSnapshot ? { loro_update: bytesToBase64(
|
|
167
|
+
...entityPlan.rows.loroSnapshot ? { loro_update: bytesToBase64(this.compileJournal(entityPlan)) } : {},
|
|
167
168
|
plan_kind: "entities",
|
|
168
169
|
doc_id: this.document.meta.draft_id ?? "",
|
|
169
170
|
base_version: baseVersion,
|
|
@@ -177,59 +178,55 @@ var EntityEditSandboxSession = class {
|
|
|
177
178
|
logs: this.logs.slice()
|
|
178
179
|
};
|
|
179
180
|
}
|
|
181
|
+
compileJournal(plan) {
|
|
182
|
+
return LoroEntityDocument.fromSnapshot(base64ToBytes(plan.rows.loroSnapshot), (state) => {
|
|
183
|
+
assertCanonicalEditorResources(state.rows);
|
|
184
|
+
projectEntityTimeline(state.rows, this.document.meta);
|
|
185
|
+
}).transact((draft) => {
|
|
186
|
+
for (const command of plan.commands) switch (command.kind) {
|
|
187
|
+
case "create-entity": {
|
|
188
|
+
const rows = toDslRows({
|
|
189
|
+
revision: 0,
|
|
190
|
+
audioScriptEntityId: null,
|
|
191
|
+
entities: [command.entity],
|
|
192
|
+
relations: []
|
|
193
|
+
});
|
|
194
|
+
draft.create(rows.entities[0]);
|
|
195
|
+
if (command.entity.entity_kind === "audio-script") draft.attach("audioScriptEntityId", command.entity.entity_id);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case "update-entity":
|
|
199
|
+
draft.replaceOwned(command.entity_id, command.payload);
|
|
200
|
+
break;
|
|
201
|
+
case "change-entity":
|
|
202
|
+
draft.change(command.entity_id, command.changes);
|
|
203
|
+
break;
|
|
204
|
+
case "delete-entity":
|
|
205
|
+
draft.delete(command.entity_id);
|
|
206
|
+
break;
|
|
207
|
+
case "link-relation": {
|
|
208
|
+
const rows = toDslRows({
|
|
209
|
+
revision: 0,
|
|
210
|
+
audioScriptEntityId: null,
|
|
211
|
+
entities: [],
|
|
212
|
+
relations: [command.relation]
|
|
213
|
+
});
|
|
214
|
+
draft.link(rows.relations[0]);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "change-relation":
|
|
218
|
+
draft.changeRelation(command.relation_id, command.changes);
|
|
219
|
+
break;
|
|
220
|
+
case "unlink-relation":
|
|
221
|
+
draft.unlink(command.relation_id);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
draft.reconcileOrder(toDslRows(plan.rows));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
180
227
|
getLogs() {
|
|
181
228
|
return this.logs;
|
|
182
229
|
}
|
|
183
|
-
buildEditFacade() {
|
|
184
|
-
return {
|
|
185
|
-
insertClip: (input) => this.runNativeEdit((editor) => editor.insertClip(input)),
|
|
186
|
-
insertPlacedClip: (input) => this.runNativeEdit((editor) => editor.insertPlacedClip(input)),
|
|
187
|
-
updateClipMarker: (input) => this.runNativeEdit((editor) => editor.updateClipMarker(input)),
|
|
188
|
-
setClipPlacement: (input) => this.runNativeEdit((editor) => editor.setClipPlacement(input)),
|
|
189
|
-
moveSequentialClips: (input) => this.runNativeEdit((editor) => editor.moveSequentialClips(input)),
|
|
190
|
-
moveClip: (input) => this.runNativeEdit((editor) => editor.moveClip(input)),
|
|
191
|
-
replaceClipContent: (input) => this.runNativeEdit((editor) => editor.replaceClipContent(input)),
|
|
192
|
-
setClipVolume: (input) => this.runNativeEdit((editor) => editor.setClipVolume(input)),
|
|
193
|
-
setClipSpeed: (input) => this.runNativeEdit((editor) => editor.setClipSpeed(input)),
|
|
194
|
-
trimClip: (input) => this.runNativeEdit((editor) => editor.trimClip(input)),
|
|
195
|
-
deleteClip: (input) => this.runNativeEdit((editor) => editor.deleteClip(input)),
|
|
196
|
-
deleteClipTree: (input) => this.runNativeEdit((editor) => editor.deleteClipTree(input)),
|
|
197
|
-
updateClip: (input) => this.runNativeEdit((editor) => editor.updateClip(input)),
|
|
198
|
-
moveVoiceover: (input) => this.runNativeEdit((editor) => editor.moveVoiceover(input)),
|
|
199
|
-
moveClipsToStarts: (input) => this.runNativeEdit((editor) => editor.moveClipsToStarts(input)),
|
|
200
|
-
deleteVoiceover: (input) => this.runNativeEdit((editor) => editor.deleteVoiceover(input)),
|
|
201
|
-
deleteBgm: (input) => this.runNativeEdit((editor) => editor.deleteBgm(input)),
|
|
202
|
-
setCaptionVisibility: (input) => this.runNativeEdit((editor) => editor.setCaptionVisibility(input)),
|
|
203
|
-
patchCaptionStyle: (input) => this.runNativeEdit((editor) => editor.patchCaptionStyle(input)),
|
|
204
|
-
insertCaptionClip: (input) => this.runNativeEdit((editor) => editor.insertCaptionClip(input))
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
runNativeEdit(mutate) {
|
|
208
|
-
const checkpoint = this.entitySandbox.commandCount;
|
|
209
|
-
try {
|
|
210
|
-
const before = this.entitySandbox.buildPlan().rows;
|
|
211
|
-
const editor = new EntityTimelineEditor(toDslRows(before), this.domainIdFactory);
|
|
212
|
-
const result = mutate(editor);
|
|
213
|
-
const expected = fromDslRows(editor.rows(), before.revision, before.audioScriptEntityId);
|
|
214
|
-
applyGraphDiff(this.entitySandbox, before, expected);
|
|
215
|
-
const applied = this.entitySandbox.buildPlan().rows;
|
|
216
|
-
if (!graphRowsEqual(applied, expected)) throw new Error("Entity timeline command diff did not reproduce the editor result");
|
|
217
|
-
return result;
|
|
218
|
-
} catch (error) {
|
|
219
|
-
this.entitySandbox.rollbackTo(checkpoint);
|
|
220
|
-
throw error;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
snapshot() {
|
|
224
|
-
const audioScriptEntityId = this.entitySandbox.audioScriptEntityId;
|
|
225
|
-
if (audioScriptEntityId === null) throw new Error("Document AudioScript is not initialized");
|
|
226
|
-
return {
|
|
227
|
-
revision: this.entityRevision,
|
|
228
|
-
audioScriptEntityId,
|
|
229
|
-
entities: this.entities.list(),
|
|
230
|
-
relations: this.relations.list()
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
230
|
appendLog(line) {
|
|
234
231
|
if (this.logCapped) return;
|
|
235
232
|
if (this.logs.length >= LOG_LINE_CAP || this.logBytes >= LOG_BYTE_CAP) {
|
|
@@ -253,141 +250,6 @@ var EntityEditSandboxSession = class {
|
|
|
253
250
|
};
|
|
254
251
|
}
|
|
255
252
|
};
|
|
256
|
-
function applyGraphDiff(sandbox, before, after) {
|
|
257
|
-
const beforeEntities = new Map(before.entities.map((entity) => [entity.entity_id, entity]));
|
|
258
|
-
const afterEntities = new Map(after.entities.map((entity) => [entity.entity_id, entity]));
|
|
259
|
-
const beforeRelations = new Map(before.relations.map((relation) => [relation.relation_id, relation]));
|
|
260
|
-
const afterRelations = new Map(after.relations.map((relation) => [relation.relation_id, relation]));
|
|
261
|
-
for (const [entityId, previous] of beforeEntities) {
|
|
262
|
-
const next = afterEntities.get(entityId);
|
|
263
|
-
if (next != null && next.entity_kind !== previous.entity_kind) throw new Error(`Entity id "${entityId}" cannot change kind from "${previous.entity_kind}" to "${next.entity_kind}"`);
|
|
264
|
-
}
|
|
265
|
-
for (const [relationId, previous] of beforeRelations) {
|
|
266
|
-
const next = afterRelations.get(relationId);
|
|
267
|
-
if (next != null && (next.relation_kind !== previous.relation_kind || next.endpoint_0_entity_id !== previous.endpoint_0_entity_id || next.endpoint_1_entity_id !== previous.endpoint_1_entity_id)) throw new Error(`Relation id "${relationId}" cannot change kind or persisted endpoint positions`);
|
|
268
|
-
}
|
|
269
|
-
const relationIdsToReplace = new Set([...beforeRelations].filter(([relationId, previous]) => {
|
|
270
|
-
const next = afterRelations.get(relationId);
|
|
271
|
-
return next != null && (!jsonEqual(previous.metadata, next.metadata) || !jsonEqual(previous.trace, next.trace));
|
|
272
|
-
}).map(([relationId]) => relationId));
|
|
273
|
-
const relationIdsToUnlink = [...beforeRelations.keys()].filter((relationId) => !afterRelations.has(relationId) || relationIdsToReplace.has(relationId)).sort();
|
|
274
|
-
for (const relationId of relationIdsToUnlink) sandbox.relations.unlink({ relation_id: relationId });
|
|
275
|
-
const entityIdsToDelete = [...beforeEntities.keys()].filter((entityId) => !afterEntities.has(entityId)).sort();
|
|
276
|
-
for (const entityId of entityIdsToDelete) sandbox.entities.delete({ entity_id: entityId });
|
|
277
|
-
const entitiesToCreate = [...afterEntities.values()].filter((entity) => !beforeEntities.has(entity.entity_id)).sort((left, right) => left.entity_id.localeCompare(right.entity_id));
|
|
278
|
-
for (const entity of entitiesToCreate) sandbox.entities.create(entity);
|
|
279
|
-
const entitiesToUpdate = [...afterEntities.values()].filter((entity) => {
|
|
280
|
-
const previous = beforeEntities.get(entity.entity_id);
|
|
281
|
-
return previous != null && !jsonEqual(previous.payload, entity.payload);
|
|
282
|
-
}).sort((left, right) => left.entity_id.localeCompare(right.entity_id));
|
|
283
|
-
for (const entity of entitiesToUpdate) sandbox.replaceOwnedPayload({
|
|
284
|
-
entity_id: entity.entity_id,
|
|
285
|
-
payload: entity.payload
|
|
286
|
-
});
|
|
287
|
-
const relationsToLink = [...afterRelations.values()].filter((relation) => !beforeRelations.has(relation.relation_id) || relationIdsToReplace.has(relation.relation_id)).sort((left, right) => left.relation_id.localeCompare(right.relation_id));
|
|
288
|
-
for (const relation of relationsToLink) linkRelation(sandbox, relation);
|
|
289
|
-
}
|
|
290
|
-
function linkRelation(sandbox, relation) {
|
|
291
|
-
if (relation.relation_kind === "generated") {
|
|
292
|
-
sandbox.relations.linkGenerated({
|
|
293
|
-
relation_id: relation.relation_id,
|
|
294
|
-
output_entity_id: relation.endpoint_0_entity_id,
|
|
295
|
-
input_entity_id: relation.endpoint_1_entity_id,
|
|
296
|
-
trace: relation.trace
|
|
297
|
-
});
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
if (relation.relation_kind === "clip-anchor") {
|
|
301
|
-
sandbox.relations.linkClipAnchor({
|
|
302
|
-
relation_id: relation.relation_id,
|
|
303
|
-
child_clip_entity_id: relation.endpoint_0_entity_id,
|
|
304
|
-
host_clip_entity_id: relation.endpoint_1_entity_id,
|
|
305
|
-
trace: relation.trace
|
|
306
|
-
});
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
if (relation.relation_kind === "phonetic-script-render") {
|
|
310
|
-
const firstIsVoice = sandbox.entities.get(relation.endpoint_0_entity_id)?.entity_kind === "voice";
|
|
311
|
-
sandbox.relations.linkPhoneticScriptRender({
|
|
312
|
-
relation_id: relation.relation_id,
|
|
313
|
-
output_entity_id: firstIsVoice ? relation.endpoint_0_entity_id : relation.endpoint_1_entity_id,
|
|
314
|
-
phonetic_script_entity_id: firstIsVoice ? relation.endpoint_1_entity_id : relation.endpoint_0_entity_id,
|
|
315
|
-
trace: relation.trace
|
|
316
|
-
});
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
if (relation.relation_kind === "audio-script-source") {
|
|
320
|
-
const firstIsScript = sandbox.entities.get(relation.endpoint_0_entity_id)?.entity_kind === "audio-script";
|
|
321
|
-
sandbox.relations.linkAudioScriptSource({
|
|
322
|
-
relation_id: relation.relation_id,
|
|
323
|
-
script_entity_id: firstIsScript ? relation.endpoint_0_entity_id : relation.endpoint_1_entity_id,
|
|
324
|
-
source_entity_id: firstIsScript ? relation.endpoint_1_entity_id : relation.endpoint_0_entity_id,
|
|
325
|
-
trace: relation.trace
|
|
326
|
-
});
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
sandbox.relations.link({
|
|
330
|
-
relation_id: relation.relation_id,
|
|
331
|
-
relation_kind: relation.relation_kind,
|
|
332
|
-
endpoint_0_entity_id: relation.endpoint_0_entity_id,
|
|
333
|
-
endpoint_1_entity_id: relation.endpoint_1_entity_id,
|
|
334
|
-
metadata: relation.metadata,
|
|
335
|
-
trace: relation.trace
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
function toDslRows(snapshot) {
|
|
339
|
-
return {
|
|
340
|
-
entities: snapshot.entities.map((entity) => ({
|
|
341
|
-
entityId: createEntityId(entity.entity_id),
|
|
342
|
-
entityKind: entity.entity_kind,
|
|
343
|
-
payload: structuredClone(entity.payload)
|
|
344
|
-
})),
|
|
345
|
-
relations: snapshot.relations.map((relation) => ({
|
|
346
|
-
relationId: createRelationId(relation.relation_id),
|
|
347
|
-
relationKind: relation.relation_kind,
|
|
348
|
-
endpoint0EntityId: createEntityId(relation.endpoint_0_entity_id),
|
|
349
|
-
endpoint1EntityId: createEntityId(relation.endpoint_1_entity_id),
|
|
350
|
-
metadata: structuredClone(relation.metadata),
|
|
351
|
-
trace: structuredClone(relation.trace)
|
|
352
|
-
}))
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function fromDslRows(rows, revision, audioScriptEntityId) {
|
|
356
|
-
return {
|
|
357
|
-
revision,
|
|
358
|
-
audioScriptEntityId,
|
|
359
|
-
entities: rows.entities.map((entity) => ({
|
|
360
|
-
entity_id: entity.entityId,
|
|
361
|
-
entity_kind: entity.entityKind,
|
|
362
|
-
payload: structuredClone(entity.payload)
|
|
363
|
-
})),
|
|
364
|
-
relations: rows.relations.map((relation) => ({
|
|
365
|
-
relation_id: relation.relationId,
|
|
366
|
-
relation_kind: relation.relationKind,
|
|
367
|
-
endpoint_0_entity_id: relation.endpoint0EntityId,
|
|
368
|
-
endpoint_1_entity_id: relation.endpoint1EntityId,
|
|
369
|
-
metadata: structuredClone(relation.metadata),
|
|
370
|
-
trace: structuredClone(relation.trace)
|
|
371
|
-
}))
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function jsonEqual(left, right) {
|
|
375
|
-
if (Object.is(left, right)) return true;
|
|
376
|
-
if (Array.isArray(left) || Array.isArray(right)) return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => jsonEqual(value, right[index]));
|
|
377
|
-
if (!isRecord(left) || !isRecord(right)) return false;
|
|
378
|
-
const leftKeys = Object.keys(left).sort();
|
|
379
|
-
const rightKeys = Object.keys(right).sort();
|
|
380
|
-
return leftKeys.length === rightKeys.length && leftKeys.every((key, index) => key === rightKeys[index] && jsonEqual(left[key], right[key]));
|
|
381
|
-
}
|
|
382
|
-
function graphRowsEqual(left, right) {
|
|
383
|
-
if (left.revision !== right.revision || left.audioScriptEntityId !== right.audioScriptEntityId || left.entities.length !== right.entities.length || left.relations.length !== right.relations.length) return false;
|
|
384
|
-
const rightEntities = new Map(right.entities.map((entity) => [entity.entity_id, entity]));
|
|
385
|
-
const rightRelations = new Map(right.relations.map((relation) => [relation.relation_id, relation]));
|
|
386
|
-
return left.entities.every((entity) => jsonEqual(entity, rightEntities.get(entity.entity_id))) && left.relations.every((relation) => jsonEqual(relation, rightRelations.get(relation.relation_id)));
|
|
387
|
-
}
|
|
388
|
-
function isRecord(value) {
|
|
389
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
390
|
-
}
|
|
391
253
|
function formatLogArg(value) {
|
|
392
254
|
if (typeof value === "string") return value;
|
|
393
255
|
if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) return String(value);
|
|
@@ -490,8 +352,8 @@ async function main() {
|
|
|
490
352
|
index
|
|
491
353
|
})
|
|
492
354
|
};
|
|
493
|
-
const session =
|
|
494
|
-
const wrapped = `(async (
|
|
355
|
+
const session = new EntityEditSandboxSession(data.document, options);
|
|
356
|
+
const wrapped = `(async (entities, relations, checkpoint, rollbackTo, inputs, console, rgetAssetFromEntity) => {${data.script}\n})`;
|
|
495
357
|
const ctx = vm.createContext(Object.create(null));
|
|
496
358
|
let run;
|
|
497
359
|
try {
|
|
@@ -515,11 +377,10 @@ async function main() {
|
|
|
515
377
|
try {
|
|
516
378
|
const invoke = run;
|
|
517
379
|
post({ t: "ready" });
|
|
518
|
-
await invoke(session.
|
|
519
|
-
if (!(session instanceof EntityEditSandboxSession)) throw new Error("Entity-only sandbox required");
|
|
380
|
+
await invoke(session.entities, session.relations, session.checkpoint, session.rollbackTo, data.inputs ?? {}, session.console, (entityId) => {
|
|
520
381
|
return session.rgetAssetFromEntity(entityId, loadEntityAsset);
|
|
521
382
|
});
|
|
522
|
-
|
|
383
|
+
await session.prepareEntityAssets(loadEntityAsset);
|
|
523
384
|
} catch (error) {
|
|
524
385
|
post({
|
|
525
386
|
t: "fail",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-entry.mjs","names":[],"sources":["../src/entity/entity-asset.ts","../src/sandbox/entity-script-session.ts","../src/sandbox/worker-entry.ts"],"sourcesContent":["import type { JsonValue, SandboxEntity } from './entity-contract.ts';\n\n/** Immutable resource content resolved by the host for a document Entity. */\nexport interface EntityAssetContent {\n assetId: string;\n content: JsonValue;\n}\n\n/** Host-only I/O. The sandbox supplies an Entity, never an arbitrary Asset query. */\nexport type EntityAssetLoader = (docId: string, entity: SandboxEntity) => Promise<EntityAssetContent>;\n\nexport interface CaptionAssetSegment {\n text: string;\n start_time_ms: number;\n end_time_ms: number;\n}\n\n/** MCAP's output_caption JSON contract; unknown formats never become invented captions. */\nexport function captionAssetSegments(content: JsonValue): CaptionAssetSegment[] {\n if (!content || typeof content !== 'object' || Array.isArray(content) || !Array.isArray(content.segments))\n throw new Error('Caption Asset must contain an output_caption object with segments');\n if (!content.segments.length) throw new Error('Caption Asset contains no speech segments');\n return content.segments.map((value) => {\n if (\n !value ||\n typeof value !== 'object' ||\n Array.isArray(value) ||\n typeof value.text !== 'string' ||\n !value.text.trim() ||\n !Number.isSafeInteger(value.start_time_ms) ||\n !Number.isSafeInteger(value.end_time_ms) ||\n (value.start_time_ms as number) < 0 ||\n (value.end_time_ms as number) <= (value.start_time_ms as number)\n )\n throw new Error('Caption Asset has invalid text or millisecond timing');\n return { text: value.text, start_time_ms: value.start_time_ms as number, end_time_ms: value.end_time_ms as number };\n });\n}\n","import {\n EntityTimelineEditor,\n compileEntityRows,\n projectEntityTimeline,\n base64ToBytes,\n bytesToBase64,\n assertCanonicalEditorResources,\n assertMediaAssetWritePolicy,\n type ClipEntityId,\n type DeleteBgmInput,\n type DeleteClipInput,\n type DeleteClipTreeInput,\n type DeleteVoiceoverInput,\n type InsertCaptionClipInput,\n type InsertClipInput,\n type InsertPlacedClipInput,\n type MoveClipInput,\n type MoveClipsToStartsInput,\n type MoveSequentialClipsInput,\n type MoveVoiceoverInput,\n type PatchCaptionStyleInput,\n type ReplaceClipContentInput,\n type SetCaptionVisibilityInput,\n type SetClipPlacementInput,\n type SetClipSpeedInput,\n type SetClipVolumeInput,\n type TrimClipInput,\n type UpdateClipInput,\n type UpdateClipMarkerInput,\n type VideoDocument,\n} from '@mengine/medeo-client';\nimport {\n createEntityId,\n createRelationId,\n type EntityRelationRows,\n type EntityRow,\n type RelationRow,\n} from '@mengine/medeo-dsl';\n\nimport { captionAssetSegments, type EntityAssetContent } from '../entity/entity-asset.ts';\nimport type {\n CreateEntityInput,\n BusinessEntityFacade,\n EntityStoreSnapshot,\n LinkRelationInput,\n BusinessRelationFacade,\n SandboxEntity,\n SandboxRelation,\n} from '../entity/entity-contract.ts';\nimport { EntitySandbox, type DomainIdFactory } from '../entity/entity-sandbox.ts';\nimport { businessFacades } from './business-facades.ts';\nimport type { ChangePlan, ConsoleShim, EditSandboxSessionOptions, SandboxCheckpoint } from './script-session.ts';\n\nconst LOG_LINE_MAX = 2000;\nconst LOG_LINE_CAP = 1000;\nconst LOG_BYTE_CAP = 64 * 1024;\nconst TRUNCATE_MARK = '[truncated]';\nconst LOG_TRUNCATED = '[log truncated]';\n\n/** Model-facing timeline mutations whose source of truth is the Medeo Entity graph. */\nexport interface EntityEditFacade {\n insertClip(input: InsertClipInput): ClipEntityId;\n insertPlacedClip(input: InsertPlacedClipInput): ClipEntityId;\n updateClipMarker(input: UpdateClipMarkerInput): void;\n setClipPlacement(input: SetClipPlacementInput): void;\n moveSequentialClips(input: MoveSequentialClipsInput): void;\n moveClip(input: MoveClipInput): void;\n replaceClipContent(input: ReplaceClipContentInput): void;\n setClipVolume(input: SetClipVolumeInput): void;\n setClipSpeed(input: SetClipSpeedInput): void;\n trimClip(input: TrimClipInput): void;\n deleteClip(input: DeleteClipInput): void;\n deleteClipTree(input: DeleteClipTreeInput): void;\n updateClip(input: UpdateClipInput): void;\n moveVoiceover(input: MoveVoiceoverInput): void;\n moveClipsToStarts(input: MoveClipsToStartsInput): void;\n deleteVoiceover(input: DeleteVoiceoverInput): void;\n deleteBgm(input: DeleteBgmInput): void;\n setCaptionVisibility(input: SetCaptionVisibilityInput): void;\n patchCaptionStyle(input: PatchCaptionStyleInput): void;\n insertCaptionClip(input: InsertCaptionClipInput): ClipEntityId;\n}\n\nexport interface EntityTimelineFacade {\n /** Return the current graph draft, including uncommitted commands. */\n snapshot(): EntityStoreSnapshot & { audioScriptEntityId: string };\n}\n\n/**\n * Entity-only sandbox session used by the production model path.\n *\n * Native timeline operations execute against a detached graph editor and are\n * then journaled as ordinary EntitySandbox commands. VideoDocument is retained\n * only for the request's document identity; it is never edited or projected\n * back into the graph.\n */\nexport class EntityEditSandboxSession {\n private readonly document: VideoDocument;\n private readonly entitySandbox: EntitySandbox;\n private readonly entityRevision: number;\n private readonly baseRows: EntityRelationRows;\n private readonly domainIdFactory: DomainIdFactory;\n private readonly logs: string[] = [];\n private readonly onLog: ((line: string) => void) | undefined;\n private logBytes = 0;\n private readonly resolvedCaptionAssets = new Set<string>();\n private logCapped = false;\n\n readonly edit: EntityEditFacade;\n readonly timeline: EntityTimelineFacade;\n readonly entities: BusinessEntityFacade;\n readonly relations: BusinessRelationFacade;\n readonly console: ConsoleShim;\n readonly checkpoint: () => SandboxCheckpoint;\n readonly rollbackTo: (cp: SandboxCheckpoint) => void;\n\n constructor(document: VideoDocument, options?: EditSandboxSessionOptions) {\n this.document = structuredClone(document);\n this.entityRevision = options?.entityState?.revision ?? 0;\n this.baseRows = toDslRows(\n options?.entityState ?? { revision: 0, audioScriptEntityId: null, entities: [], relations: [] },\n );\n this.domainIdFactory =\n options?.domainIdFactory ??\n (() => {\n throw new Error('Entity id factory is unavailable in this sandbox host');\n });\n this.onLog = options?.onLog;\n this.entitySandbox = new EntitySandbox({\n state: options?.entityState,\n idFactory: this.domainIdFactory,\n onCommand: options?.onEntityCommand,\n onTruncate: options?.onEntityTruncate,\n });\n\n this.edit = this.buildEditFacade();\n this.timeline = { snapshot: () => this.snapshot() };\n const business = businessFacades(this.entitySandbox.entities, this.entitySandbox.relations);\n this.entities = business.entities;\n this.relations = business.relations;\n this.console = this.buildConsoleShim();\n this.checkpoint = () => ({ index: this.entitySandbox.commandCount });\n this.rollbackTo = (cp) => this.entitySandbox.rollbackTo(cp.index);\n }\n\n /** Resolve only the resource attached to this Entity; I/O remains in the parent host. */\n async rgetAssetFromEntity(\n entityId: string,\n load: (entity: SandboxEntity) => Promise<EntityAssetContent>,\n ): Promise<EntityAssetContent> {\n const entity = this.entitySandbox.entities.get(entityId);\n if (!entity || entity.entity_kind === 'asset') throw new Error(`Business Entity not found: ${entityId}`);\n const external = entity.payload.external;\n if (!external || typeof external !== 'object' || Array.isArray(external) || typeof external.key !== 'string')\n throw new Error(`Entity ${entityId} has no attached Asset`);\n const assetId = external.key;\n const result = await load(entity);\n if (result.assetId !== external.key) throw new Error('Host returned a different Entity Asset');\n const current = this.entitySandbox.entities.get(entityId);\n if (!current || JSON.stringify(current.payload.external) !== JSON.stringify(external))\n throw new Error('Entity resource changed during its read');\n if (entity.entity_kind === 'caption' && !this.initializedAsset(entityId, external.key)) {\n const timed = captionAssetSegments(result.content);\n const scriptId = this.entitySandbox.audioScriptEntityId;\n if (!scriptId) throw new Error('Project AudioScript is missing');\n const script = this.entitySandbox.entities.get(scriptId)!;\n const segments = timed.map((segment, index) => ({\n segmentId: `asset:${assetId}:${index}`,\n text: segment.text,\n }));\n const existing = script.payload.segments as { segmentId: string; text: string }[];\n const additions = segments.filter((segment) => !existing.some((item) => item.segmentId === segment.segmentId));\n this.entitySandbox.entities.update({ entity_id: scriptId, payload: { segments: [...existing, ...additions] } });\n const ranges = timed.map((segment, index) => ({\n segmentId: segments[index]!.segmentId,\n startMs: segment.start_time_ms,\n endMs: segment.end_time_ms,\n }));\n this.entitySandbox.entities.update({\n entity_id: entityId,\n payload: {\n baseEntityIds: [scriptId],\n selections: segments.map(({ segmentId }) => ({ segmentId })),\n extent: {\n kind: 'bounded',\n start: Math.min(...ranges.map((r) => r.startMs)),\n end: Math.max(...ranges.map((r) => r.endMs)),\n },\n sampling: 'native',\n coordinateSpace: 'milliseconds',\n segmentRanges: ranges,\n },\n });\n const markerId = this.entitySandbox.entities.create({\n entity_kind: 'sequence-marker',\n payload: {\n sourceRange: {\n start: Math.min(...ranges.map((r) => r.startMs)),\n end: Math.max(...ranges.map((r) => r.endMs)),\n },\n duration: { mode: 'from-source' },\n segmentRanges: ranges,\n },\n });\n this.entitySandbox.relations.link({\n relation_kind: 'audio-script-marker',\n endpoint_0_entity_id: scriptId,\n endpoint_1_entity_id: markerId,\n });\n }\n this.resolvedCaptionAssets.add(`${entityId}:${assetId}`);\n return result;\n }\n\n private initializedAsset(entityId: string, assetId: string): boolean {\n const current = this.entitySandbox.entities.get(entityId);\n if (\n this.resolvedCaptionAssets.has(`${entityId}:${assetId}`) &&\n Array.isArray(current?.payload.selections) &&\n Array.isArray(current?.payload.baseEntityIds)\n )\n return true;\n const baseline = this.baseRows.entities.find((row) => row.entityId === entityId);\n const external = baseline?.payload.external;\n return (\n !!external &&\n typeof external === 'object' &&\n !Array.isArray(external) &&\n 'key' in external &&\n external.key === assetId\n );\n }\n\n /** Finish unawaited Caption initialization before validation; no partial rows are published. */\n async prepareEntityAssets(load: (entity: SandboxEntity) => Promise<EntityAssetContent>): Promise<void> {\n for (const entity of this.entitySandbox.entities.list()) {\n const external = entity.payload.external;\n if (\n entity.entity_kind === 'caption' &&\n external &&\n typeof external === 'object' &&\n !Array.isArray(external) &&\n typeof external.key === 'string' &&\n !this.initializedAsset(entity.entity_id, external.key)\n )\n await this.rgetAssetFromEntity(entity.entity_id, load);\n }\n }\n\n buildPlan(baseVersion: string): ChangePlan {\n const entityPlan = this.entitySandbox.buildPlan();\n assertCanonicalEditorResources(toDslRows(entityPlan.rows));\n assertMediaAssetWritePolicy(this.baseRows, toDslRows(entityPlan.rows));\n if (entityPlan.rows.loroSnapshot) projectEntityTimeline(toDslRows(entityPlan.rows), this.document.meta);\n return {\n ...(entityPlan.rows.loroSnapshot\n ? {\n loro_update: bytesToBase64(\n compileEntityRows(base64ToBytes(entityPlan.rows.loroSnapshot), toDslRows(entityPlan.rows)).update,\n ),\n }\n : {}),\n plan_kind: 'entities',\n doc_id: this.document.meta.draft_id ?? '',\n base_version: baseVersion,\n ops: [],\n entity_base_revision: entityPlan.base_revision,\n entity_commands: entityPlan.commands,\n entity_rows: entityPlan.rows,\n deleted_entity_ids: entityPlan.deleted_entity_ids,\n deleted_relation_ids: entityPlan.deleted_relation_ids,\n preview: this.entitySandbox.renderPreview(),\n logs: this.logs.slice(),\n };\n }\n\n getLogs(): readonly string[] {\n return this.logs;\n }\n\n private buildEditFacade(): EntityEditFacade {\n return {\n insertClip: (input) => this.runNativeEdit((editor) => editor.insertClip(input)),\n insertPlacedClip: (input) => this.runNativeEdit((editor) => editor.insertPlacedClip(input)),\n updateClipMarker: (input) => this.runNativeEdit((editor) => editor.updateClipMarker(input)),\n setClipPlacement: (input) => this.runNativeEdit((editor) => editor.setClipPlacement(input)),\n moveSequentialClips: (input) => this.runNativeEdit((editor) => editor.moveSequentialClips(input)),\n moveClip: (input) => this.runNativeEdit((editor) => editor.moveClip(input)),\n replaceClipContent: (input) => this.runNativeEdit((editor) => editor.replaceClipContent(input)),\n setClipVolume: (input) => this.runNativeEdit((editor) => editor.setClipVolume(input)),\n setClipSpeed: (input) => this.runNativeEdit((editor) => editor.setClipSpeed(input)),\n trimClip: (input) => this.runNativeEdit((editor) => editor.trimClip(input)),\n deleteClip: (input) => this.runNativeEdit((editor) => editor.deleteClip(input)),\n deleteClipTree: (input) => this.runNativeEdit((editor) => editor.deleteClipTree(input)),\n updateClip: (input) => this.runNativeEdit((editor) => editor.updateClip(input)),\n moveVoiceover: (input) => this.runNativeEdit((editor) => editor.moveVoiceover(input)),\n moveClipsToStarts: (input) => this.runNativeEdit((editor) => editor.moveClipsToStarts(input)),\n deleteVoiceover: (input) => this.runNativeEdit((editor) => editor.deleteVoiceover(input)),\n deleteBgm: (input) => this.runNativeEdit((editor) => editor.deleteBgm(input)),\n setCaptionVisibility: (input) => this.runNativeEdit((editor) => editor.setCaptionVisibility(input)),\n patchCaptionStyle: (input) => this.runNativeEdit((editor) => editor.patchCaptionStyle(input)),\n insertCaptionClip: (input) => this.runNativeEdit((editor) => editor.insertCaptionClip(input)),\n };\n }\n\n private runNativeEdit<T>(mutate: (editor: EntityTimelineEditor) => T): T {\n const checkpoint = this.entitySandbox.commandCount;\n try {\n const before = this.entitySandbox.buildPlan().rows;\n const editor = new EntityTimelineEditor(toDslRows(before), this.domainIdFactory);\n const result = mutate(editor);\n const expected = fromDslRows(editor.rows(), before.revision, before.audioScriptEntityId);\n applyGraphDiff(this.entitySandbox, before, expected);\n const applied = this.entitySandbox.buildPlan().rows;\n if (!graphRowsEqual(applied, expected)) {\n throw new Error('Entity timeline command diff did not reproduce the editor result');\n }\n return result;\n } catch (error) {\n this.entitySandbox.rollbackTo(checkpoint);\n throw error;\n }\n }\n\n private snapshot(): EntityStoreSnapshot & { audioScriptEntityId: string } {\n const audioScriptEntityId = this.entitySandbox.audioScriptEntityId;\n if (audioScriptEntityId === null) throw new Error('Document AudioScript is not initialized');\n return {\n revision: this.entityRevision,\n audioScriptEntityId,\n entities: this.entities.list(),\n relations: this.relations.list(),\n };\n }\n\n private appendLog(line: string): void {\n if (this.logCapped) return;\n if (this.logs.length >= LOG_LINE_CAP || this.logBytes >= LOG_BYTE_CAP) {\n this.logs.push(LOG_TRUNCATED);\n this.logCapped = true;\n this.onLog?.(LOG_TRUNCATED);\n return;\n }\n const out =\n line.length > LOG_LINE_MAX ? `${line.slice(0, LOG_LINE_MAX - TRUNCATE_MARK.length)}${TRUNCATE_MARK}` : line;\n this.logs.push(out);\n this.logBytes += out.length;\n this.onLog?.(out);\n }\n\n private buildConsoleShim(): ConsoleShim {\n const write = (...args: unknown[]) => this.appendLog(args.map(formatLogArg).join(' '));\n return { log: write, info: write, warn: write, error: write };\n }\n}\n\nfunction applyGraphDiff(sandbox: EntitySandbox, before: EntityStoreSnapshot, after: EntityStoreSnapshot): void {\n const beforeEntities = new Map(before.entities.map((entity) => [entity.entity_id, entity]));\n const afterEntities = new Map(after.entities.map((entity) => [entity.entity_id, entity]));\n const beforeRelations = new Map(before.relations.map((relation) => [relation.relation_id, relation]));\n const afterRelations = new Map(after.relations.map((relation) => [relation.relation_id, relation]));\n\n for (const [entityId, previous] of beforeEntities) {\n const next = afterEntities.get(entityId);\n if (next != null && next.entity_kind !== previous.entity_kind) {\n throw new Error(\n `Entity id \"${entityId}\" cannot change kind from \"${previous.entity_kind}\" to \"${next.entity_kind}\"`,\n );\n }\n }\n for (const [relationId, previous] of beforeRelations) {\n const next = afterRelations.get(relationId);\n if (\n next != null &&\n (next.relation_kind !== previous.relation_kind ||\n next.endpoint_0_entity_id !== previous.endpoint_0_entity_id ||\n next.endpoint_1_entity_id !== previous.endpoint_1_entity_id)\n ) {\n throw new Error(`Relation id \"${relationId}\" cannot change kind or persisted endpoint positions`);\n }\n }\n\n const relationIdsToReplace = new Set(\n [...beforeRelations]\n .filter(([relationId, previous]) => {\n const next = afterRelations.get(relationId);\n return next != null && (!jsonEqual(previous.metadata, next.metadata) || !jsonEqual(previous.trace, next.trace));\n })\n .map(([relationId]) => relationId),\n );\n const relationIdsToUnlink = [...beforeRelations.keys()]\n .filter((relationId) => !afterRelations.has(relationId) || relationIdsToReplace.has(relationId))\n .sort();\n for (const relationId of relationIdsToUnlink) sandbox.relations.unlink({ relation_id: relationId });\n\n const entityIdsToDelete = [...beforeEntities.keys()].filter((entityId) => !afterEntities.has(entityId)).sort();\n for (const entityId of entityIdsToDelete) sandbox.entities.delete({ entity_id: entityId });\n\n const entitiesToCreate = [...afterEntities.values()]\n .filter((entity) => !beforeEntities.has(entity.entity_id))\n .sort((left, right) => left.entity_id.localeCompare(right.entity_id));\n for (const entity of entitiesToCreate) sandbox.entities.create(entity as CreateEntityInput);\n\n const entitiesToUpdate = [...afterEntities.values()]\n .filter((entity) => {\n const previous = beforeEntities.get(entity.entity_id);\n return previous != null && !jsonEqual(previous.payload, entity.payload);\n })\n .sort((left, right) => left.entity_id.localeCompare(right.entity_id));\n for (const entity of entitiesToUpdate) {\n sandbox.replaceOwnedPayload({ entity_id: entity.entity_id, payload: entity.payload });\n }\n\n const relationsToLink = [...afterRelations.values()]\n .filter((relation) => !beforeRelations.has(relation.relation_id) || relationIdsToReplace.has(relation.relation_id))\n .sort((left, right) => left.relation_id.localeCompare(right.relation_id));\n for (const relation of relationsToLink) linkRelation(sandbox, relation);\n}\n\nfunction linkRelation(sandbox: EntitySandbox, relation: SandboxRelation): void {\n if (relation.relation_kind === 'generated') {\n sandbox.relations.linkGenerated({\n relation_id: relation.relation_id,\n output_entity_id: relation.endpoint_0_entity_id,\n input_entity_id: relation.endpoint_1_entity_id,\n trace: relation.trace,\n });\n return;\n }\n if (relation.relation_kind === 'clip-anchor') {\n sandbox.relations.linkClipAnchor({\n relation_id: relation.relation_id,\n child_clip_entity_id: relation.endpoint_0_entity_id,\n host_clip_entity_id: relation.endpoint_1_entity_id,\n trace: relation.trace,\n });\n return;\n }\n if (relation.relation_kind === 'phonetic-script-render') {\n const firstIsVoice = sandbox.entities.get(relation.endpoint_0_entity_id)?.entity_kind === 'voice';\n sandbox.relations.linkPhoneticScriptRender({\n relation_id: relation.relation_id,\n output_entity_id: firstIsVoice ? relation.endpoint_0_entity_id : relation.endpoint_1_entity_id,\n phonetic_script_entity_id: firstIsVoice ? relation.endpoint_1_entity_id : relation.endpoint_0_entity_id,\n trace: relation.trace,\n });\n return;\n }\n if (relation.relation_kind === 'audio-script-source') {\n const firstIsScript = sandbox.entities.get(relation.endpoint_0_entity_id)?.entity_kind === 'audio-script';\n sandbox.relations.linkAudioScriptSource({\n relation_id: relation.relation_id,\n script_entity_id: firstIsScript ? relation.endpoint_0_entity_id : relation.endpoint_1_entity_id,\n source_entity_id: firstIsScript ? relation.endpoint_1_entity_id : relation.endpoint_0_entity_id,\n trace: relation.trace,\n });\n return;\n }\n sandbox.relations.link({\n relation_id: relation.relation_id,\n relation_kind: relation.relation_kind,\n endpoint_0_entity_id: relation.endpoint_0_entity_id,\n endpoint_1_entity_id: relation.endpoint_1_entity_id,\n metadata: relation.metadata,\n trace: relation.trace,\n } as LinkRelationInput);\n}\n\nfunction toDslRows(snapshot: EntityStoreSnapshot): EntityRelationRows {\n return {\n entities: snapshot.entities.map((entity) => ({\n entityId: createEntityId(entity.entity_id),\n entityKind: entity.entity_kind,\n payload: structuredClone(entity.payload),\n })) as EntityRow[],\n relations: snapshot.relations.map((relation) => ({\n relationId: createRelationId(relation.relation_id),\n relationKind: relation.relation_kind,\n endpoint0EntityId: createEntityId(relation.endpoint_0_entity_id),\n endpoint1EntityId: createEntityId(relation.endpoint_1_entity_id),\n metadata: structuredClone(relation.metadata),\n trace: structuredClone(relation.trace),\n })) as RelationRow[],\n };\n}\n\nfunction fromDslRows(\n rows: EntityRelationRows,\n revision: number,\n audioScriptEntityId: string | null,\n): EntityStoreSnapshot {\n return {\n revision,\n audioScriptEntityId,\n entities: rows.entities.map(\n (entity) =>\n ({\n entity_id: entity.entityId,\n entity_kind: entity.entityKind,\n payload: structuredClone(entity.payload),\n }) as SandboxEntity,\n ),\n relations: rows.relations.map(\n (relation) =>\n ({\n relation_id: relation.relationId,\n relation_kind: relation.relationKind,\n endpoint_0_entity_id: relation.endpoint0EntityId,\n endpoint_1_entity_id: relation.endpoint1EntityId,\n metadata: structuredClone(relation.metadata),\n trace: structuredClone(relation.trace),\n }) as SandboxRelation,\n ),\n };\n}\n\nfunction jsonEqual(left: unknown, right: unknown): boolean {\n if (Object.is(left, right)) return true;\n if (Array.isArray(left) || Array.isArray(right)) {\n return (\n Array.isArray(left) &&\n Array.isArray(right) &&\n left.length === right.length &&\n left.every((value, index) => jsonEqual(value, right[index]))\n );\n }\n if (!isRecord(left) || !isRecord(right)) return false;\n const leftKeys = Object.keys(left).sort();\n const rightKeys = Object.keys(right).sort();\n return (\n leftKeys.length === rightKeys.length &&\n leftKeys.every((key, index) => key === rightKeys[index] && jsonEqual(left[key], right[key]))\n );\n}\n\nfunction graphRowsEqual(left: EntityStoreSnapshot, right: EntityStoreSnapshot): boolean {\n if (\n left.revision !== right.revision ||\n left.audioScriptEntityId !== right.audioScriptEntityId ||\n left.entities.length !== right.entities.length ||\n left.relations.length !== right.relations.length\n ) {\n return false;\n }\n const rightEntities = new Map(right.entities.map((entity) => [entity.entity_id, entity]));\n const rightRelations = new Map(right.relations.map((relation) => [relation.relation_id, relation]));\n return (\n left.entities.every((entity) => jsonEqual(entity, rightEntities.get(entity.entity_id))) &&\n left.relations.every((relation) => jsonEqual(relation, rightRelations.get(relation.relation_id)))\n );\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction formatLogArg(value: unknown): string {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean' || value === null || value === undefined) {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return '[unstringifiable]';\n }\n}\n","/// <reference types=\"node\" />\nimport { randomUUID } from 'node:crypto';\nimport vm from 'node:vm';\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport type { JournalEntry, PartIdFactory, VideoDocument } from '@mengine/medeo-client';\n\nimport type { EntityAssetContent } from '../entity/entity-asset.ts';\nimport type { SandboxEntity } from '../entity/entity-contract.ts';\nimport type { EntityCommand, EntityStoreSnapshot } from '../entity/entity-contract.ts';\nimport type { DomainIdFactory } from '../entity/entity-sandbox.ts';\nimport { EntityEditSandboxSession } from './entity-script-session.ts';\nimport { EditSandboxSession, type EditSandboxSessionOptions } from './script-session.ts';\n\n/**\n * Node worker entry for trusted edit scripts.\n *\n * Spawns the requested sandbox session, runs the agent script in a bare `vm`\n * context (no fetch/process/setTimeout), and streams journals + logs to the\n * host so hard timeout / OOM termination still preserves partial products.\n */\n\nexport interface WorkerData {\n document: VideoDocument;\n script: string;\n inputs?: Record<string, unknown>;\n entityState?: EntityStoreSnapshot;\n idLabel?: string;\n entityOnly?: boolean;\n}\n\ntype HostMessage =\n | { t: 'entity-asset'; requestId: number; entity: SandboxEntity }\n | { t: 'ready' }\n | { t: 'entry'; entry: JournalEntry }\n | { t: 'entity-entry'; command: EntityCommand }\n | { t: 'log'; line: string }\n | { t: 'truncate'; index: number }\n | { t: 'entity-truncate'; index: number }\n | {\n t: 'done';\n preview: string;\n opsCount: number;\n entityCommandsCount: number;\n loroUpdate?: string;\n entityBaseRevision: number;\n entityRows?: EntityStoreSnapshot;\n deletedEntityIds: readonly string[];\n deletedRelationIds: readonly string[];\n planKind: 'timeline' | 'entities';\n }\n | {\n t: 'fail';\n phase: 'parse' | 'runtime';\n error: { message: string; line?: number; column?: number; stack?: string };\n };\n\nconst data = workerData as WorkerData;\nif (parentPort == null) {\n throw new Error('worker-entry must run inside a worker_threads Worker');\n}\nconst port = parentPort;\nlet requestId = 0;\nconst pending = new Map<number, { resolve: (result: EntityAssetContent) => void; reject: (error: Error) => void }>();\nport.on('message', (message: { t: string; requestId: number; result: EntityAssetContent; error?: string }) => {\n if (message.t !== 'entity-asset-result') return;\n const waiter = pending.get(message.requestId);\n pending.delete(message.requestId);\n if (message.error) waiter?.reject(new Error(message.error));\n else waiter?.resolve(message.result);\n});\nfunction loadEntityAsset(entity: SandboxEntity): Promise<EntityAssetContent> {\n return new Promise((resolve, reject) => {\n const id = ++requestId;\n pending.set(id, { resolve, reject });\n port.postMessage({ t: 'entity-asset', requestId: id, entity });\n });\n}\n\nfunction post(message: HostMessage): void {\n port.postMessage(message);\n}\n\nfunction countingFactory(label: string): PartIdFactory {\n let n = 0;\n return (prefix) => `${prefix}_${label}${++n}`;\n}\n\nfunction domainIdFactory(label?: string): DomainIdFactory {\n let n = 0;\n return (prefix) => `${prefix}_${label == null ? randomUUID() : `${label}${++n}`}`;\n}\n\n/** Extract script line/column from the first `agent-script.js` stack frame. */\nfunction positionFromError(\n error: unknown,\n script?: string,\n phase?: 'parse' | 'runtime',\n): { line?: number; column?: number; stack?: string; message: string } {\n // Duck-type: vm SyntaxError in a worker may fail `instanceof Error` across realms.\n const obj = error != null && typeof error === 'object' ? (error as Record<string, unknown>) : null;\n const message =\n obj != null && typeof obj.message === 'string'\n ? obj.message\n : error instanceof Error\n ? error.message\n : String(error);\n const stack = obj != null && typeof obj.stack === 'string' ? obj.stack : undefined;\n\n let line = typeof obj?.lineNumber === 'number' ? obj.lineNumber : undefined;\n let column = typeof obj?.columnNumber === 'number' ? obj.columnNumber : undefined;\n\n if (stack != null) {\n // Prefer the header form `agent-script.js:N` (SyntaxError) or `agent-script.js:N:M`.\n const match = /agent-script\\.js:(\\d+)(?::(\\d+))?/.exec(stack);\n if (match != null) {\n line = Number(match[1]);\n if (match[2] != null) column = Number(match[2]);\n }\n }\n\n // Parse-phase refinement: V8 often points at the token after an unclosed\n // `{`/`(`/`[`; walk back one line when the previous line ends that way so\n // the reported line matches the agent-authored incomplete construct.\n if (phase === 'parse' && script != null && line != null && line >= 2) {\n const lines = script.split('\\n');\n const prev = lines[line - 2];\n if (prev != null && /[{([]\\s*$/.test(prev)) {\n line = line - 1;\n column = prev.length;\n }\n }\n\n return { message, line, column, stack };\n}\n\nasync function main(): Promise<void> {\n const idFactory = data.idLabel != null ? countingFactory(data.idLabel) : undefined;\n const options: EditSandboxSessionOptions = {\n idFactory,\n entityState: data.entityState,\n domainIdFactory: domainIdFactory(data.idLabel),\n onEntry: (entry) => post({ t: 'entry', entry }),\n onEntityCommand: (command) => post({ t: 'entity-entry', command }),\n onLog: (line) => post({ t: 'log', line }),\n onTruncate: (index) => post({ t: 'truncate', index }),\n onEntityTruncate: (index) => post({ t: 'entity-truncate', index }),\n };\n const session = data.entityOnly\n ? new EntityEditSandboxSession(data.document, options)\n : new EditSandboxSession(data.document, options);\n\n // Prelude stays on the same physical line as script line 1 so stack line\n // numbers map 1:1 onto the agent script (no leading newline).\n const wrapped = `(async (edit, timeline, entities, relations, checkpoint, rollbackTo, inputs, console, rgetAssetFromEntity) => {${data.script}\\n})`;\n\n const ctx = vm.createContext(Object.create(null) as Record<string, unknown>);\n\n let run: unknown;\n try {\n run = vm.runInContext(wrapped, ctx, { filename: 'agent-script.js' });\n } catch (error) {\n const pos = positionFromError(error, data.script, 'parse');\n post({ t: 'fail', phase: 'parse', error: pos });\n return;\n }\n\n if (typeof run !== 'function') {\n post({\n t: 'fail',\n phase: 'runtime',\n error: { message: 'agent script wrapper did not evaluate to a function' },\n });\n return;\n }\n\n try {\n const invoke = run as (\n edit: typeof session.edit,\n timeline: typeof session.timeline,\n entities: typeof session.entities,\n relations: typeof session.relations,\n checkpoint: typeof session.checkpoint,\n rollbackTo: typeof session.rollbackTo,\n inputs: Record<string, unknown>,\n console: typeof session.console,\n rgetAssetFromEntity: (entityId: string) => Promise<EntityAssetContent>,\n ) => Promise<unknown>;\n // Signal host that cold start is done; timeout wall-clock starts here.\n post({ t: 'ready' });\n await invoke(\n session.edit,\n session.timeline,\n session.entities,\n session.relations,\n session.checkpoint,\n session.rollbackTo,\n data.inputs ?? {},\n session.console,\n (entityId) => {\n if (!(session instanceof EntityEditSandboxSession)) throw new Error('Entity-only sandbox required');\n return session.rgetAssetFromEntity(entityId, loadEntityAsset);\n },\n );\n if (session instanceof EntityEditSandboxSession) await session.prepareEntityAssets(loadEntityAsset);\n } catch (error) {\n const pos = positionFromError(error, data.script, 'runtime');\n post({ t: 'fail', phase: 'runtime', error: pos });\n return;\n }\n\n const plan = session.buildPlan('');\n post({\n t: 'done',\n ...(plan.loro_update ? { loroUpdate: plan.loro_update } : {}),\n preview: plan.preview,\n opsCount: plan.ops.length,\n entityCommandsCount: plan.entity_commands.length,\n entityBaseRevision: plan.entity_base_revision,\n ...(plan.entity_rows !== undefined ? { entityRows: plan.entity_rows } : {}),\n deletedEntityIds: plan.deleted_entity_ids ?? [],\n deletedRelationIds: plan.deleted_relation_ids ?? [],\n planKind: plan.plan_kind,\n });\n}\n\nmain().catch((error: unknown) => {\n const pos = positionFromError(error);\n post({ t: 'fail', phase: 'runtime', error: pos });\n});\n"],"mappings":";;;;;;;AAkBA,SAAgB,qBAAqB,SAA2C;CAC9E,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,KAAK,CAAC,MAAM,QAAQ,QAAQ,QAAQ,GACtG,MAAM,IAAI,MAAM,mEAAmE;CACrF,IAAI,CAAC,QAAQ,SAAS,QAAQ,MAAM,IAAI,MAAM,2CAA2C;CACzF,OAAO,QAAQ,SAAS,KAAK,UAAU;EACrC,IACE,CAAC,SACD,OAAO,UAAU,YACjB,MAAM,QAAQ,KAAK,KACnB,OAAO,MAAM,SAAS,YACtB,CAAC,MAAM,KAAK,KAAK,KACjB,CAAC,OAAO,cAAc,MAAM,aAAa,KACzC,CAAC,OAAO,cAAc,MAAM,WAAW,KACtC,MAAM,gBAA2B,KACjC,MAAM,eAA2B,MAAM,eAExC,MAAM,IAAI,MAAM,sDAAsD;EACxE,OAAO;GAAE,MAAM,MAAM;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CAEA,MAAM,OAAO,QAAQ,UAAU,EAAE;CACjC,KAAK;EACH,GAAG;EACH,GAAI,KAAK,cAAc,EAAE,YAAY,KAAK,YAAY,IAAI,CAAC;EAC3D,SAAS,KAAK;EACd,UAAU,KAAK,IAAI;EACnB,qBAAqB,KAAK,gBAAgB;EAC1C,oBAAoB,KAAK;EACzB,GAAI,KAAK,gBAAgB,KAAA,IAAY,EAAE,YAAY,KAAK,YAAY,IAAI,CAAC;EACzE,kBAAkB,KAAK,sBAAsB,CAAC;EAC9C,oBAAoB,KAAK,wBAAwB,CAAC;EAClD,UAAU,KAAK;CACjB,CAAC;AACH;AAEA,KAAK,EAAE,OAAO,UAAmB;CAE/B,KAAK;EAAE,GAAG;EAAQ,OAAO;EAAW,OADxB,kBAAkB,KACe;CAAE,CAAC;AAClD,CAAC"}
|
|
1
|
+
{"version":3,"file":"worker-entry.mjs","names":[],"sources":["../src/entity/entity-asset.ts","../src/sandbox/entity-script-session.ts","../src/sandbox/worker-entry.ts"],"sourcesContent":["import type { JsonValue, SandboxEntity } from './entity-contract.ts';\n\n/** Immutable resource content resolved by the host for a document Entity. */\nexport interface EntityAssetContent {\n assetId: string;\n content: JsonValue;\n}\n\n/** Host-only I/O. The sandbox supplies an Entity, never an arbitrary Asset query. */\nexport type EntityAssetLoader = (docId: string, entity: SandboxEntity) => Promise<EntityAssetContent>;\n\nexport interface CaptionAssetSegment {\n text: string;\n start_time_ms: number;\n end_time_ms: number;\n}\n\n/** MCAP's output_caption JSON contract; unknown formats never become invented captions. */\nexport function captionAssetSegments(content: JsonValue): CaptionAssetSegment[] {\n if (!content || typeof content !== 'object' || Array.isArray(content) || !Array.isArray(content.segments))\n throw new Error('Caption Asset must contain an output_caption object with segments');\n if (!content.segments.length) throw new Error('Caption Asset contains no speech segments');\n return content.segments.map((value) => {\n if (\n !value ||\n typeof value !== 'object' ||\n Array.isArray(value) ||\n typeof value.text !== 'string' ||\n !value.text.trim() ||\n !Number.isSafeInteger(value.start_time_ms) ||\n !Number.isSafeInteger(value.end_time_ms) ||\n (value.start_time_ms as number) < 0 ||\n (value.end_time_ms as number) <= (value.start_time_ms as number)\n )\n throw new Error('Caption Asset has invalid text or millisecond timing');\n return { text: value.text, start_time_ms: value.start_time_ms as number, end_time_ms: value.end_time_ms as number };\n });\n}\n","import {\n LoroEntityDocument,\n projectEntityTimeline,\n base64ToBytes,\n bytesToBase64,\n assertCanonicalEditorResources,\n assertMediaAssetWritePolicy,\n type VideoDocument,\n} from '@mengine/medeo-client';\nimport { type EntityRelationRows } from '@mengine/medeo-dsl';\n\nimport { captionAssetSegments, type EntityAssetContent } from '../entity/entity-asset.ts';\nimport type {\n BusinessEntityFacade,\n BusinessRelationFacade,\n EntitySandboxCheckpoint,\n SandboxEntity,\n} from '../entity/entity-contract.ts';\nimport { EntitySandbox, toDslRows, type DomainIdFactory } from '../entity/entity-sandbox.ts';\nimport { businessFacades } from './business-facades.ts';\nimport type { ChangePlan, ConsoleShim, EditSandboxSessionOptions } from './script-session.ts';\n\nconst LOG_LINE_MAX = 2000;\nconst LOG_LINE_CAP = 1000;\nconst LOG_BYTE_CAP = 64 * 1024;\nconst TRUNCATE_MARK = '[truncated]';\nconst LOG_TRUNCATED = '[log truncated]';\n\n/** Entity/relation script session; compilation retains the ordered operation journal. */\nexport class EntityEditSandboxSession {\n private readonly document: VideoDocument;\n private readonly entitySandbox: EntitySandbox;\n private readonly baseRows: EntityRelationRows;\n private readonly domainIdFactory: DomainIdFactory;\n private readonly logs: string[] = [];\n private readonly onLog: ((line: string) => void) | undefined;\n private logBytes = 0;\n private readonly resolvedCaptionAssets = new Set<string>();\n private logCapped = false;\n\n readonly entities: BusinessEntityFacade;\n readonly relations: BusinessRelationFacade;\n readonly console: ConsoleShim;\n readonly checkpoint: () => EntitySandboxCheckpoint;\n readonly rollbackTo: (cp: EntitySandboxCheckpoint) => void;\n\n constructor(document: VideoDocument, options?: EditSandboxSessionOptions) {\n this.document = structuredClone(document);\n this.baseRows = toDslRows(\n options?.entityState ?? { revision: 0, audioScriptEntityId: null, entities: [], relations: [] },\n );\n this.domainIdFactory =\n options?.domainIdFactory ??\n (() => {\n throw new Error('Entity id factory is unavailable in this sandbox host');\n });\n this.onLog = options?.onLog;\n this.entitySandbox = new EntitySandbox({\n state: options?.entityState,\n idFactory: this.domainIdFactory,\n onCommand: options?.onEntityCommand,\n onTruncate: options?.onEntityTruncate,\n });\n\n const business = businessFacades(this.entitySandbox.entities, this.entitySandbox.relations);\n this.entities = business.entities;\n this.relations = business.relations;\n this.console = this.buildConsoleShim();\n const checkpoints = new Map<EntitySandboxCheckpoint, number>();\n this.checkpoint = () => {\n const token = Object.freeze({}) as EntitySandboxCheckpoint;\n checkpoints.set(token, this.entitySandbox.commandCount);\n return token;\n };\n this.rollbackTo = (cp) => {\n const index = checkpoints.get(cp);\n if (index === undefined) throw new Error('Invalid or expired sandbox checkpoint');\n this.entitySandbox.rollbackTo(index);\n let later = false;\n for (const token of checkpoints.keys()) {\n if (later) checkpoints.delete(token);\n if (token === cp) later = true;\n }\n };\n }\n\n /** Resolve only the resource attached to this Entity; I/O remains in the parent host. */\n async rgetAssetFromEntity(\n entityId: string,\n load: (entity: SandboxEntity) => Promise<EntityAssetContent>,\n ): Promise<EntityAssetContent> {\n const entity = this.entitySandbox.entities.get(entityId);\n if (!entity || entity.entity_kind === 'asset') throw new Error(`Business Entity not found: ${entityId}`);\n const external = entity.payload.external;\n if (!external || typeof external !== 'object' || Array.isArray(external) || typeof external.key !== 'string')\n throw new Error(`Entity ${entityId} has no attached Asset`);\n const assetId = external.key;\n const result = await load(entity);\n if (result.assetId !== external.key) throw new Error('Host returned a different Entity Asset');\n const current = this.entitySandbox.entities.get(entityId);\n if (!current || JSON.stringify(current.payload.external) !== JSON.stringify(external))\n throw new Error('Entity resource changed during its read');\n if (entity.entity_kind === 'caption' && !this.initializedAsset(entityId, external.key)) {\n const timed = captionAssetSegments(result.content);\n const scriptId = this.entitySandbox.audioScriptEntityId;\n if (!scriptId) throw new Error('Project AudioScript is missing');\n const script = this.entitySandbox.entities.get(scriptId)!;\n const segments = timed.map((segment, index) => ({\n segmentId: `asset:${assetId}:${index}`,\n text: segment.text,\n }));\n const existing = script.payload.segments as { segmentId: string; text: string }[];\n const additions = segments.filter((segment) => !existing.some((item) => item.segmentId === segment.segmentId));\n this.entitySandbox.entities.update({ entity_id: scriptId, payload: { segments: [...existing, ...additions] } });\n const ranges = timed.map((segment, index) => ({\n segmentId: segments[index]!.segmentId,\n startMs: segment.start_time_ms,\n endMs: segment.end_time_ms,\n }));\n this.entitySandbox.entities.update({\n entity_id: entityId,\n payload: {\n baseEntityIds: [scriptId],\n selections: segments.map(({ segmentId }) => ({ segmentId })),\n extent: {\n kind: 'bounded',\n start: Math.min(...ranges.map((r) => r.startMs)),\n end: Math.max(...ranges.map((r) => r.endMs)),\n },\n sampling: 'native',\n coordinateSpace: 'milliseconds',\n segmentRanges: ranges,\n },\n });\n const markerId = this.entitySandbox.entities.create({\n entity_kind: 'sequence-marker',\n payload: {\n sourceRange: {\n start: Math.min(...ranges.map((r) => r.startMs)),\n end: Math.max(...ranges.map((r) => r.endMs)),\n },\n duration: { mode: 'from-source' },\n segmentRanges: ranges,\n },\n });\n this.entitySandbox.relations.link({\n relation_kind: 'audio-script-marker',\n endpoint_0_entity_id: scriptId,\n endpoint_1_entity_id: markerId,\n });\n }\n this.resolvedCaptionAssets.add(`${entityId}:${assetId}`);\n return result;\n }\n\n private initializedAsset(entityId: string, assetId: string): boolean {\n const current = this.entitySandbox.entities.get(entityId);\n if (\n this.resolvedCaptionAssets.has(`${entityId}:${assetId}`) &&\n Array.isArray(current?.payload.selections) &&\n Array.isArray(current?.payload.baseEntityIds)\n )\n return true;\n const baseline = this.baseRows.entities.find((row) => row.entityId === entityId);\n const external = baseline?.payload.external;\n return (\n !!external &&\n typeof external === 'object' &&\n !Array.isArray(external) &&\n 'key' in external &&\n external.key === assetId\n );\n }\n\n /** Finish unawaited Caption initialization before validation; no partial rows are published. */\n async prepareEntityAssets(load: (entity: SandboxEntity) => Promise<EntityAssetContent>): Promise<void> {\n for (const entity of this.entitySandbox.entities.list()) {\n const external = entity.payload.external;\n if (\n entity.entity_kind === 'caption' &&\n external &&\n typeof external === 'object' &&\n !Array.isArray(external) &&\n typeof external.key === 'string' &&\n !this.initializedAsset(entity.entity_id, external.key)\n )\n await this.rgetAssetFromEntity(entity.entity_id, load);\n }\n }\n\n buildPlan(baseVersion: string): ChangePlan {\n const entityPlan = this.entitySandbox.buildPlan();\n assertCanonicalEditorResources(toDslRows(entityPlan.rows));\n assertMediaAssetWritePolicy(this.baseRows, toDslRows(entityPlan.rows));\n if (entityPlan.rows.loroSnapshot) projectEntityTimeline(toDslRows(entityPlan.rows), this.document.meta);\n return {\n ...(entityPlan.rows.loroSnapshot\n ? {\n loro_update: bytesToBase64(this.compileJournal(entityPlan)),\n }\n : {}),\n plan_kind: 'entities',\n doc_id: this.document.meta.draft_id ?? '',\n base_version: baseVersion,\n ops: [],\n entity_base_revision: entityPlan.base_revision,\n entity_commands: entityPlan.commands,\n entity_rows: entityPlan.rows,\n deleted_entity_ids: entityPlan.deleted_entity_ids,\n deleted_relation_ids: entityPlan.deleted_relation_ids,\n preview: this.entitySandbox.renderPreview(),\n logs: this.logs.slice(),\n };\n }\n\n private compileJournal(plan: ReturnType<EntitySandbox['buildPlan']>): Uint8Array {\n const editor = LoroEntityDocument.fromSnapshot(base64ToBytes(plan.rows.loroSnapshot!), (state) => {\n assertCanonicalEditorResources(state.rows);\n projectEntityTimeline(state.rows, this.document.meta);\n });\n return editor.transact((draft) => {\n for (const command of plan.commands) {\n switch (command.kind) {\n case 'create-entity': {\n const rows = toDslRows({\n revision: 0,\n audioScriptEntityId: null,\n entities: [command.entity],\n relations: [],\n });\n draft.create(rows.entities[0]!);\n if (command.entity.entity_kind === 'audio-script')\n draft.attach('audioScriptEntityId', command.entity.entity_id);\n break;\n }\n case 'update-entity':\n draft.replaceOwned(command.entity_id, command.payload);\n break;\n case 'change-entity':\n draft.change(command.entity_id, command.changes);\n break;\n case 'delete-entity':\n draft.delete(command.entity_id);\n break;\n case 'link-relation': {\n const rows = toDslRows({\n revision: 0,\n audioScriptEntityId: null,\n entities: [],\n relations: [command.relation],\n });\n draft.link(rows.relations[0]!);\n break;\n }\n case 'change-relation':\n draft.changeRelation(command.relation_id, command.changes);\n break;\n case 'unlink-relation':\n draft.unlink(command.relation_id);\n break;\n }\n }\n draft.reconcileOrder(toDslRows(plan.rows));\n });\n }\n\n getLogs(): readonly string[] {\n return this.logs;\n }\n\n private appendLog(line: string): void {\n if (this.logCapped) return;\n if (this.logs.length >= LOG_LINE_CAP || this.logBytes >= LOG_BYTE_CAP) {\n this.logs.push(LOG_TRUNCATED);\n this.logCapped = true;\n this.onLog?.(LOG_TRUNCATED);\n return;\n }\n const out =\n line.length > LOG_LINE_MAX ? `${line.slice(0, LOG_LINE_MAX - TRUNCATE_MARK.length)}${TRUNCATE_MARK}` : line;\n this.logs.push(out);\n this.logBytes += out.length;\n this.onLog?.(out);\n }\n\n private buildConsoleShim(): ConsoleShim {\n const write = (...args: unknown[]) => this.appendLog(args.map(formatLogArg).join(' '));\n return { log: write, info: write, warn: write, error: write };\n }\n}\n\nfunction formatLogArg(value: unknown): string {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean' || value === null || value === undefined) {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return '[unstringifiable]';\n }\n}\n","/// <reference types=\"node\" />\nimport { randomUUID } from 'node:crypto';\nimport vm from 'node:vm';\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport type { JournalEntry, PartIdFactory, VideoDocument } from '@mengine/medeo-client';\n\nimport type { EntityAssetContent } from '../entity/entity-asset.ts';\nimport type { SandboxEntity } from '../entity/entity-contract.ts';\nimport type { EntityCommand, EntityStoreSnapshot } from '../entity/entity-contract.ts';\nimport type { DomainIdFactory } from '../entity/entity-sandbox.ts';\nimport { EntityEditSandboxSession } from './entity-script-session.ts';\nimport { type EditSandboxSessionOptions } from './script-session.ts';\n\n/**\n * Node worker entry for trusted edit scripts.\n *\n * Spawns the requested sandbox session, runs the agent script in a bare `vm`\n * context (no fetch/process/setTimeout), and streams journals + logs to the\n * host so hard timeout / OOM termination still preserves partial products.\n */\n\nexport interface WorkerData {\n document: VideoDocument;\n script: string;\n inputs?: Record<string, unknown>;\n entityState?: EntityStoreSnapshot;\n idLabel?: string;\n}\n\ntype HostMessage =\n | { t: 'entity-asset'; requestId: number; entity: SandboxEntity }\n | { t: 'ready' }\n | { t: 'entry'; entry: JournalEntry }\n | { t: 'entity-entry'; command: EntityCommand }\n | { t: 'log'; line: string }\n | { t: 'truncate'; index: number }\n | { t: 'entity-truncate'; index: number }\n | {\n t: 'done';\n preview: string;\n opsCount: number;\n entityCommandsCount: number;\n loroUpdate?: string;\n entityBaseRevision: number;\n entityRows?: EntityStoreSnapshot;\n deletedEntityIds: readonly string[];\n deletedRelationIds: readonly string[];\n planKind: 'timeline' | 'entities';\n }\n | {\n t: 'fail';\n phase: 'parse' | 'runtime';\n error: { message: string; line?: number; column?: number; stack?: string };\n };\n\nconst data = workerData as WorkerData;\nif (parentPort == null) {\n throw new Error('worker-entry must run inside a worker_threads Worker');\n}\nconst port = parentPort;\nlet requestId = 0;\nconst pending = new Map<number, { resolve: (result: EntityAssetContent) => void; reject: (error: Error) => void }>();\nport.on('message', (message: { t: string; requestId: number; result: EntityAssetContent; error?: string }) => {\n if (message.t !== 'entity-asset-result') return;\n const waiter = pending.get(message.requestId);\n pending.delete(message.requestId);\n if (message.error) waiter?.reject(new Error(message.error));\n else waiter?.resolve(message.result);\n});\nfunction loadEntityAsset(entity: SandboxEntity): Promise<EntityAssetContent> {\n return new Promise((resolve, reject) => {\n const id = ++requestId;\n pending.set(id, { resolve, reject });\n port.postMessage({ t: 'entity-asset', requestId: id, entity });\n });\n}\n\nfunction post(message: HostMessage): void {\n port.postMessage(message);\n}\n\nfunction countingFactory(label: string): PartIdFactory {\n let n = 0;\n return (prefix) => `${prefix}_${label}${++n}`;\n}\n\nfunction domainIdFactory(label?: string): DomainIdFactory {\n let n = 0;\n return (prefix) => `${prefix}_${label == null ? randomUUID() : `${label}${++n}`}`;\n}\n\n/** Extract script line/column from the first `agent-script.js` stack frame. */\nfunction positionFromError(\n error: unknown,\n script?: string,\n phase?: 'parse' | 'runtime',\n): { line?: number; column?: number; stack?: string; message: string } {\n // Duck-type: vm SyntaxError in a worker may fail `instanceof Error` across realms.\n const obj = error != null && typeof error === 'object' ? (error as Record<string, unknown>) : null;\n const message =\n obj != null && typeof obj.message === 'string'\n ? obj.message\n : error instanceof Error\n ? error.message\n : String(error);\n const stack = obj != null && typeof obj.stack === 'string' ? obj.stack : undefined;\n\n let line = typeof obj?.lineNumber === 'number' ? obj.lineNumber : undefined;\n let column = typeof obj?.columnNumber === 'number' ? obj.columnNumber : undefined;\n\n if (stack != null) {\n // Prefer the header form `agent-script.js:N` (SyntaxError) or `agent-script.js:N:M`.\n const match = /agent-script\\.js:(\\d+)(?::(\\d+))?/.exec(stack);\n if (match != null) {\n line = Number(match[1]);\n if (match[2] != null) column = Number(match[2]);\n }\n }\n\n // Parse-phase refinement: V8 often points at the token after an unclosed\n // `{`/`(`/`[`; walk back one line when the previous line ends that way so\n // the reported line matches the agent-authored incomplete construct.\n if (phase === 'parse' && script != null && line != null && line >= 2) {\n const lines = script.split('\\n');\n const prev = lines[line - 2];\n if (prev != null && /[{([]\\s*$/.test(prev)) {\n line = line - 1;\n column = prev.length;\n }\n }\n\n return { message, line, column, stack };\n}\n\nasync function main(): Promise<void> {\n const idFactory = data.idLabel != null ? countingFactory(data.idLabel) : undefined;\n const options: EditSandboxSessionOptions = {\n idFactory,\n entityState: data.entityState,\n domainIdFactory: domainIdFactory(data.idLabel),\n onEntry: (entry) => post({ t: 'entry', entry }),\n onEntityCommand: (command) => post({ t: 'entity-entry', command }),\n onLog: (line) => post({ t: 'log', line }),\n onTruncate: (index) => post({ t: 'truncate', index }),\n onEntityTruncate: (index) => post({ t: 'entity-truncate', index }),\n };\n const session = new EntityEditSandboxSession(data.document, options);\n\n // Prelude stays on the same physical line as script line 1 so stack line\n // numbers map 1:1 onto the agent script (no leading newline).\n const wrapped = `(async (entities, relations, checkpoint, rollbackTo, inputs, console, rgetAssetFromEntity) => {${data.script}\\n})`;\n\n const ctx = vm.createContext(Object.create(null) as Record<string, unknown>);\n\n let run: unknown;\n try {\n run = vm.runInContext(wrapped, ctx, { filename: 'agent-script.js' });\n } catch (error) {\n const pos = positionFromError(error, data.script, 'parse');\n post({ t: 'fail', phase: 'parse', error: pos });\n return;\n }\n\n if (typeof run !== 'function') {\n post({\n t: 'fail',\n phase: 'runtime',\n error: { message: 'agent script wrapper did not evaluate to a function' },\n });\n return;\n }\n\n try {\n const invoke = run as (\n entities: typeof session.entities,\n relations: typeof session.relations,\n checkpoint: typeof session.checkpoint,\n rollbackTo: typeof session.rollbackTo,\n inputs: Record<string, unknown>,\n console: typeof session.console,\n rgetAssetFromEntity: (entityId: string) => Promise<EntityAssetContent>,\n ) => Promise<unknown>;\n // Signal host that cold start is done; timeout wall-clock starts here.\n post({ t: 'ready' });\n await invoke(\n session.entities,\n session.relations,\n session.checkpoint,\n session.rollbackTo,\n data.inputs ?? {},\n session.console,\n (entityId) => {\n return session.rgetAssetFromEntity(entityId, loadEntityAsset);\n },\n );\n await session.prepareEntityAssets(loadEntityAsset);\n } catch (error) {\n const pos = positionFromError(error, data.script, 'runtime');\n post({ t: 'fail', phase: 'runtime', error: pos });\n return;\n }\n\n const plan = session.buildPlan('');\n post({\n t: 'done',\n ...(plan.loro_update ? { loroUpdate: plan.loro_update } : {}),\n preview: plan.preview,\n opsCount: plan.ops.length,\n entityCommandsCount: plan.entity_commands.length,\n entityBaseRevision: plan.entity_base_revision,\n ...(plan.entity_rows !== undefined ? { entityRows: plan.entity_rows } : {}),\n deletedEntityIds: plan.deleted_entity_ids ?? [],\n deletedRelationIds: plan.deleted_relation_ids ?? [],\n planKind: plan.plan_kind,\n });\n}\n\nmain().catch((error: unknown) => {\n const pos = positionFromError(error);\n post({ t: 'fail', phase: 'runtime', error: pos });\n});\n"],"mappings":";;;;;;;AAkBA,SAAgB,qBAAqB,SAA2C;CAC9E,IAAI,CAAC,WAAW,OAAO,YAAY,YAAY,MAAM,QAAQ,OAAO,KAAK,CAAC,MAAM,QAAQ,QAAQ,QAAQ,GACtG,MAAM,IAAI,MAAM,mEAAmE;CACrF,IAAI,CAAC,QAAQ,SAAS,QAAQ,MAAM,IAAI,MAAM,2CAA2C;CACzF,OAAO,QAAQ,SAAS,KAAK,UAAU;EACrC,IACE,CAAC,SACD,OAAO,UAAU,YACjB,MAAM,QAAQ,KAAK,KACnB,OAAO,MAAM,SAAS,YACtB,CAAC,MAAM,KAAK,KAAK,KACjB,CAAC,OAAO,cAAc,MAAM,aAAa,KACzC,CAAC,OAAO,cAAc,MAAM,WAAW,KACtC,MAAM,gBAA2B,KACjC,MAAM,eAA2B,MAAM,eAExC,MAAM,IAAI,MAAM,sDAAsD;EACxE,OAAO;GAAE,MAAM,MAAM;GAAM,eAAe,MAAM;GAAyB,aAAa,MAAM;EAAsB;CACpH,CAAC;AACH;;;ACfA,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,eAAe,KAAK;AAC1B,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;;AAGtB,IAAa,2BAAb,MAAsC;CACpC;CACA;CACA;CACA;CACA,OAAkC,CAAC;CACnC;CACA,WAAmB;CACnB,wCAAyC,IAAI,IAAY;CACzD,YAAoB;CAEpB;CACA;CACA;CACA;CACA;CAEA,YAAY,UAAyB,SAAqC;EACxE,KAAK,WAAW,gBAAgB,QAAQ;EACxC,KAAK,WAAW,UACd,SAAS,eAAe;GAAE,UAAU;GAAG,qBAAqB;GAAM,UAAU,CAAC;GAAG,WAAW,CAAC;EAAE,CAChG;EACA,KAAK,kBACH,SAAS,0BACF;GACL,MAAM,IAAI,MAAM,uDAAuD;EACzE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sD;EAC1E,CAAC;EACD;CACF;CAEA,IAAI;EACF,MAAM,SAAS;EAUf,KAAK,EAAE,GAAG,QAAQ,CAAC;EACnB,MAAM,OACJ,QAAQ,UACR,QAAQ,WACR,QAAQ,YACR,QAAQ,YACR,KAAK,UAAU,CAAC,GAChB,QAAQ,UACP,aAAa;GACZ,OAAO,QAAQ,oBAAoB,UAAU,eAAe;EAC9D,CACF;EACA,MAAM,QAAQ,oBAAoB,eAAe;CACnD,SAAS,OAAO;EAEd,KAAK;GAAE,GAAG;GAAQ,OAAO;GAAW,OADxB,kBAAkB,OAAO,KAAK,QAAQ,SACL;EAAE,CAAC;EAChD;CACF;CAEA,MAAM,OAAO,QAAQ,UAAU,EAAE;CACjC,KAAK;EACH,GAAG;EACH,GAAI,KAAK,cAAc,EAAE,YAAY,KAAK,YAAY,IAAI,CAAC;EAC3D,SAAS,KAAK;EACd,UAAU,KAAK,IAAI;EACnB,qBAAqB,KAAK,gBAAgB;EAC1C,oBAAoB,KAAK;EACzB,GAAI,KAAK,gBAAgB,KAAA,IAAY,EAAE,YAAY,KAAK,YAAY,IAAI,CAAC;EACzE,kBAAkB,KAAK,sBAAsB,CAAC;EAC9C,oBAAoB,KAAK,wBAAwB,CAAC;EAClD,UAAU,KAAK;CACjB,CAAC;AACH;AAEA,KAAK,EAAE,OAAO,UAAmB;CAE/B,KAAK;EAAE,GAAG;EAAQ,OAAO;EAAW,OADxB,kBAAkB,KACe;CAAE,CAAC;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mengine/medeo-tool",
|
|
3
|
-
"version": "1.4.1-alpha.
|
|
3
|
+
"version": "1.4.1-alpha.3",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@mengine/medeo-client": "1.4.1-alpha.
|
|
27
|
+
"@mengine/medeo-client": "1.4.1-alpha.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^25.9.1",
|