@statelyai/sdk 0.29.1 → 0.31.1

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.
Files changed (34) hide show
  1. package/README.md +15 -0
  2. package/dist/assetStorage.d.mts +1 -1
  3. package/dist/auth.d.mts +1 -1
  4. package/dist/{statelyPragma-p1vu8PmH.mjs → dist-wbhkeGh6.mjs} +468 -204
  5. package/dist/{editor-sync-types-DB1N6QUK.d.mts → editor-sync-types-CPpzTSnT.d.mts} +4 -0
  6. package/dist/{editorHostSession-vSt07IJV.d.mts → editorHostSession-Bo-YhDEG.d.mts} +105 -6
  7. package/dist/{editorHostSession-DNpXPNAc.mjs → editorHostSession-CT8y0yzG.mjs} +380 -20
  8. package/dist/editorHostSession.d.mts +2 -2
  9. package/dist/editorHostSession.mjs +3 -2
  10. package/dist/embed.d.mts +3 -4
  11. package/dist/embed.mjs +5 -2
  12. package/dist/{graph-C8E1Exad.d.mts → graph-CR_g-mOq.d.mts} +1 -1
  13. package/dist/graph.d.mts +1 -1
  14. package/dist/{index-D4pdeDpT.d.mts → index-DlOZxzrW.d.mts} +92 -2
  15. package/dist/index.d.mts +8 -9
  16. package/dist/index.mjs +6 -5
  17. package/dist/{inspect-D61HS-t7.d.mts → inspect-BoWXrB-V.d.mts} +3 -2
  18. package/dist/{inspect-dmCvrIl1.mjs → inspect-DoDj7iWa.mjs} +25 -1
  19. package/dist/inspect.d.mts +2 -2
  20. package/dist/inspect.mjs +2 -2
  21. package/dist/patchTypes.d.mts +1 -1
  22. package/dist/protocol-2cvzJtGN.d.mts +846 -0
  23. package/dist/protocol.d.mts +2 -821
  24. package/dist/relay.d.mts +1 -1
  25. package/dist/statelyPragma-D46lczJR.mjs +102 -0
  26. package/dist/{studio-D-yqFd0u.d.mts → studio-DV5IIGhV.d.mts} +2 -2
  27. package/dist/studio.d.mts +1 -1
  28. package/dist/sync.d.mts +2 -2
  29. package/dist/sync.mjs +411 -30
  30. package/dist/{version-DC3yW9Dk.mjs → version-B6OHpDiz.mjs} +1 -1
  31. package/package.json +3 -3
  32. package/schemas/statelyai.schema.json +6 -0
  33. package/dist/embedPanel-Bpbq4sfJ.d.mts +0 -13
  34. /package/dist/{auth-BPyCCHYo.d.mts → auth-Dg7prjeL.d.mts} +0 -0
@@ -1,5 +1,7 @@
1
1
  import { c as object, f as unknown, i as custom, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./openapi-BTDjYWXd.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
+ import { p as graphChangeToPatchesResult } from "./dist-wbhkeGh6.mjs";
4
+ import * as ts$1 from "typescript";
3
5
 
4
6
  //#region ../api-contract/dist/editor-sync.mjs
5
7
  const EDITOR_SYNC_PROTOCOL_VERSION = 1;
@@ -80,20 +82,22 @@ const editorSyncDocumentContextSchema = object({
80
82
  rootDir: string(),
81
83
  documents: array(editorSyncSourceDocumentSchema)
82
84
  });
85
+ const editorSyncParseRequestSchema = editorSyncDocumentContextSchema.extend({ machineIndex: number().int().nonnegative().optional() });
83
86
  const editorSyncParseResponseSchema = object({
84
87
  machine: unknown(),
85
88
  format: string(),
86
89
  sourceLocations: machineSourceLocationsSchema.optional(),
87
90
  access: editorSyncAccessSchema.optional()
88
91
  }).passthrough();
89
- const editorSyncApplyRequestSchema = editorSyncDocumentContextSchema.extend({
92
+ const editorSyncApplyRequestSchema = editorSyncParseRequestSchema.extend({
90
93
  machineConfig: unknown().optional(),
91
94
  patches: array(unknown()).optional(),
92
95
  prevGraph: unknown().optional(),
93
96
  nextGraph: unknown().optional(),
94
97
  sourceLocations: machineSourceLocationsSchema.optional(),
95
98
  serialized: record(string(), string()).optional(),
96
- preserveStatelyMetadata: boolean().optional()
99
+ preserveStatelyMetadata: boolean().optional(),
100
+ sourceUpdateStrategy: _enum(["preserve", "rewrite"]).optional()
97
101
  }).passthrough();
98
102
  const editorSyncTextReplacementSchema = object({
99
103
  uri: string().optional(),
@@ -185,27 +189,27 @@ var EditorHostSession = class {
185
189
  currentSourceLocations;
186
190
  access;
187
191
  watchedSourceUris = /* @__PURE__ */ new Set();
188
- selfEditCount = 0;
189
- saveReminderShown = false;
190
192
  watcher;
191
193
  changeWatcher;
192
194
  retrieveRequestCount = 0;
193
195
  pendingRetrievals = /* @__PURE__ */ new Map();
194
- constructor(options) {
196
+ constructor(options, saveReminderState = { shown: false }, selfEditState = { count: 0 }) {
195
197
  this.options = options;
198
+ this.saveReminderState = saveReminderState;
199
+ this.selfEditState = selfEditState;
196
200
  this.watcher = options.source.watchSavedDocuments?.((uri) => {
197
- this.saveReminderShown = false;
201
+ this.saveReminderState.shown = false;
198
202
  return this.handleSavedDocument(uri);
199
203
  });
200
204
  this.changeWatcher = options.source.watchChangedDocuments?.((uri) => {
201
205
  if (uri !== this.options.source.rootUri && !this.watchedSourceUris.has(uri)) return;
202
- if (this.selfEditCount > 0) return;
203
- if (this.saveReminderShown) return;
204
- this.saveReminderShown = true;
206
+ if (this.selfEditState.count > 0) return;
207
+ if (this.saveReminderState.shown) return;
208
+ this.saveReminderState.shown = true;
205
209
  this.options.send({
206
210
  type: "@statelyai.toast",
207
211
  message: "Save code to see changes.",
208
- toastType: "info"
212
+ toastType: "warning"
209
213
  });
210
214
  });
211
215
  }
@@ -264,7 +268,11 @@ var EditorHostSession = class {
264
268
  await this.save(message);
265
269
  } catch (error) {
266
270
  const text = formatError(error, "Failed to apply Viz changes.");
267
- this.reportSourceSyncError(text, "save", { errorName: error instanceof Error ? error.name : void 0 }, message.requestId);
271
+ this.reportSourceSyncError(text, "save", {
272
+ errorName: error instanceof Error ? error.name : void 0,
273
+ sourceUpdateStrategy: message.sourceUpdateStrategy ?? this.options.sourceUpdateStrategy ?? "preserve",
274
+ canRewrite: (message.sourceUpdateStrategy ?? this.options.sourceUpdateStrategy ?? "preserve") === "preserve"
275
+ }, message.requestId);
268
276
  }
269
277
  break;
270
278
  case "@statelyai.refresh":
@@ -317,6 +325,7 @@ var EditorHostSession = class {
317
325
  rootUri: this.options.source.rootUri,
318
326
  rootFileName: this.options.source.rootFileName,
319
327
  rootDir: this.options.source.rootDir,
328
+ ...this.options.source.machineIndex !== void 0 ? { machineIndex: this.options.source.machineIndex } : {},
320
329
  documents
321
330
  });
322
331
  this.currentFormat = update.format;
@@ -372,7 +381,22 @@ var EditorHostSession = class {
372
381
  return;
373
382
  }
374
383
  const previousGraph = this.lastPersistedGraph ?? this.currentGraph;
375
- if (!message.patches?.length && graphsEqual(previousGraph, message.graph)) {
384
+ let patches = message.patches;
385
+ if (!patches?.length && previousGraph !== void 0) try {
386
+ const semanticChange = graphChangeToPatchesResult(previousGraph, message.graph);
387
+ if (semanticChange.patches.length === 0 && semanticChange.unsupportedChanges.length === 0) {
388
+ this.currentGraph = message.graph;
389
+ this.lastPersistedGraph = message.graph;
390
+ this.options.send({
391
+ type: "@statelyai.saved",
392
+ ...message.requestId ? { requestId: message.requestId } : {},
393
+ graph: message.graph
394
+ });
395
+ return;
396
+ }
397
+ patches = semanticChange.patches;
398
+ } catch {}
399
+ if (!patches?.length && graphsEqual(previousGraph, message.graph)) {
376
400
  this.currentGraph = message.graph;
377
401
  this.lastPersistedGraph = message.graph;
378
402
  this.options.send({
@@ -384,34 +408,40 @@ var EditorHostSession = class {
384
408
  }
385
409
  const documents = await this.options.source.collectDocuments(sourceLocationUris(this.currentSourceLocations));
386
410
  const serialized = await this.getSerializedPayload();
411
+ const sourceUpdateStrategy = message.sourceUpdateStrategy ?? this.options.sourceUpdateStrategy ?? "preserve";
387
412
  const response = await this.options.sync.apply({
388
413
  rootUri: this.options.source.rootUri,
389
414
  rootFileName: this.options.source.rootFileName,
390
415
  rootDir: this.options.source.rootDir,
416
+ ...this.options.source.machineIndex !== void 0 ? { machineIndex: this.options.source.machineIndex } : {},
391
417
  documents,
392
418
  machineConfig: message.machineConfig,
393
- patches: message.patches,
419
+ patches,
394
420
  prevGraph: previousGraph,
395
421
  nextGraph: message.graph,
396
422
  sourceLocations: this.currentSourceLocations,
397
423
  serialized,
398
- preserveStatelyMetadata: this.options.source.getPreserveStatelyMetadata?.(this.options.source.rootUri) ?? true
424
+ preserveStatelyMetadata: this.options.source.getPreserveStatelyMetadata?.(this.options.source.rootUri) ?? true,
425
+ sourceUpdateStrategy
399
426
  });
427
+ assertSyntacticallyValidSourceUpdates(documents, response.replacements, this.options.source.rootUri);
400
428
  if (response.replacements.length === 0) {
401
429
  this.reportSourceSyncError("Could not write visual changes to the source file. Your visual edits are still unsaved.", "save", {
402
430
  reason: "no_replacements",
403
- patchCount: message.patches?.length ?? 0,
431
+ patchCount: patches?.length ?? 0,
404
432
  profile: this.currentSourceLocations?.profileRef ?? this.currentSourceLocations?.profile,
405
- sourceFile: this.options.source.rootFileName.split(/[\\/]/).pop()
433
+ sourceFile: this.options.source.rootFileName.split(/[\\/]/).pop(),
434
+ sourceUpdateStrategy,
435
+ canRewrite: sourceUpdateStrategy === "preserve"
406
436
  }, message.requestId);
407
437
  return;
408
438
  }
409
- this.selfEditCount++;
439
+ this.selfEditState.count++;
410
440
  try {
411
441
  const touchedUris = await this.options.source.applyReplacements(response.replacements, this.options.source.rootUri);
412
442
  await this.options.source.saveDocuments?.(touchedUris);
413
443
  } finally {
414
- this.selfEditCount--;
444
+ this.selfEditState.count--;
415
445
  }
416
446
  this.currentGraph = message.graph;
417
447
  this.lastPersistedGraph = message.graph;
@@ -423,13 +453,14 @@ var EditorHostSession = class {
423
453
  }
424
454
  async handleSavedDocument(uri) {
425
455
  if (this.editorProtocolState !== "compatible") return;
426
- if (uri !== this.options.source.rootUri && !this.watchedSourceUris.has(uri) || this.selfEditCount > 0) return;
456
+ if (uri !== this.options.source.rootUri && !this.watchedSourceUris.has(uri) || this.selfEditState.count > 0) return;
427
457
  try {
428
458
  const documents = await this.options.source.collectDocuments(sourceLocationUris(this.currentSourceLocations));
429
459
  const update = await this.options.sync.parse({
430
460
  rootUri: this.options.source.rootUri,
431
461
  rootFileName: this.options.source.rootFileName,
432
462
  rootDir: this.options.source.rootDir,
463
+ ...this.options.source.machineIndex !== void 0 ? { machineIndex: this.options.source.machineIndex } : {},
433
464
  documents
434
465
  });
435
466
  this.currentFormat = update.format;
@@ -503,6 +534,335 @@ var EditorHostSession = class {
503
534
  pending.resolve(typeof data === "string" ? data : JSON.stringify(data, null, 2));
504
535
  }
505
536
  };
537
+ /**
538
+ * Runs one source-sync session per discovered machine while presenting the
539
+ * editor's project/workspace protocol as a single surface.
540
+ */
541
+ var EditorHostWorkspaceSession = class {
542
+ children = /* @__PURE__ */ new Map();
543
+ machineDefinitions = /* @__PURE__ */ new Map();
544
+ initialMessages = /* @__PURE__ */ new Map();
545
+ selectedMachineId;
546
+ sentHandshake = false;
547
+ sentApiKey = false;
548
+ initialized = false;
549
+ projectWorkspaceOpen;
550
+ retrieveRequestCount = 0;
551
+ pendingRetrievals = /* @__PURE__ */ new Map();
552
+ saveReminderStates = /* @__PURE__ */ new Map();
553
+ selfEditStates = /* @__PURE__ */ new Map();
554
+ constructor(options) {
555
+ this.options = options;
556
+ if (options.machines.length === 0) throw new Error("A visual editor workspace needs at least one machine.");
557
+ this.selectedMachineId = options.currentMachineId && options.machines.some((machine) => machine.id === options.currentMachineId) ? options.currentMachineId : options.machines[0].id;
558
+ this.projectWorkspaceOpen = options.projectWorkspaceOpen ?? false;
559
+ for (const machine of options.machines) {
560
+ const saveReminderState = this.saveReminderStates.get(machine.source.rootUri) ?? { shown: false };
561
+ this.saveReminderStates.set(machine.source.rootUri, saveReminderState);
562
+ const selfEditState = this.selfEditStates.get(machine.source.rootUri) ?? { count: 0 };
563
+ this.selfEditStates.set(machine.source.rootUri, selfEditState);
564
+ this.children.set(machine.id, new EditorHostSession({
565
+ ...options,
566
+ source: machine.source,
567
+ send: (message) => this.handleChildMessage(machine, message)
568
+ }, saveReminderState, selfEditState));
569
+ }
570
+ }
571
+ async receive(message) {
572
+ if (message.type === "@statelyai.ready") {
573
+ await Promise.all([...this.children.values()].map((session) => session.receive(message)));
574
+ this.flushProjectInit();
575
+ return;
576
+ }
577
+ if (message.type === "@statelyai.project.machineSelected") {
578
+ if (this.children.has(message.machineId)) this.selectedMachineId = message.machineId;
579
+ return;
580
+ }
581
+ if (message.type === "@statelyai.project.workspaceOpenChanged") {
582
+ this.projectWorkspaceOpen = message.open;
583
+ return;
584
+ }
585
+ if (message.type === "@statelyai.project.workspaceAction") return;
586
+ if ((message.type === "@statelyai.retrieved" || message.type === "@statelyai.error") && message.requestId) {
587
+ const pending = this.pendingRetrievals.get(message.requestId);
588
+ if (pending) {
589
+ this.pendingRetrievals.delete(message.requestId);
590
+ await this.children.get(pending.machineId)?.receive({
591
+ ...message,
592
+ requestId: pending.childRequestId,
593
+ machineId: pending.machineId
594
+ });
595
+ return;
596
+ }
597
+ }
598
+ const routedMessage = message.type === "@statelyai.save" ? normalizeWorkspaceSaveMessage(message, this.options.machines) : message;
599
+ const machineId = ("machineId" in routedMessage ? routedMessage.machineId : void 0) ?? this.selectedMachineId;
600
+ const child = this.children.get(machineId);
601
+ if (child) await child.receive(routedMessage);
602
+ }
603
+ selectMachine(machineId) {
604
+ if (!this.children.has(machineId)) return;
605
+ this.selectedMachineId = machineId;
606
+ this.options.send({
607
+ type: "@statelyai.project.selectMachine",
608
+ machineId
609
+ });
610
+ }
611
+ dispose() {
612
+ for (const child of this.children.values()) child.dispose();
613
+ this.children.clear();
614
+ this.pendingRetrievals.clear();
615
+ }
616
+ handleChildMessage(machine, message) {
617
+ switch (message.type) {
618
+ case "@statelyai.init":
619
+ this.initialMessages.set(machine.id, message);
620
+ this.machineDefinitions.set(machine.id, {
621
+ id: machine.id,
622
+ name: machine.name,
623
+ sourceReference: machine.sourceReference,
624
+ sourceUri: machine.source.rootUri,
625
+ machine: message.machine,
626
+ format: message.format,
627
+ sourceLocations: message.sourceLocations
628
+ });
629
+ if (this.initialMessages.size === this.children.size) this.flushProjectInit();
630
+ return;
631
+ case "@statelyai.update": {
632
+ const previous = this.machineDefinitions.get(machine.id);
633
+ this.machineDefinitions.set(machine.id, {
634
+ id: machine.id,
635
+ name: machine.name,
636
+ sourceReference: machine.sourceReference,
637
+ sourceUri: machine.source.rootUri,
638
+ machine: message.machine,
639
+ format: message.format,
640
+ sourceLocations: message.sourceLocations,
641
+ ...previous?.projectId ? { projectId: previous.projectId } : {}
642
+ });
643
+ if (this.initialized) this.options.send({
644
+ type: "@statelyai.project.update",
645
+ machines: this.getProjectMachines(),
646
+ currentMachineId: this.selectedMachineId,
647
+ projectWorkspace: this.getProjectWorkspace(),
648
+ projectWorkspaceOpen: this.projectWorkspaceOpen
649
+ });
650
+ return;
651
+ }
652
+ case "@statelyai.handshake":
653
+ if (this.sentHandshake) return;
654
+ this.sentHandshake = true;
655
+ this.options.send(message);
656
+ return;
657
+ case "@statelyai.setApiKey":
658
+ if (this.sentApiKey) return;
659
+ this.sentApiKey = true;
660
+ this.options.send(message);
661
+ return;
662
+ case "@statelyai.retrieve": {
663
+ const requestId = `workspace-retrieve-${++this.retrieveRequestCount}`;
664
+ this.pendingRetrievals.set(requestId, {
665
+ machineId: machine.id,
666
+ childRequestId: message.requestId
667
+ });
668
+ this.options.send({
669
+ ...message,
670
+ requestId,
671
+ machineId: machine.id
672
+ });
673
+ return;
674
+ }
675
+ case "@statelyai.saved":
676
+ case "@statelyai.toast":
677
+ case "@statelyai.error":
678
+ this.options.send({
679
+ ...message,
680
+ machineId: machine.id
681
+ });
682
+ return;
683
+ default: this.options.send(message);
684
+ }
685
+ }
686
+ flushProjectInit() {
687
+ if (this.initialized || this.initialMessages.size === 0) return;
688
+ const first = this.initialMessages.values().next().value;
689
+ if (!first) return;
690
+ if (!this.machineDefinitions.has(this.selectedMachineId)) {
691
+ const firstAvailableMachineId = this.machineDefinitions.keys().next().value;
692
+ if (!firstAvailableMachineId) return;
693
+ this.selectedMachineId = firstAvailableMachineId;
694
+ }
695
+ this.initialized = true;
696
+ this.options.send({
697
+ type: "@statelyai.project.init",
698
+ machines: this.getProjectMachines(),
699
+ currentMachineId: this.selectedMachineId,
700
+ mode: first.mode,
701
+ theme: first.theme,
702
+ readOnly: first.readOnly,
703
+ readOnlyReason: first.readOnlyReason,
704
+ capabilities: first.capabilities,
705
+ settings: first.settings,
706
+ panels: first.panels,
707
+ unsavedIndicator: first.unsavedIndicator,
708
+ projectWorkspace: this.getProjectWorkspace(),
709
+ projectWorkspaceOpen: this.projectWorkspaceOpen
710
+ });
711
+ }
712
+ getProjectMachines() {
713
+ return this.options.machines.flatMap((machine) => {
714
+ const definition = this.machineDefinitions.get(machine.id);
715
+ return definition ? [definition] : [];
716
+ });
717
+ }
718
+ getProjectWorkspace() {
719
+ return { project: {
720
+ id: "source-workspace",
721
+ name: this.options.workspaceName ?? "Source workspace",
722
+ machines: this.options.machines.flatMap((machine) => this.machineDefinitions.has(machine.id) ? [{
723
+ id: machine.id,
724
+ name: machine.name
725
+ }] : [])
726
+ } };
727
+ }
728
+ };
729
+ function normalizeWorkspaceSaveMessage(message, machines) {
730
+ const sourceReferences = new Map(machines.flatMap((machine) => machine.sourceReference ? [[machine.id, machine.sourceReference]] : []));
731
+ if (sourceReferences.size === 0) return message;
732
+ try {
733
+ const usedReferences = /* @__PURE__ */ new Set();
734
+ const graph = structuredClone(message.graph);
735
+ const machineConfig = structuredClone(message.machineConfig);
736
+ normalizeInvokeSources(graph, sourceReferences, usedReferences);
737
+ normalizeInvokeSources(machineConfig, sourceReferences, usedReferences);
738
+ if (usedReferences.size === 0) return message;
739
+ addWorkspaceActorImplementations(graph, usedReferences);
740
+ const patches = message.patches ? structuredClone(message.patches) : void 0;
741
+ if (patches) {
742
+ normalizeInvokeSources(patches, sourceReferences, usedReferences);
743
+ for (const sourceReference of usedReferences) {
744
+ if (patches.some((patch) => isRecord(patch) && patch.op === "createImplementation" && patch.sourceType === "actor" && isRecord(patch.implementation) && patch.implementation.id === sourceReference)) continue;
745
+ patches.push({
746
+ op: "createImplementation",
747
+ sourceType: "actor",
748
+ implementation: {
749
+ id: sourceReference,
750
+ name: sourceReference,
751
+ code: sourceReference
752
+ }
753
+ });
754
+ }
755
+ }
756
+ return {
757
+ ...message,
758
+ graph,
759
+ machineConfig,
760
+ ...patches ? { patches } : {}
761
+ };
762
+ } catch {
763
+ return message;
764
+ }
765
+ }
766
+ function normalizeInvokeSources(value, sourceReferences, usedReferences) {
767
+ if (Array.isArray(value)) {
768
+ for (const item of value) normalizeInvokeSources(item, sourceReferences, usedReferences);
769
+ return;
770
+ }
771
+ if (!isRecord(value)) return;
772
+ if (typeof value.src === "string") {
773
+ const sourceReference = sourceReferences.get(value.src);
774
+ if (sourceReference) {
775
+ value.src = sourceReference;
776
+ usedReferences.add(sourceReference);
777
+ }
778
+ }
779
+ for (const child of Object.values(value)) normalizeInvokeSources(child, sourceReferences, usedReferences);
780
+ }
781
+ function addWorkspaceActorImplementations(graph, sourceReferences) {
782
+ if (!isRecord(graph) || !isRecord(graph.data)) return;
783
+ if (!isRecord(graph.data.implementations)) graph.data.implementations = {};
784
+ const implementations = graph.data.implementations;
785
+ if (!isRecord(implementations)) return;
786
+ const actors = Array.isArray(implementations.actors) ? implementations.actors : implementations.actors = [];
787
+ for (const sourceReference of sourceReferences) {
788
+ if (actors.some((actor) => isRecord(actor) && actor.id === sourceReference)) continue;
789
+ actors.push({
790
+ id: sourceReference,
791
+ name: sourceReference,
792
+ description: null,
793
+ inputSchema: null,
794
+ outputSchema: null,
795
+ code: {
796
+ body: sourceReference,
797
+ lang: "ts",
798
+ deps: {}
799
+ }
800
+ });
801
+ }
802
+ }
803
+ function isRecord(value) {
804
+ return typeof value === "object" && value !== null && !Array.isArray(value);
805
+ }
806
+ function assertSyntacticallyValidSourceUpdates(documents, replacements, rootUri) {
807
+ const documentsByIdentifier = /* @__PURE__ */ new Map();
808
+ for (const document of documents) {
809
+ documentsByIdentifier.set(document.uri, document);
810
+ documentsByIdentifier.set(document.fileName, document);
811
+ }
812
+ const replacementsByUri = /* @__PURE__ */ new Map();
813
+ for (const replacement of replacements) {
814
+ const uri = replacement.uri ?? rootUri;
815
+ const current = replacementsByUri.get(uri) ?? [];
816
+ current.push(replacement);
817
+ replacementsByUri.set(uri, current);
818
+ }
819
+ for (const [uri, documentReplacements] of replacementsByUri) {
820
+ const document = documentsByIdentifier.get(uri);
821
+ if (!document || !/\.[cm]?[jt]sx?$/i.test(document.fileName)) continue;
822
+ const candidate = applySourceReplacements(document.text, documentReplacements);
823
+ const diagnostics = getIntroducedSyntacticDiagnostics(document.fileName, document.text, candidate);
824
+ if (diagnostics.length) {
825
+ const detail = ts$1.flattenDiagnosticMessageText(diagnostics[0].messageText, "\n");
826
+ throw new Error(`Stately refused to write invalid source to ${document.fileName}: ${detail}`);
827
+ }
828
+ }
829
+ }
830
+ function getIntroducedSyntacticDiagnostics(fileName, original, candidate) {
831
+ const getDiagnostics = (text) => ts$1.transpileModule(text, {
832
+ fileName,
833
+ reportDiagnostics: true,
834
+ compilerOptions: {
835
+ allowJs: true,
836
+ jsx: ts$1.JsxEmit.Preserve,
837
+ target: ts$1.ScriptTarget.Latest
838
+ }
839
+ }).diagnostics ?? [];
840
+ const originalCounts = /* @__PURE__ */ new Map();
841
+ for (const diagnostic of getDiagnostics(original)) {
842
+ const key = diagnosticKey(diagnostic);
843
+ originalCounts.set(key, (originalCounts.get(key) ?? 0) + 1);
844
+ }
845
+ return getDiagnostics(candidate).filter((diagnostic) => {
846
+ const key = diagnosticKey(diagnostic);
847
+ const remaining = originalCounts.get(key) ?? 0;
848
+ if (remaining === 0) return true;
849
+ originalCounts.set(key, remaining - 1);
850
+ return false;
851
+ });
852
+ }
853
+ function diagnosticKey(diagnostic) {
854
+ return `${diagnostic.code}:${ts$1.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}`;
855
+ }
856
+ function applySourceReplacements(source, replacements) {
857
+ const lineStarts = [0];
858
+ for (let index = 0; index < source.length; index++) if (source.charCodeAt(index) === 10) lineStarts.push(index + 1);
859
+ const offsetAt = (line, character) => (lineStarts[Math.min(Math.max(line, 0), lineStarts.length - 1)] ?? 0) + character;
860
+ return [...replacements].sort((left, right) => offsetAt(right.range.startLine, right.range.startChar) - offsetAt(left.range.startLine, left.range.startChar)).reduce((text, replacement) => {
861
+ const start = offsetAt(replacement.range.startLine, replacement.range.startChar);
862
+ const end = offsetAt(replacement.range.endLine, replacement.range.endChar);
863
+ return `${text.slice(0, start)}${replacement.newText}${text.slice(end)}`;
864
+ }, source);
865
+ }
506
866
  function graphsEqual(left, right) {
507
867
  if (left === void 0 || right === void 0) return false;
508
868
  try {
@@ -540,4 +900,4 @@ function stateSourceLocationUris(sourceLocations) {
540
900
  }
541
901
 
542
902
  //#endregion
543
- export { fetchEditorSyncAccess as i, EditorSyncError as n, createRemoteEditorSyncBackend as r, EditorHostSession as t };
903
+ export { fetchEditorSyncAccess as a, createRemoteEditorSyncBackend as i, EditorHostWorkspaceSession as n, EditorSyncError as r, EditorHostSession as t };
@@ -1,2 +1,2 @@
1
- import { a as EditorSyncError, c as fetchEditorSyncAccess, d as EditorHostExportFormat, f as EditorHostInboundMessage, h as EditorHostValidationIssue, i as EditorSyncBackend, l as EDITOR_PROTOCOL_VERSION, m as EditorHostOutboundMessage, n as EditorHostSessionOptions, o as RemoteEditorSyncBackendOptions, p as EditorHostInitOptions, r as EditorSourceHost, s as createRemoteEditorSyncBackend, t as EditorHostSession, u as EditorHostDiagnostic } from "./editorHostSession-vSt07IJV.mjs";
2
- export { EDITOR_PROTOCOL_VERSION, EditorHostDiagnostic, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorSourceHost, EditorSyncBackend, EditorSyncError, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
1
+ import { _ as EditorHostOutboundMessage, a as EditorHostWorkspaceSessionOptions, c as EditorSyncError, d as fetchEditorSyncAccess, f as EDITOR_PROTOCOL_VERSION, g as EditorHostInitOptions, h as EditorHostInboundMessage, i as EditorHostWorkspaceSession, l as RemoteEditorSyncBackendOptions, m as EditorHostExportFormat, n as EditorHostSessionOptions, o as EditorSourceHost, p as EditorHostDiagnostic, r as EditorHostWorkspaceMachine, s as EditorSyncBackend, t as EditorHostSession, u as createRemoteEditorSyncBackend, v as EditorHostValidationIssue } from "./editorHostSession-Bo-YhDEG.mjs";
2
+ export { EDITOR_PROTOCOL_VERSION, EditorHostDiagnostic, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorHostWorkspaceMachine, EditorHostWorkspaceSession, EditorHostWorkspaceSessionOptions, EditorSourceHost, EditorSyncBackend, EditorSyncError, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
@@ -1,5 +1,6 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
- import { i as fetchEditorSyncAccess, n as EditorSyncError, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-DNpXPNAc.mjs";
3
+ import { a as fetchEditorSyncAccess, i as createRemoteEditorSyncBackend, n as EditorHostWorkspaceSession, r as EditorSyncError, t as EditorHostSession } from "./editorHostSession-CT8y0yzG.mjs";
4
+ import "./dist-wbhkeGh6.mjs";
4
5
 
5
- export { EDITOR_PROTOCOL_VERSION, EditorHostSession, EditorSyncError, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
6
+ export { EDITOR_PROTOCOL_VERSION, EditorHostSession, EditorHostWorkspaceSession, EditorSyncError, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
package/dist/embed.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- import { i as ProfileManifest } from "./index-D4pdeDpT.mjs";
2
- import { i as StatelyGraph } from "./graph-C8E1Exad.mjs";
3
- import { n as EmbedPanelPosition, t as EmbedPanelConfig } from "./embedPanel-Bpbq4sfJ.mjs";
4
- import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedExtensionsManifest, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, MachineVersionAutoSaveOptions, ProjectEmbedMachine, ProjectWorkspaceAction, ProjectWorkspaceActionIcon, ProjectWorkspaceCapabilities, ProjectWorkspaceConfig, ProjectWorkspaceMachine, ProjectWorkspaceMachineOrigin, ProjectWorkspaceProject, UploadResult } from "./protocol.mjs";
1
+ import { i as ProfileManifest } from "./index-DlOZxzrW.mjs";
2
+ import { i as StatelyGraph } from "./graph-CR_g-mOq.mjs";
3
+ import { Bt as UploadResult, D as ExportCallOptions, F as InitOptions, G as MachineVersionAutoSaveOptions, O as ExportFormat, Qt as EmbedPanelPosition, S as EmbedExtensionsManifest, U as MachineInitOptions, W as MachineSourceLocations, Y as ProjectEmbedMachine, Zt as EmbedPanelConfig, _ as EmbedDocumentLanguage, at as ProjectWorkspaceCapabilities, b as EmbedEventName, ct as ProjectWorkspaceMachineOrigin, d as CommentsConfig, g as EmbedDocument, k as ExportFormatMap, m as EditorCapabilities, nt as ProjectWorkspaceAction, ot as ProjectWorkspaceConfig, r as CapabilityDeniedEvent, rt as ProjectWorkspaceActionIcon, st as ProjectWorkspaceMachine, ut as ProjectWorkspaceProject, v as EmbedEventHandler, w as EmbedMode, y as EmbedEventMap } from "./protocol-2cvzJtGN.mjs";
5
4
  import { AssetUploadAdapter } from "./assetStorage.mjs";
6
5
 
7
6
  //#region src/embed.d.ts
package/dist/embed.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-DC3yW9Dk.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-B6OHpDiz.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
3
 
4
4
  //#region src/embed.ts
@@ -44,6 +44,8 @@ function serializeExtensions(options) {
44
44
  description: profile.description,
45
45
  namespace: profile.namespace,
46
46
  extends: profile.extends,
47
+ lineage: profile.lineage,
48
+ selectable: profile.selectable,
47
49
  formats: profile.formats,
48
50
  defaultFormat: profile.defaultFormat,
49
51
  graph: profile.graph,
@@ -290,7 +292,8 @@ function createStatelyEmbed(options) {
290
292
  machineId: save.machineId,
291
293
  patches: save.patches,
292
294
  validations: save.validations,
293
- sourceLocations: save.sourceLocations
295
+ sourceLocations: save.sourceLocations,
296
+ sourceUpdateStrategy: save.sourceUpdateStrategy
294
297
  });
295
298
  break;
296
299
  }
@@ -1,4 +1,4 @@
1
- import { t as CodeExpression } from "./index-D4pdeDpT.mjs";
1
+ import { t as CodeExpression } from "./index-DlOZxzrW.mjs";
2
2
  import * as _statelyai_graph0 from "@statelyai/graph";
3
3
  import { Graph } from "@statelyai/graph";
4
4
 
package/dist/graph.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-C8E1Exad.mjs";
1
+ import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-CR_g-mOq.mjs";
2
2
  export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };