@mengine/medeo-tool 1.0.1-alpha.2 → 1.2.1-alpha.10

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.
@@ -1,6 +1,294 @@
1
- import { t as EditSandboxSession } from "./script-session-B8fc9Ccb.mjs";
1
+ import { a as createRelationId, i as createEntityId, n as EntitySandbox, t as EditSandboxSession } from "./script-session-B4fLNe-p.mjs";
2
+ import { EntityTimelineEditor, assertCanonicalEditorResources, assertMediaAssetWritePolicy } from "@mengine/medeo-client";
2
3
  import { parentPort, workerData } from "node:worker_threads";
4
+ import { randomUUID } from "node:crypto";
3
5
  import vm from "node:vm";
6
+ //#region src/sandbox/entity-script-session.ts
7
+ const LOG_LINE_MAX = 2e3;
8
+ const LOG_LINE_CAP = 1e3;
9
+ const LOG_BYTE_CAP = 64 * 1024;
10
+ const TRUNCATE_MARK = "[truncated]";
11
+ const LOG_TRUNCATED = "[log truncated]";
12
+ /**
13
+ * Entity-only sandbox session used by the production model path.
14
+ *
15
+ * Native timeline operations execute against a detached graph editor and are
16
+ * then journaled as ordinary EntitySandbox commands. VideoDocument is retained
17
+ * only for the request's document identity; it is never edited or projected
18
+ * back into the graph.
19
+ */
20
+ var EntityEditSandboxSession = class {
21
+ document;
22
+ entitySandbox;
23
+ entityRevision;
24
+ baseRows;
25
+ domainIdFactory;
26
+ logs = [];
27
+ onLog;
28
+ logBytes = 0;
29
+ logCapped = false;
30
+ edit;
31
+ timeline;
32
+ entities;
33
+ relations;
34
+ console;
35
+ checkpoint;
36
+ rollbackTo;
37
+ constructor(document, options) {
38
+ this.document = structuredClone(document);
39
+ this.entityRevision = options?.entityState?.revision ?? 0;
40
+ this.baseRows = toDslRows(options?.entityState ?? {
41
+ revision: 0,
42
+ entities: [],
43
+ relations: []
44
+ });
45
+ this.domainIdFactory = options?.domainIdFactory ?? (() => {
46
+ throw new Error("Entity id factory is unavailable in this sandbox host");
47
+ });
48
+ this.onLog = options?.onLog;
49
+ this.entitySandbox = new EntitySandbox({
50
+ state: options?.entityState,
51
+ idFactory: this.domainIdFactory,
52
+ onCommand: options?.onEntityCommand,
53
+ onTruncate: options?.onEntityTruncate
54
+ });
55
+ this.edit = this.buildEditFacade();
56
+ this.timeline = { snapshot: () => this.snapshot() };
57
+ this.entities = this.entitySandbox.entities;
58
+ this.relations = this.entitySandbox.relations;
59
+ this.console = this.buildConsoleShim();
60
+ this.checkpoint = () => ({ index: this.entitySandbox.commandCount });
61
+ this.rollbackTo = (cp) => this.entitySandbox.rollbackTo(cp.index);
62
+ }
63
+ buildPlan(baseVersion) {
64
+ const entityPlan = this.entitySandbox.buildPlan();
65
+ assertCanonicalEditorResources(toDslRows(entityPlan.rows));
66
+ assertMediaAssetWritePolicy(this.baseRows, toDslRows(entityPlan.rows));
67
+ return {
68
+ plan_kind: "entities",
69
+ doc_id: this.document.meta.draft_id ?? "",
70
+ base_version: baseVersion,
71
+ ops: [],
72
+ entity_base_revision: entityPlan.base_revision,
73
+ entity_commands: entityPlan.commands,
74
+ entity_rows: entityPlan.rows,
75
+ deleted_entity_ids: entityPlan.deleted_entity_ids,
76
+ deleted_relation_ids: entityPlan.deleted_relation_ids,
77
+ preview: this.entitySandbox.renderPreview(),
78
+ logs: this.logs.slice()
79
+ };
80
+ }
81
+ getLogs() {
82
+ return this.logs;
83
+ }
84
+ buildEditFacade() {
85
+ return {
86
+ insertClip: (input) => this.runNativeEdit((editor) => editor.insertClip(input)),
87
+ insertPlacedClip: (input) => this.runNativeEdit((editor) => editor.insertPlacedClip(input)),
88
+ updateClipMarker: (input) => this.runNativeEdit((editor) => editor.updateClipMarker(input)),
89
+ setClipPlacement: (input) => this.runNativeEdit((editor) => editor.setClipPlacement(input)),
90
+ moveSequentialClips: (input) => this.runNativeEdit((editor) => editor.moveSequentialClips(input)),
91
+ moveClip: (input) => this.runNativeEdit((editor) => editor.moveClip(input)),
92
+ replaceClipContent: (input) => this.runNativeEdit((editor) => editor.replaceClipContent(input)),
93
+ insertMediaClip: (input) => this.runNativeEdit((editor) => editor.insertMediaClip(input)),
94
+ insertMediaClips: (input) => this.runNativeEdit((editor) => editor.insertMediaClips(input)),
95
+ replaceMediaClip: (input) => this.runNativeEdit((editor) => editor.replaceMediaClip(input)),
96
+ setClipVolume: (input) => this.runNativeEdit((editor) => editor.setClipVolume(input)),
97
+ setClipSpeed: (input) => this.runNativeEdit((editor) => editor.setClipSpeed(input)),
98
+ trimClip: (input) => this.runNativeEdit((editor) => editor.trimClip(input)),
99
+ replaceSequentialClips: (input) => this.runNativeEdit((editor) => editor.replaceSequentialClips(input)),
100
+ deleteClip: (input) => this.runNativeEdit((editor) => editor.deleteClip(input)),
101
+ deleteClipTree: (input) => this.runNativeEdit((editor) => editor.deleteClipTree(input)),
102
+ updateClip: (input) => this.runNativeEdit((editor) => editor.updateClip(input)),
103
+ upsertVoiceoverTake: (input) => this.runNativeEdit((editor) => editor.upsertVoiceoverTake(input)),
104
+ moveVoiceover: (input) => this.runNativeEdit((editor) => editor.moveVoiceover(input)),
105
+ moveClipsToStarts: (input) => this.runNativeEdit((editor) => editor.moveClipsToStarts(input)),
106
+ deleteVoiceover: (input) => this.runNativeEdit((editor) => editor.deleteVoiceover(input)),
107
+ setBgm: (input) => this.runNativeEdit((editor) => editor.setBgm(input)),
108
+ deleteBgm: (input) => this.runNativeEdit((editor) => editor.deleteBgm(input)),
109
+ setCaptionVisibility: (input) => this.runNativeEdit((editor) => editor.setCaptionVisibility(input)),
110
+ patchCaptionStyle: (input) => this.runNativeEdit((editor) => editor.patchCaptionStyle(input))
111
+ };
112
+ }
113
+ runNativeEdit(mutate) {
114
+ const checkpoint = this.entitySandbox.commandCount;
115
+ try {
116
+ const before = this.entitySandbox.buildPlan().rows;
117
+ const editor = new EntityTimelineEditor(toDslRows(before), this.domainIdFactory);
118
+ const result = mutate(editor);
119
+ const expected = fromDslRows(editor.rows(), before.revision);
120
+ applyGraphDiff(this.entitySandbox, before, expected);
121
+ const applied = this.entitySandbox.buildPlan().rows;
122
+ if (!graphRowsEqual(applied, expected)) throw new Error("Entity timeline command diff did not reproduce the editor result");
123
+ return result;
124
+ } catch (error) {
125
+ this.entitySandbox.rollbackTo(checkpoint);
126
+ throw error;
127
+ }
128
+ }
129
+ snapshot() {
130
+ return {
131
+ revision: this.entityRevision,
132
+ entities: this.entitySandbox.entities.list(),
133
+ relations: this.entitySandbox.relations.list()
134
+ };
135
+ }
136
+ appendLog(line) {
137
+ if (this.logCapped) return;
138
+ if (this.logs.length >= LOG_LINE_CAP || this.logBytes >= LOG_BYTE_CAP) {
139
+ this.logs.push(LOG_TRUNCATED);
140
+ this.logCapped = true;
141
+ this.onLog?.(LOG_TRUNCATED);
142
+ return;
143
+ }
144
+ const out = line.length > LOG_LINE_MAX ? `${line.slice(0, LOG_LINE_MAX - 11)}${TRUNCATE_MARK}` : line;
145
+ this.logs.push(out);
146
+ this.logBytes += out.length;
147
+ this.onLog?.(out);
148
+ }
149
+ buildConsoleShim() {
150
+ const write = (...args) => this.appendLog(args.map(formatLogArg).join(" "));
151
+ return {
152
+ log: write,
153
+ info: write,
154
+ warn: write,
155
+ error: write
156
+ };
157
+ }
158
+ };
159
+ function applyGraphDiff(sandbox, before, after) {
160
+ const beforeEntities = new Map(before.entities.map((entity) => [entity.entity_id, entity]));
161
+ const afterEntities = new Map(after.entities.map((entity) => [entity.entity_id, entity]));
162
+ const beforeRelations = new Map(before.relations.map((relation) => [relation.relation_id, relation]));
163
+ const afterRelations = new Map(after.relations.map((relation) => [relation.relation_id, relation]));
164
+ for (const [entityId, previous] of beforeEntities) {
165
+ const next = afterEntities.get(entityId);
166
+ 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}"`);
167
+ }
168
+ for (const [relationId, previous] of beforeRelations) {
169
+ const next = afterRelations.get(relationId);
170
+ 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`);
171
+ }
172
+ const relationIdsToReplace = new Set([...beforeRelations].filter(([relationId, previous]) => {
173
+ const next = afterRelations.get(relationId);
174
+ return next != null && (!jsonEqual(previous.metadata, next.metadata) || !jsonEqual(previous.trace, next.trace));
175
+ }).map(([relationId]) => relationId));
176
+ const relationIdsToUnlink = [...beforeRelations.keys()].filter((relationId) => !afterRelations.has(relationId) || relationIdsToReplace.has(relationId)).sort();
177
+ for (const relationId of relationIdsToUnlink) sandbox.relations.unlink({ relation_id: relationId });
178
+ const entityIdsToDelete = [...beforeEntities.keys()].filter((entityId) => !afterEntities.has(entityId)).sort();
179
+ for (const entityId of entityIdsToDelete) sandbox.entities.delete({ entity_id: entityId });
180
+ const entitiesToCreate = [...afterEntities.values()].filter((entity) => !beforeEntities.has(entity.entity_id)).sort((left, right) => left.entity_id.localeCompare(right.entity_id));
181
+ for (const entity of entitiesToCreate) sandbox.entities.create(entity);
182
+ const entitiesToUpdate = [...afterEntities.values()].filter((entity) => {
183
+ const previous = beforeEntities.get(entity.entity_id);
184
+ return previous != null && !jsonEqual(previous.payload, entity.payload);
185
+ }).sort((left, right) => left.entity_id.localeCompare(right.entity_id));
186
+ for (const entity of entitiesToUpdate) sandbox.entities.update({
187
+ entity_id: entity.entity_id,
188
+ payload: entity.payload
189
+ });
190
+ 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));
191
+ for (const relation of relationsToLink) linkRelation(sandbox, relation);
192
+ }
193
+ function linkRelation(sandbox, relation) {
194
+ if (relation.relation_kind === "generated") {
195
+ sandbox.relations.linkGenerated({
196
+ relation_id: relation.relation_id,
197
+ output_entity_id: relation.endpoint_0_entity_id,
198
+ input_entity_id: relation.endpoint_1_entity_id,
199
+ trace: relation.trace
200
+ });
201
+ return;
202
+ }
203
+ if (relation.relation_kind === "clip-anchor") {
204
+ sandbox.relations.linkClipAnchor({
205
+ relation_id: relation.relation_id,
206
+ child_clip_entity_id: relation.endpoint_0_entity_id,
207
+ host_clip_entity_id: relation.endpoint_1_entity_id,
208
+ trace: relation.trace
209
+ });
210
+ return;
211
+ }
212
+ if (relation.relation_kind === "audio-script-render") {
213
+ sandbox.relations.linkAudioScriptRender({
214
+ relation_id: relation.relation_id,
215
+ output_entity_id: relation.endpoint_0_entity_id,
216
+ script_entity_id: relation.endpoint_1_entity_id,
217
+ trace: relation.trace
218
+ });
219
+ return;
220
+ }
221
+ sandbox.relations.link({
222
+ relation_id: relation.relation_id,
223
+ relation_kind: relation.relation_kind,
224
+ endpoint_0_entity_id: relation.endpoint_0_entity_id,
225
+ endpoint_1_entity_id: relation.endpoint_1_entity_id,
226
+ metadata: relation.metadata,
227
+ trace: relation.trace
228
+ });
229
+ }
230
+ function toDslRows(snapshot) {
231
+ return {
232
+ entities: snapshot.entities.map((entity) => ({
233
+ entityId: createEntityId(entity.entity_id),
234
+ entityKind: entity.entity_kind,
235
+ payload: structuredClone(entity.payload)
236
+ })),
237
+ relations: snapshot.relations.map((relation) => ({
238
+ relationId: createRelationId(relation.relation_id),
239
+ relationKind: relation.relation_kind,
240
+ endpoint0EntityId: createEntityId(relation.endpoint_0_entity_id),
241
+ endpoint1EntityId: createEntityId(relation.endpoint_1_entity_id),
242
+ metadata: structuredClone(relation.metadata),
243
+ trace: structuredClone(relation.trace)
244
+ }))
245
+ };
246
+ }
247
+ function fromDslRows(rows, revision) {
248
+ return {
249
+ revision,
250
+ entities: rows.entities.map((entity) => ({
251
+ entity_id: entity.entityId,
252
+ entity_kind: entity.entityKind,
253
+ payload: structuredClone(entity.payload)
254
+ })),
255
+ relations: rows.relations.map((relation) => ({
256
+ relation_id: relation.relationId,
257
+ relation_kind: relation.relationKind,
258
+ endpoint_0_entity_id: relation.endpoint0EntityId,
259
+ endpoint_1_entity_id: relation.endpoint1EntityId,
260
+ metadata: structuredClone(relation.metadata),
261
+ trace: structuredClone(relation.trace)
262
+ }))
263
+ };
264
+ }
265
+ function jsonEqual(left, right) {
266
+ if (Object.is(left, right)) return true;
267
+ 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]));
268
+ if (!isRecord(left) || !isRecord(right)) return false;
269
+ const leftKeys = Object.keys(left).sort();
270
+ const rightKeys = Object.keys(right).sort();
271
+ return leftKeys.length === rightKeys.length && leftKeys.every((key, index) => key === rightKeys[index] && jsonEqual(left[key], right[key]));
272
+ }
273
+ function graphRowsEqual(left, right) {
274
+ if (left.revision !== right.revision || left.entities.length !== right.entities.length || left.relations.length !== right.relations.length) return false;
275
+ const rightEntities = new Map(right.entities.map((entity) => [entity.entity_id, entity]));
276
+ const rightRelations = new Map(right.relations.map((relation) => [relation.relation_id, relation]));
277
+ return left.entities.every((entity) => jsonEqual(entity, rightEntities.get(entity.entity_id))) && left.relations.every((relation) => jsonEqual(relation, rightRelations.get(relation.relation_id)));
278
+ }
279
+ function isRecord(value) {
280
+ return value !== null && typeof value === "object" && !Array.isArray(value);
281
+ }
282
+ function formatLogArg(value) {
283
+ if (typeof value === "string") return value;
284
+ if (typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) return String(value);
285
+ try {
286
+ return JSON.stringify(value);
287
+ } catch {
288
+ return "[unstringifiable]";
289
+ }
290
+ }
291
+ //#endregion
4
292
  //#region src/sandbox/worker-entry.ts
5
293
  const data = workerData;
6
294
  if (parentPort == null) throw new Error("worker-entry must run inside a worker_threads Worker");
@@ -12,6 +300,10 @@ function countingFactory(label) {
12
300
  let n = 0;
13
301
  return (prefix) => `${prefix}_${label}${++n}`;
14
302
  }
303
+ function domainIdFactory(label) {
304
+ let n = 0;
305
+ return (prefix) => `${prefix}_${label == null ? randomUUID() : `${label}${++n}`}`;
306
+ }
15
307
  /** Extract script line/column from the first `agent-script.js` stack frame. */
16
308
  function positionFromError(error, script, phase) {
17
309
  const obj = error != null && typeof error === "object" ? error : null;
@@ -41,13 +333,18 @@ function positionFromError(error, script, phase) {
41
333
  };
42
334
  }
43
335
  async function main() {
44
- const idFactory = data.idLabel != null ? countingFactory(data.idLabel) : void 0;
45
- const session = new EditSandboxSession(data.document, {
46
- idFactory,
336
+ const options = {
337
+ idFactory: data.idLabel != null ? countingFactory(data.idLabel) : void 0,
338
+ entityState: data.entityState,
339
+ domainIdFactory: domainIdFactory(data.idLabel),
47
340
  onEntry: (entry) => post({
48
341
  t: "entry",
49
342
  entry
50
343
  }),
344
+ onEntityCommand: (command) => post({
345
+ t: "entity-entry",
346
+ command
347
+ }),
51
348
  onLog: (line) => post({
52
349
  t: "log",
53
350
  line
@@ -55,9 +352,14 @@ async function main() {
55
352
  onTruncate: (index) => post({
56
353
  t: "truncate",
57
354
  index
355
+ }),
356
+ onEntityTruncate: (index) => post({
357
+ t: "entity-truncate",
358
+ index
58
359
  })
59
- });
60
- const wrapped = `(async (edit, timeline, checkpoint, rollbackTo, inputs, console) => {${data.script}\n})`;
360
+ };
361
+ const session = data.entityOnly ? new EntityEditSandboxSession(data.document, options) : new EditSandboxSession(data.document, options);
362
+ const wrapped = `(async (edit, timeline, entities, relations, checkpoint, rollbackTo, inputs, console) => {${data.script}\n})`;
61
363
  const ctx = vm.createContext(Object.create(null));
62
364
  let run;
63
365
  try {
@@ -81,7 +383,7 @@ async function main() {
81
383
  try {
82
384
  const invoke = run;
83
385
  post({ t: "ready" });
84
- await invoke(session.edit, session.timeline, session.checkpoint, session.rollbackTo, data.inputs ?? {}, session.console);
386
+ await invoke(session.edit, session.timeline, session.entities, session.relations, session.checkpoint, session.rollbackTo, data.inputs ?? {}, session.console);
85
387
  } catch (error) {
86
388
  post({
87
389
  t: "fail",
@@ -94,7 +396,13 @@ async function main() {
94
396
  post({
95
397
  t: "done",
96
398
  preview: plan.preview,
97
- opsCount: plan.ops.length
399
+ opsCount: plan.ops.length,
400
+ entityCommandsCount: plan.entity_commands.length,
401
+ entityBaseRevision: plan.entity_base_revision,
402
+ ...plan.entity_rows !== void 0 ? { entityRows: plan.entity_rows } : {},
403
+ deletedEntityIds: plan.deleted_entity_ids ?? [],
404
+ deletedRelationIds: plan.deleted_relation_ids ?? [],
405
+ planKind: plan.plan_kind
98
406
  });
99
407
  }
100
408
  main().catch((error) => {
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.mjs","names":[],"sources":["../src/sandbox/worker-entry.ts"],"sourcesContent":["/// <reference types=\"node\" />\n\nimport vm from 'node:vm';\nimport { parentPort, workerData } from 'node:worker_threads';\n\nimport type { JournalEntry, PartIdFactory, VideoDocument } from '@mengine/medeo-client';\n\nimport { EditSandboxSession } from './script-session.ts';\n\n/**\n * Node worker entry for trusted edit scripts.\n *\n * Spawns an `EditSandboxSession`, runs the agent script in a bare `vm` context\n * (no fetch/process/setTimeout), and streams journal entries + logs to the host\n * 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 idLabel?: string;\n}\n\ntype HostMessage =\n | { t: 'ready' }\n | { t: 'entry'; entry: JournalEntry }\n | { t: 'log'; line: string }\n | { t: 'truncate'; index: number }\n | { t: 'done'; preview: string; opsCount: number }\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;\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\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 session = new EditSandboxSession(data.document, {\n idFactory,\n onEntry: (entry) => post({ t: 'entry', entry }),\n onLog: (line) => post({ t: 'log', line }),\n onTruncate: (index) => post({ t: 'truncate', index }),\n });\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, checkpoint, rollbackTo, inputs, console) => {${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: EditSandboxSession['edit'],\n timeline: EditSandboxSession['timeline'],\n checkpoint: EditSandboxSession['checkpoint'],\n rollbackTo: EditSandboxSession['rollbackTo'],\n inputs: Record<string, unknown>,\n console: EditSandboxSession['console'],\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.checkpoint,\n session.rollbackTo,\n data.inputs ?? {},\n session.console,\n );\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({ t: 'done', preview: plan.preview, opsCount: plan.ops.length });\n}\n\nmain().catch((error: unknown) => {\n const pos = positionFromError(error);\n post({ t: 'fail', phase: 'runtime', error: pos });\n});\n"],"mappings":";;;;AAoCA,MAAM,OAAO;AACb,IAAI,cAAc,MAChB,MAAM,IAAI,MAAM,sDAAsD;AAExE,MAAM,OAAO;AAEb,SAAS,KAAK,SAA4B;CACxC,KAAK,YAAY,OAAO;AAC1B;AAEA,SAAS,gBAAgB,OAA8B;CACrD,IAAI,IAAI;CACR,QAAQ,WAAW,GAAG,OAAO,GAAG,QAAQ,EAAE;AAC5C;;AAGA,SAAS,kBACP,OACA,QACA,OACqE;CAErE,MAAM,MAAM,SAAS,QAAQ,OAAO,UAAU,WAAY,QAAoC;CAC9F,MAAM,UACJ,OAAO,QAAQ,OAAO,IAAI,YAAY,WAClC,IAAI,UACJ,iBAAiB,QACf,MAAM,UACN,OAAO,KAAK;CACpB,MAAM,QAAQ,OAAO,QAAQ,OAAO,IAAI,UAAU,WAAW,IAAI,QAAQ,KAAA;CAEzE,IAAI,OAAO,OAAO,KAAK,eAAe,WAAW,IAAI,aAAa,KAAA;CAClE,IAAI,SAAS,OAAO,KAAK,iBAAiB,WAAW,IAAI,eAAe,KAAA;CAExE,IAAI,SAAS,MAAM;EAEj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,OACJ,QAAQ,MACR,QAAQ,UACR,QAAQ,YACR,QAAQ,YACR,KAAK,UAAU,CAAC,GAChB,QAAQ,OACV;CACF,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;EAAE,GAAG;EAAQ,SAAS,KAAK;EAAS,UAAU,KAAK,IAAI;CAAO,CAAC;AACtE;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/sandbox/entity-script-session.ts","../src/sandbox/worker-entry.ts"],"sourcesContent":["import {\n EntityTimelineEditor,\n assertCanonicalEditorResources,\n assertMediaAssetWritePolicy,\n type ClipEntityId,\n type DeleteBgmInput,\n type DeleteClipInput,\n type DeleteClipTreeInput,\n type DeleteVoiceoverInput,\n type InsertClipInput,\n type InsertMediaClipInput,\n type InsertMediaClipsInput,\n type InsertPlacedClipInput,\n type MoveClipInput,\n type MoveClipsToStartsInput,\n type MoveSequentialClipsInput,\n type MoveVoiceoverInput,\n type PatchCaptionStyleInput,\n type ReplaceMediaClipInput,\n type ReplaceSequentialClipsInput,\n type ReplaceClipContentInput,\n type SetBgmInput,\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 type VoiceoverTakeInput,\n type VoiceoverTakeResult,\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 type {\n CreateEntityInput,\n EntityFacade,\n EntityStoreSnapshot,\n LinkRelationInput,\n RelationFacade,\n SandboxEntity,\n SandboxRelation,\n} from '../entity/entity-contract.ts';\nimport { EntitySandbox, type DomainIdFactory } from '../entity/entity-sandbox.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 insertMediaClip(input: InsertMediaClipInput): ClipEntityId;\n insertMediaClips(input: InsertMediaClipsInput): readonly ClipEntityId[];\n replaceMediaClip(input: ReplaceMediaClipInput): void;\n setClipVolume(input: SetClipVolumeInput): void;\n setClipSpeed(input: SetClipSpeedInput): void;\n trimClip(input: TrimClipInput): void;\n replaceSequentialClips(input: ReplaceSequentialClipsInput): readonly ClipEntityId[];\n deleteClip(input: DeleteClipInput): void;\n deleteClipTree(input: DeleteClipTreeInput): void;\n updateClip(input: UpdateClipInput): void;\n upsertVoiceoverTake(input: VoiceoverTakeInput): VoiceoverTakeResult;\n moveVoiceover(input: MoveVoiceoverInput): void;\n moveClipsToStarts(input: MoveClipsToStartsInput): void;\n deleteVoiceover(input: DeleteVoiceoverInput): void;\n setBgm(input: SetBgmInput): ClipEntityId;\n deleteBgm(input: DeleteBgmInput): void;\n setCaptionVisibility(input: SetCaptionVisibilityInput): void;\n patchCaptionStyle(input: PatchCaptionStyleInput): void;\n}\n\nexport interface EntityTimelineFacade {\n /** Return the current graph draft, including uncommitted commands. */\n snapshot(): EntityStoreSnapshot;\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 logCapped = false;\n\n readonly edit: EntityEditFacade;\n readonly timeline: EntityTimelineFacade;\n readonly entities: EntityFacade;\n readonly relations: RelationFacade;\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(options?.entityState ?? { revision: 0, entities: [], relations: [] });\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 this.entities = this.entitySandbox.entities;\n this.relations = this.entitySandbox.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 buildPlan(baseVersion: string): ChangePlan {\n const entityPlan = this.entitySandbox.buildPlan();\n assertCanonicalEditorResources(toDslRows(entityPlan.rows));\n assertMediaAssetWritePolicy(this.baseRows, toDslRows(entityPlan.rows));\n return {\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 insertMediaClip: (input) => this.runNativeEdit((editor) => editor.insertMediaClip(input)),\n insertMediaClips: (input) => this.runNativeEdit((editor) => editor.insertMediaClips(input)),\n replaceMediaClip: (input) => this.runNativeEdit((editor) => editor.replaceMediaClip(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 replaceSequentialClips: (input) => this.runNativeEdit((editor) => editor.replaceSequentialClips(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 upsertVoiceoverTake: (input) => this.runNativeEdit((editor) => editor.upsertVoiceoverTake(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 setBgm: (input) => this.runNativeEdit((editor) => editor.setBgm(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 };\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);\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 {\n return {\n revision: this.entityRevision,\n entities: this.entitySandbox.entities.list(),\n relations: this.entitySandbox.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.entities.update({ 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 === 'audio-script-render') {\n sandbox.relations.linkAudioScriptRender({\n relation_id: relation.relation_id,\n output_entity_id: relation.endpoint_0_entity_id,\n script_entity_id: relation.endpoint_1_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(rows: EntityRelationRows, revision: number): EntityStoreSnapshot {\n return {\n revision,\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.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\" />\n\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 { 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: '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 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;\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) => {${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 ) => 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 );\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 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":";;;;;;AAqDA,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,eAAe,KAAK;AAC1B,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;;;;;;;;;AA4CtB,IAAa,2BAAb,MAAsC;CACpC;CACA;CACA;CACA;CACA;CACA,OAAkC,CAAC;CACnC;CACA,WAAmB;CACnB,YAAoB;CAEpB;CACA;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,UAAyB,SAAqC;EACxE,KAAK,WAAW,gBAAgB,QAAQ;EACxC,KAAK,iBAAiB,SAAS,aAAa,YAAY;EACxD,KAAK,WAAW,UAAU,SAAS,eAAe;GAAE,UAAU;GAAG,UAAU,CAAC;GAAG,WAAW,CAAC;EAAE,CAAC;EAC9F,KAAK,kBACH,SAAS,0BACF;GACL,MAAM,IAAI,MAAM,uDAAuD;EACzE;EACF,KAAK,QAAQ,SAAS;EACtB,KAAK,gBAAgB,IAAI,cAAc;GACrC,OAAO,SAAS;GAChB,WAAW,KAAK;GAChB,WAAW,SAAS;GACpB,YAAY,SAAS;EACvB,CAAC;EAED,KAAK,OAAO,KAAK,gBAAgB;EACjC,KAAK,WAAW,EAAE,gBAAgB,KAAK,SAAS,EAAE;EAClD,KAAK,WAAW,KAAK,cAAc;EACnC,KAAK,YAAY,KAAK,cAAc;EACpC,KAAK,UAAU,KAAK,iBAAiB;EACrC,KAAK,oBAAoB,EAAE,OAAO,KAAK,cAAc,aAAa;EAClE,KAAK,cAAc,OAAO,KAAK,cAAc,WAAW,GAAG,KAAK;CAClE;CAEA,UAAU,aAAiC;EACzC,MAAM,aAAa,KAAK,cAAc,UAAU;EAChD,+BAA+B,UAAU,WAAW,IAAI,CAAC;EACzD,4BAA4B,KAAK,UAAU,UAAU,WAAW,IAAI,CAAC;EACrE,OAAO;GACL,WAAW;GACX,Q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AwB,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.0.1-alpha.2",
3
+ "version": "1.2.1-alpha.10",
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.0.1-alpha.2"
27
+ "@mengine/medeo-client": "1.2.1-alpha.10"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^25.9.1",
@@ -32,7 +32,8 @@
32
32
  "loro-crdt": "^1.13.6",
33
33
  "tsx": "^4.22.3",
34
34
  "typescript": "^6.0.3",
35
- "vite-plus": "^0.1.23"
35
+ "vite-plus": "^0.1.23",
36
+ "@mengine/medeo-dsl": "0.0.0"
36
37
  },
37
38
  "scripts": {
38
39
  "build": "vp pack",