@statelyai/sdk 0.17.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +38 -2
  2. package/dist/auth.d.mts +1 -1
  3. package/dist/editor-sync-types-D8_EZm0A.d.mts +94 -0
  4. package/dist/editorHostProtocol-D_h4y3rX.mjs +5 -0
  5. package/dist/editorHostSession-CZHd22pZ.mjs +478 -0
  6. package/dist/editorHostSession-jnC5mQDN.d.mts +184 -0
  7. package/dist/editorHostSession.d.mts +2 -0
  8. package/dist/editorHostSession.mjs +4 -0
  9. package/dist/embed.d.mts +3 -3
  10. package/dist/embed.mjs +33 -3
  11. package/dist/{graph-DuOeLGvh.d.mts → graph-DxeqWHC3.d.mts} +1 -1
  12. package/dist/graph.d.mts +1 -1
  13. package/dist/index.d.mts +8 -7
  14. package/dist/index.mjs +8 -6
  15. package/dist/{inspect-BZFzyeew.d.mts → inspect-CGJR4iZK.d.mts} +13 -3
  16. package/dist/{inspect-CF_6aEnv.mjs → inspect-CWwLGwLq.mjs} +58 -31
  17. package/dist/inspect.d.mts +1 -1
  18. package/dist/inspect.mjs +2 -1
  19. package/dist/patchTypes.d.mts +1 -1
  20. package/dist/protocol.d.mts +66 -50
  21. package/dist/protocol.mjs +17 -3
  22. package/dist/{studio-txdyJHD7.mjs → schemas-C2raUv-n.mjs} +1 -396
  23. package/dist/{statelyPragma-Th0gdXfx.mjs → statelyPragma-GN-bfuC_.mjs} +2 -1
  24. package/dist/{studio-Bk_u41gu.d.mts → studio-DLduJRSp.d.mts} +2 -2
  25. package/dist/studio-EKd7cQN7.mjs +397 -0
  26. package/dist/studio.d.mts +1 -1
  27. package/dist/studio.mjs +1 -1
  28. package/dist/sync.d.mts +2 -2
  29. package/dist/sync.mjs +2 -2
  30. package/dist/{transport-B_ig9Znn.mjs → version-TY9EZF0F.mjs} +39 -5
  31. package/package.json +6 -2
  32. /package/dist/{auth-2Thaw42j.d.mts → auth-B0ZTKri2.d.mts} +0 -0
  33. /package/dist/{index-ag6K2iAS.d.mts → index-CKFbG_Ix.d.mts} +0 -0
@@ -0,0 +1,184 @@
1
+ import { a as EditorSyncParseRequest, d as EditorSyncTextReplacement, f as MachineSourceLocations, i as EditorSyncApplyResponse, n as EditorSyncAccess, o as EditorSyncParseResponse, r as EditorSyncApplyRequest, s as EditorSyncSourceDocument, t as EditorCapabilities } from "./editor-sync-types-D8_EZm0A.mjs";
2
+
3
+ //#region src/editorHostProtocol.d.ts
4
+ declare const EDITOR_PROTOCOL_VERSION = 1;
5
+ type EditorHostExportFormat = 'xstate-v6' | 'xstate' | 'async' | 'xstate-json' | 'xgraph' | 'digraph' | 'd2' | 'mermaid' | 'redux' | 'zustand' | 'asl-json' | 'asl-yaml' | 'scxml';
6
+ interface EditorHostValidationIssue {
7
+ nodeIds: string[];
8
+ edgeIds: string[];
9
+ level: 'info' | 'warning' | 'error';
10
+ message: string;
11
+ }
12
+ type EditorHostInboundMessage = {
13
+ type: '@statelyai.ready';
14
+ version?: string;
15
+ protocolVersion?: number;
16
+ } | {
17
+ type: '@statelyai.loaded';
18
+ graph: unknown;
19
+ sourceLocations?: MachineSourceLocations;
20
+ } | {
21
+ type: '@statelyai.change';
22
+ graph: unknown;
23
+ machineConfig: unknown;
24
+ patches?: unknown[];
25
+ sourceLocations?: MachineSourceLocations;
26
+ } | {
27
+ type: '@statelyai.save';
28
+ graph: unknown;
29
+ machineConfig: unknown;
30
+ patches?: unknown[];
31
+ validations?: EditorHostValidationIssue[];
32
+ sourceLocations?: MachineSourceLocations;
33
+ } | {
34
+ type: '@statelyai.retrieved';
35
+ requestId: string;
36
+ data: unknown;
37
+ } | {
38
+ type: '@statelyai.error';
39
+ code: string;
40
+ message: string;
41
+ requestId?: string;
42
+ } | {
43
+ type: '@statelyai.clipboardRead';
44
+ requestId: string;
45
+ } | {
46
+ type: '@statelyai.clipboardWrite';
47
+ requestId: string;
48
+ text: string;
49
+ };
50
+ interface EditorHostInitOptions {
51
+ settings?: Record<string, unknown>;
52
+ leftPanels?: string[];
53
+ rightPanels?: string[];
54
+ activePanels?: string[];
55
+ unsavedIndicator?: {
56
+ enabled?: boolean;
57
+ mode?: 'structural' | 'all';
58
+ };
59
+ }
60
+ type EditorHostOutboundMessage = {
61
+ type: '@statelyai.init';
62
+ machine: unknown;
63
+ format?: string;
64
+ mode?: 'editing' | 'viewing';
65
+ theme?: 'light' | 'dark';
66
+ readOnly?: boolean;
67
+ readOnlyReason?: 'free-plan' | 'access-unverified';
68
+ capabilities?: EditorCapabilities;
69
+ sourceLocations?: MachineSourceLocations;
70
+ settings?: Record<string, unknown>;
71
+ leftPanels?: string[];
72
+ rightPanels?: string[];
73
+ activePanels?: string[];
74
+ unsavedIndicator?: {
75
+ enabled?: boolean;
76
+ mode?: 'structural' | 'all';
77
+ };
78
+ } | {
79
+ type: '@statelyai.setApiKey';
80
+ apiKey: string;
81
+ } | {
82
+ type: '@statelyai.handshake';
83
+ protocolVersion: number;
84
+ client?: {
85
+ name: string;
86
+ version: string;
87
+ };
88
+ } | {
89
+ type: '@statelyai.update';
90
+ machine: unknown;
91
+ format?: string;
92
+ sourceLocations?: MachineSourceLocations;
93
+ } | {
94
+ type: '@statelyai.saved';
95
+ graph: unknown;
96
+ } | {
97
+ type: '@statelyai.retrieve';
98
+ requestId: string;
99
+ format: EditorHostExportFormat;
100
+ } | {
101
+ type: '@statelyai.toast';
102
+ message: string;
103
+ toastType?: 'success' | 'error' | 'info' | 'warning';
104
+ } | {
105
+ type: '@statelyai.error';
106
+ code: string;
107
+ message: string;
108
+ } | {
109
+ type: '@statelyai.clipboardReadResponse';
110
+ requestId: string;
111
+ text: string;
112
+ } | {
113
+ type: '@statelyai.clipboardWriteResponse';
114
+ requestId: string;
115
+ ok: boolean;
116
+ };
117
+ //#endregion
118
+ //#region src/editorHostSession.d.ts
119
+ interface EditorSyncBackend {
120
+ parse(request: EditorSyncParseRequest): Promise<EditorSyncParseResponse>;
121
+ apply(request: EditorSyncApplyRequest): Promise<EditorSyncApplyResponse>;
122
+ }
123
+ interface RemoteEditorSyncBackendOptions {
124
+ editorUrl: string;
125
+ apiKey?: string;
126
+ fetch?: typeof globalThis.fetch;
127
+ }
128
+ declare function createRemoteEditorSyncBackend(options: RemoteEditorSyncBackendOptions): EditorSyncBackend;
129
+ declare function fetchEditorSyncAccess(options: RemoteEditorSyncBackendOptions): Promise<EditorSyncAccess>;
130
+ interface EditorSourceHost {
131
+ rootUri: string;
132
+ rootFileName: string;
133
+ rootDir: string;
134
+ collectDocuments(extraUris?: readonly string[]): Promise<EditorSyncSourceDocument[]>;
135
+ applyReplacements(replacements: EditorSyncTextReplacement[], rootUri: string): Promise<string[]>;
136
+ saveDocuments?(uris: string[]): Promise<void>;
137
+ watchSavedDocuments?(listener: (uri: string) => void | Promise<void>): {
138
+ dispose(): void;
139
+ };
140
+ getPreserveStatelyMetadata?(uri: string): boolean;
141
+ }
142
+ interface EditorHostSessionOptions {
143
+ source: EditorSourceHost;
144
+ sync: EditorSyncBackend;
145
+ send(message: EditorHostOutboundMessage): void;
146
+ access?: EditorSyncAccess;
147
+ apiKey?: string;
148
+ getTheme?(): 'light' | 'dark';
149
+ showError?(message: string): void;
150
+ readClipboard?(): Promise<string>;
151
+ writeClipboard?(text: string): Promise<void>;
152
+ init?: EditorHostInitOptions;
153
+ client?: {
154
+ name: string;
155
+ version: string;
156
+ };
157
+ }
158
+ declare class EditorHostSession {
159
+ private options;
160
+ private editorProtocolState;
161
+ private currentGraph;
162
+ private lastPersistedGraph;
163
+ private currentFormat;
164
+ private currentSourceLocations;
165
+ private access;
166
+ private watchedSourceUris;
167
+ private selfEditCount;
168
+ private watcher;
169
+ private retrieveRequestCount;
170
+ private pendingRetrievals;
171
+ constructor(options: EditorHostSessionOptions);
172
+ dispose(): void;
173
+ notifySavedDocument(uri?: string): Promise<void>;
174
+ receive(message: EditorHostInboundMessage): Promise<void>;
175
+ private initialize;
176
+ private save;
177
+ private handleSavedDocument;
178
+ private updateWatchedSourceUris;
179
+ private getSerializedPayload;
180
+ private requestSerialized;
181
+ private resolveRetrieved;
182
+ }
183
+ //#endregion
184
+ export { RemoteEditorSyncBackendOptions as a, EDITOR_PROTOCOL_VERSION as c, EditorHostInitOptions as d, EditorHostOutboundMessage as f, EditorSyncBackend as i, EditorHostExportFormat as l, EditorHostSessionOptions as n, createRemoteEditorSyncBackend as o, EditorHostValidationIssue as p, EditorSourceHost as r, fetchEditorSyncAccess as s, EditorHostSession as t, EditorHostInboundMessage as u };
@@ -0,0 +1,2 @@
1
+ import { a as RemoteEditorSyncBackendOptions, c as EDITOR_PROTOCOL_VERSION, d as EditorHostInitOptions, f as EditorHostOutboundMessage, i as EditorSyncBackend, l as EditorHostExportFormat, n as EditorHostSessionOptions, o as createRemoteEditorSyncBackend, p as EditorHostValidationIssue, r as EditorSourceHost, s as fetchEditorSyncAccess, t as EditorHostSession, u as EditorHostInboundMessage } from "./editorHostSession-jnC5mQDN.mjs";
2
+ export { EDITOR_PROTOCOL_VERSION, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorSourceHost, EditorSyncBackend, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
@@ -0,0 +1,4 @@
1
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
2
+ import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-CZHd22pZ.mjs";
3
+
4
+ export { EDITOR_PROTOCOL_VERSION, EditorHostSession, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
package/dist/embed.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as StatelyGraph } from "./graph-DuOeLGvh.mjs";
2
- import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, UploadResult } from "./protocol.mjs";
1
+ import { i as StatelyGraph } from "./graph-DxeqWHC3.mjs";
2
+ import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, UploadResult } from "./protocol.mjs";
3
3
  import { AssetUploadAdapter } from "./assetStorage.mjs";
4
4
 
5
5
  //#region src/embed.d.ts
@@ -91,4 +91,4 @@ interface StatelyEmbed {
91
91
  }
92
92
  declare function createStatelyEmbed(options: StatelyEmbedOptions): StatelyEmbed;
93
93
  //#endregion
94
- export { AssetConfig, type CapabilityDeniedEvent, type CommentsConfig, type EditorCapabilities, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type InitOptions, type MachineInitOptions, type MachineSourceLocations, type ProjectEmbedMachine, StatelyEmbed, StatelyEmbedOptions, type UploadResult, createStatelyEmbed };
94
+ export { AssetConfig, type CapabilityDeniedEvent, type CommentsConfig, type EditorCapabilities, type EmbedDocument, type EmbedDocumentLanguage, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type InitOptions, type MachineInitOptions, type MachineSourceLocations, type ProjectEmbedMachine, StatelyEmbed, StatelyEmbedOptions, type UploadResult, createStatelyEmbed };
package/dist/embed.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { a as toInitMessage, i as createPendingExportManager, r as createEventRegistry, t as createPostMessageTransport } from "./transport-B_ig9Znn.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-TY9EZF0F.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
2
3
 
3
4
  //#region src/embed.ts
4
5
  function buildEmbedUrl(options) {
@@ -10,6 +11,7 @@ function buildEmbedUrl(options) {
10
11
  function extractInitOptions(options) {
11
12
  if (options.machines) return {
12
13
  machines: options.machines,
14
+ documents: options.documents,
13
15
  currentMachineId: options.currentMachineId,
14
16
  mode: options.mode,
15
17
  theme: options.theme,
@@ -22,6 +24,7 @@ function extractInitOptions(options) {
22
24
  };
23
25
  if (options.machine !== void 0) return {
24
26
  machine: options.machine,
27
+ documents: options.documents,
25
28
  format: options.format,
26
29
  mode: options.mode,
27
30
  theme: options.theme,
@@ -43,6 +46,7 @@ function createStatelyEmbed(options) {
43
46
  let transport = null;
44
47
  let ownedIframe = false;
45
48
  let destroyed = false;
49
+ let editorProtocolCompatible;
46
50
  const pendingMessages = [];
47
51
  const events = createEventRegistry();
48
52
  const exportManager = createPendingExportManager((message) => send(message));
@@ -54,6 +58,7 @@ function createStatelyEmbed(options) {
54
58
  const assetAccept = options.assets?.accept ?? assetUploadAdapter?.accept;
55
59
  const assetMaxFileSize = options.assets?.maxFileSize ?? assetUploadAdapter?.maxFileSize;
56
60
  function send(msg) {
61
+ if (editorProtocolCompatible === false) return;
57
62
  if (!transport?.ready) {
58
63
  pendingMessages.push(msg);
59
64
  return;
@@ -61,7 +66,7 @@ function createStatelyEmbed(options) {
61
66
  transport.send(msg);
62
67
  }
63
68
  function flush() {
64
- if (!transport) return;
69
+ if (!transport || editorProtocolCompatible === false) return;
65
70
  while (pendingMessages.length > 0) {
66
71
  const msg = pendingMessages.shift();
67
72
  transport.send(msg);
@@ -72,6 +77,27 @@ function createStatelyEmbed(options) {
72
77
  switch (data.type) {
73
78
  case "@statelyai.ready": {
74
79
  const ready = data;
80
+ if (ready.protocolVersion !== void 0) {
81
+ if (ready.protocolVersion !== EDITOR_PROTOCOL_VERSION) {
82
+ editorProtocolCompatible = false;
83
+ const error = {
84
+ code: "unsupported_protocol",
85
+ message: `Editor protocol ${ready.protocolVersion} is unsupported; this SDK supports ${EDITOR_PROTOCOL_VERSION}.`
86
+ };
87
+ options.onError?.(error);
88
+ events.emit("error", error);
89
+ break;
90
+ }
91
+ editorProtocolCompatible = true;
92
+ send({
93
+ type: "@statelyai.handshake",
94
+ protocolVersion: EDITOR_PROTOCOL_VERSION,
95
+ client: {
96
+ name: "@statelyai/sdk",
97
+ version: SDK_VERSION
98
+ }
99
+ });
100
+ } else editorProtocolCompatible = true;
75
101
  flush();
76
102
  if (uploadAsset) send({
77
103
  type: "@statelyai.uploadCapabilities",
@@ -187,6 +213,7 @@ function createStatelyEmbed(options) {
187
213
  }
188
214
  function replaceTransport(nextTransport) {
189
215
  transport?.destroy();
216
+ editorProtocolCompatible = void 0;
190
217
  transport = nextTransport;
191
218
  }
192
219
  function setupTransport(el) {
@@ -196,7 +223,10 @@ function createStatelyEmbed(options) {
196
223
  });
197
224
  replaceTransport(nextTransport);
198
225
  nextTransport.onMessage(handleMessage);
199
- nextTransport.onReady(flush);
226
+ nextTransport.onReady(() => {
227
+ editorProtocolCompatible ??= true;
228
+ flush();
229
+ });
200
230
  }
201
231
  const embed = {
202
232
  attach(el) {
@@ -1,4 +1,4 @@
1
- import { r as CodeExpression } from "./index-ag6K2iAS.mjs";
1
+ import { r as CodeExpression } from "./index-CKFbG_Ix.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-DuOeLGvh.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-DxeqWHC3.mjs";
2
2
  export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };
package/dist/index.d.mts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
2
- import { _ as serializeJS, c as MachineConfigOptions, d as contextSchemaToTSType, f as eventsSchemaToTSType, g as raw, h as jsonSchemaToTSType, i as CodeGenGraph, l as RawCode, m as graphToXStateTS, o as GraphPatch, p as graphToMachineConfig, t as ActionLocation, u as XStateTSOptions } from "./index-ag6K2iAS.mjs";
3
- import { C as EventTypeData, S as DigraphNodeConfig, _ as studioMachineConverter, a as StatelyGraphData, b as DigraphConfig, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, o as StatelyGuard, r as StatelyEdgeData, t as StatelyAction, v as toStudioMachine, w as StateNodeJSONData, x as DigraphEdgeConfig, y as DigraphAction } from "./graph-DuOeLGvh.mjs";
4
- import { CapabilityDeniedCapability, CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, InitOptions, InspectionAction, InspectionSentEvent, InspectionTakenTransition, ProjectEmbedMachine, UploadResult, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
2
+ import { _ as serializeJS, c as MachineConfigOptions, d as contextSchemaToTSType, f as eventsSchemaToTSType, g as raw, h as jsonSchemaToTSType, i as CodeGenGraph, l as RawCode, m as graphToXStateTS, o as GraphPatch, p as graphToMachineConfig, t as ActionLocation, u as XStateTSOptions } from "./index-CKFbG_Ix.mjs";
3
+ import { C as EventTypeData, S as DigraphNodeConfig, _ as studioMachineConverter, a as StatelyGraphData, b as DigraphConfig, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, o as StatelyGuard, r as StatelyEdgeData, t as StatelyAction, v as toStudioMachine, w as StateNodeJSONData, x as DigraphEdgeConfig, y as DigraphAction } from "./graph-DxeqWHC3.mjs";
4
+ import { CapabilityDeniedCapability, CapabilityDeniedEvent, CommentsConfig, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, InitOptions, InspectionAction, InspectionSentEvent, InspectionTakenTransition, ProjectEmbedMachine, UploadResult, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
5
5
  import { AssetUploadAdapter, AssetUploadContext, AssetUploadRequest, CreateS3AssetUploadAdapterOptions, CreateSupabaseAssetUploadAdapterOptions, S3UploadTarget, SupabaseStorageClient, createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
6
- import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-2Thaw42j.mjs";
6
+ import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
7
+ import { a as RemoteEditorSyncBackendOptions, c as EDITOR_PROTOCOL_VERSION, d as EditorHostInitOptions, f as EditorHostOutboundMessage, i as EditorSyncBackend, l as EditorHostExportFormat, n as EditorHostSessionOptions, o as createRemoteEditorSyncBackend, p as EditorHostValidationIssue, r as EditorSourceHost, s as fetchEditorSyncAccess, t as EditorHostSession, u as EditorHostInboundMessage } from "./editorHostSession-jnC5mQDN.mjs";
7
8
  import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
8
- import { a as InspectedTransition, c as InspectorInspectionEvent, d as createStatelyInspector, f as Transport, h as createWebSocketTransport, i as InspectedSnapshot, l as ManualActorOptions, m as createPostMessageTransport, n as CreateInspectorOptions, o as Inspector, p as TransportFailure, r as InspectedEvent, s as InspectorEvents, t as AdoptedActor, u as createInspector } from "./inspect-BZFzyeew.mjs";
9
- import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-Bk_u41gu.mjs";
9
+ import { a as InspectedTransition, c as InspectorInspectionEvent, d as createStatelyInspector, f as Transport, h as createWebSocketTransport, i as InspectedSnapshot, l as ManualActorOptions, m as createPostMessageTransport, n as CreateInspectorOptions, o as Inspector, p as TransportFailure, r as InspectedEvent, s as InspectorEvents, t as AdoptedActor, u as createInspector } from "./inspect-CGJR4iZK.mjs";
10
+ import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-DLduJRSp.mjs";
10
11
  import { OAuthAuthorizationServerMetadata, OAuthClientRegistrationResponse, OAuthProtectedResourceMetadata, OAuthTokenResponse, PkcePair, buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
11
12
  import { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
12
13
  import { CreateInspectionRelayOptions, InspectionRelay, InspectionRelayEffect, InspectionRelayPeer, InspectionRelayRole, InspectionRelaySnapshot, createInspectionRelay } from "./relay.mjs";
@@ -32,4 +33,4 @@ declare function findStatelyPragmaAttachments(sourceText: string, fileName?: str
32
33
  declare function getStatelyPragma(sourceText: string, fileName?: string, machineIndex?: number): StatelyPragma | undefined;
33
34
  declare function upsertStatelyPragma(sourceText: string, id: string, options?: UpsertStatelyPragmaOptions): string;
34
35
  //#endregion
35
- export { type ActionLocation, type AdoptedActor, type AssetConfig, type AssetUploadAdapter, type AssetUploadContext, type AssetUploadRequest, type CapabilityDeniedCapability, type CapabilityDeniedEvent, type CodeGenGraph, type CommentsConfig, type ConnectedRepo, type CreateInspectionRelayOptions, type CreateInspectorOptions, type CreateMachineFromDefinitionInput, type CreateMachineFromTemplateInput, type CreateMachineInput, type CreateMachineTemplate, type CreateProjectInput, type CreateS3AssetUploadAdapterOptions, type CreateSupabaseAssetUploadAdapterOptions, DEFAULT_STATELY_BASE_URL, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, type EditorCapabilities, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EnsureProjectInput, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesInput, type ExtractMachinesResponse, type ExtractedMachine, type ExtractedMachines, type GetMachineOptions, type GraphPatch, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, type InitOptions, type InspectedEvent, type InspectedSnapshot, type InspectedTransition, type InspectionAction, type InspectionRelay, type InspectionRelayEffect, type InspectionRelayPeer, type InspectionRelayRole, type InspectionRelaySnapshot, type InspectionSentEvent, type InspectionTakenTransition, type Inspector, type InspectorEvents, type InspectorInspectionEvent, type LegacyProjectVisibility, type LegacyUpdateMachineInput, type Machine, type MachineConfigOptions, type MachineVersion, type ManualActorOptions, type OAuthAuthorizationServerMetadata, type OAuthClientRegistrationResponse, type OAuthProtectedResourceMetadata, type OAuthTokenResponse, type PkcePair, type PlanSyncOptions, type Project, type ProjectData, type ProjectEmbedMachine, type ProjectMachine, type ProjectMachineSummary, type ProjectSummary, type ProjectVisibility, type PullSyncResult, type PushLocalMachineLinksResult, type PushSyncOptions, type PushSyncProjectOptions, type PushSyncResult, RawCode, type RepoType, type ResolvedSyncInput, type ResourceErrorCode, type S3UploadTarget, type StateNodeJSONData, type StatelyAction, type StatelyApiClientOptions, StatelyApiError, type StatelyApiUrlOptions, type StatelyAuthMode, type StatelyCredential, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StatelyPragma, type StatelyPragmaAttachment, type StudioAction, StudioApiError, type StudioApiErrorOptions, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioMachineRecord, type StudioNode, type StudioRequestOptions, type SupabaseStorageClient, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type TransportFailure, type UpdateMachineInput, type UpdateProjectInput, type UploadResult, type UpsertStatelyPragmaOptions, type VerifyApiKeyResponse, type VerifyResult, type XStateTSOptions, type XStateVersion, buildAuthorizeUrl, contextSchemaToTSType, createAuthorizationHeader, createInspectionActorId, createInspectionRelay, createInspectionRoomUrls, createInspector, createPkcePair, createPostMessageTransport, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, discoverAuthorizationServer, discoverProtectedResource, eventsSchemaToTSType, exchangeCodeForToken, findStatelyPragmaAttachments, fromStudioMachine, getCredentialToken, getInspectionRoomId, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, refreshToken, registerOAuthClient, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
36
+ export { type ActionLocation, type AdoptedActor, type AssetConfig, type AssetUploadAdapter, type AssetUploadContext, type AssetUploadRequest, type CapabilityDeniedCapability, type CapabilityDeniedEvent, type CodeGenGraph, type CommentsConfig, type ConnectedRepo, type CreateInspectionRelayOptions, type CreateInspectorOptions, type CreateMachineFromDefinitionInput, type CreateMachineFromTemplateInput, type CreateMachineInput, type CreateMachineTemplate, type CreateProjectInput, type CreateS3AssetUploadAdapterOptions, type CreateSupabaseAssetUploadAdapterOptions, DEFAULT_STATELY_BASE_URL, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, EDITOR_PROTOCOL_VERSION, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, type EditorCapabilities, type EditorHostExportFormat, type EditorHostInboundMessage, type EditorHostInitOptions, type EditorHostOutboundMessage, EditorHostSession, type EditorHostSessionOptions, type EditorHostValidationIssue, type EditorSourceHost, type EditorSyncBackend, type EmbedDocument, type EmbedDocumentLanguage, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EnsureProjectInput, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesInput, type ExtractMachinesResponse, type ExtractedMachine, type ExtractedMachines, type GetMachineOptions, type GraphPatch, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, type InitOptions, type InspectedEvent, type InspectedSnapshot, type InspectedTransition, type InspectionAction, type InspectionRelay, type InspectionRelayEffect, type InspectionRelayPeer, type InspectionRelayRole, type InspectionRelaySnapshot, type InspectionSentEvent, type InspectionTakenTransition, type Inspector, type InspectorEvents, type InspectorInspectionEvent, type LegacyProjectVisibility, type LegacyUpdateMachineInput, type Machine, type MachineConfigOptions, type MachineVersion, type ManualActorOptions, type OAuthAuthorizationServerMetadata, type OAuthClientRegistrationResponse, type OAuthProtectedResourceMetadata, type OAuthTokenResponse, type PkcePair, type PlanSyncOptions, type Project, type ProjectData, type ProjectEmbedMachine, type ProjectMachine, type ProjectMachineSummary, type ProjectSummary, type ProjectVisibility, type PullSyncResult, type PushLocalMachineLinksResult, type PushSyncOptions, type PushSyncProjectOptions, type PushSyncResult, RawCode, type RemoteEditorSyncBackendOptions, type RepoType, type ResolvedSyncInput, type ResourceErrorCode, type S3UploadTarget, type StateNodeJSONData, type StatelyAction, type StatelyApiClientOptions, StatelyApiError, type StatelyApiUrlOptions, type StatelyAuthMode, type StatelyCredential, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StatelyPragma, type StatelyPragmaAttachment, type StudioAction, StudioApiError, type StudioApiErrorOptions, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioMachineRecord, type StudioNode, type StudioRequestOptions, type SupabaseStorageClient, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type TransportFailure, type UpdateMachineInput, type UpdateProjectInput, type UploadResult, type UpsertStatelyPragmaOptions, type VerifyApiKeyResponse, type VerifyResult, type XStateTSOptions, type XStateVersion, buildAuthorizeUrl, contextSchemaToTSType, createAuthorizationHeader, createInspectionActorId, createInspectionRelay, createInspectionRoomUrls, createInspector, createPkcePair, createPostMessageTransport, createRemoteEditorSyncBackend, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, discoverAuthorizationServer, discoverProtectedResource, eventsSchemaToTSType, exchangeCodeForToken, fetchEditorSyncAccess, findStatelyPragmaAttachments, fromStudioMachine, getCredentialToken, getInspectionRoomId, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, refreshToken, registerOAuthClient, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
package/dist/index.mjs CHANGED
@@ -1,14 +1,16 @@
1
- import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-B_ig9Znn.mjs";
2
- import { INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
1
+ import { EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
2
+ import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-TY9EZF0F.mjs";
3
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
3
4
  import { createStatelyEmbed } from "./embed.mjs";
5
+ import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-CZHd22pZ.mjs";
6
+ import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-EKd7cQN7.mjs";
7
+ import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, n as getStatelyPragma, o as contextSchemaToTSType, p as serializeJS, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-GN-bfuC_.mjs";
4
8
  import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
5
- import { n as createStatelyInspector, t as createInspector } from "./inspect-CF_6aEnv.mjs";
6
- import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-txdyJHD7.mjs";
7
- import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, n as getStatelyPragma, o as contextSchemaToTSType, p as serializeJS, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-Th0gdXfx.mjs";
9
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-CWwLGwLq.mjs";
8
10
  import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
9
11
  import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
10
12
  import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
11
13
  import { fromStudioMachine, studioMachineConverter, toStudioMachine } from "./graph.mjs";
12
14
  import { createInspectionRelay } from "./relay.mjs";
13
15
 
14
- export { DEFAULT_STATELY_BASE_URL, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, RawCode, StatelyApiError, StudioApiError, buildAuthorizeUrl, contextSchemaToTSType, createAuthorizationHeader, createInspectionActorId, createInspectionRelay, createInspectionRoomUrls, createInspector, createPkcePair, createPostMessageTransport, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, discoverAuthorizationServer, discoverProtectedResource, eventsSchemaToTSType, exchangeCodeForToken, findStatelyPragmaAttachments, fromStudioMachine, getCredentialToken, getInspectionRoomId, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, refreshToken, registerOAuthClient, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
16
+ export { DEFAULT_STATELY_BASE_URL, EDITOR_PROTOCOL_VERSION, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, EditorHostSession, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, RawCode, StatelyApiError, StudioApiError, buildAuthorizeUrl, contextSchemaToTSType, createAuthorizationHeader, createInspectionActorId, createInspectionRelay, createInspectionRoomUrls, createInspector, createPkcePair, createPostMessageTransport, createRemoteEditorSyncBackend, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, discoverAuthorizationServer, discoverProtectedResource, eventsSchemaToTSType, exchangeCodeForToken, fetchEditorSyncAccess, findStatelyPragmaAttachments, fromStudioMachine, getCredentialToken, getInspectionRoomId, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, refreshToken, registerOAuthClient, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
@@ -62,7 +62,7 @@ interface InspectorInspectionEvent {
62
62
  readonly actorRef: unknown;
63
63
  }
64
64
  interface AdoptedActor {
65
- /** XState process-local `actor.sessionId`. Pair with inspector.producerId. */
65
+ /** Producer-local session id; defaults to XState's `actor.sessionId`. */
66
66
  sessionId: string;
67
67
  /** System-local `actor.id`. */
68
68
  actorId: string;
@@ -137,7 +137,10 @@ interface CreateInspectorOptions {
137
137
  url?: string;
138
138
  /** Unguessable inspection room capability. Defaults to a random UUID. */
139
139
  roomId?: string;
140
- /** Stable identity for this producer connection. Defaults to a random UUID. */
140
+ /**
141
+ * Stable identity for this producer across reconnects and restored Inspector
142
+ * instances. Defaults to a random UUID.
143
+ */
141
144
  producerId?: string;
142
145
  /**
143
146
  * Inspector UI base URL when hosted separately from the WebSocket relay. The
@@ -172,6 +175,13 @@ interface CreateInspectorOptions {
172
175
  * @deprecated Use {@link extractMachine}; it also accepts source strings.
173
176
  */
174
177
  extractMachineConfig?: (actor: any, source?: unknown) => unknown;
178
+ /**
179
+ * Resolve the producer-local identity used for an actor on the inspection
180
+ * wire. Defaults to XState's runtime `actor.sessionId`. The resolver runs
181
+ * once per runtime actor and must return a non-empty id that is unique among
182
+ * all actors observed by this inspector.
183
+ */
184
+ resolveSessionId?: (actor: any, defaultSessionId: string) => string;
175
185
  /** Selected actor session id to focus on first. */
176
186
  selectedSessionId?: string;
177
187
  /** @deprecated Use {@link selectedSessionId}. */
@@ -193,7 +203,7 @@ interface CreateInspectorOptions {
193
203
  transport?: Transport;
194
204
  }
195
205
  interface Inspector {
196
- /** Snapshot of this producer's actors keyed by XState `sessionId`. */
206
+ /** Snapshot of this producer's actors keyed by resolved `sessionId`. */
197
207
  readonly actors: ReadonlyMap<string, AdoptedActor>;
198
208
  /** Unguessable inspection room capability. */
199
209
  readonly roomId: string;
@@ -1,5 +1,5 @@
1
- import { i as createPendingExportManager, n as createWebSocketTransport, r as createEventRegistry } from "./transport-B_ig9Znn.mjs";
2
1
  import { INSPECTION_PROTOCOL_VERSION, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
2
+ import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-TY9EZF0F.mjs";
3
3
 
4
4
  //#region src/openBrowser.ts
5
5
  async function openBrowser(url) {
@@ -26,15 +26,6 @@ async function openBrowser(url) {
26
26
  });
27
27
  }
28
28
 
29
- //#endregion
30
- //#region src/version.ts
31
- const SDK_VERSION = "0.17.0";
32
- function inspectionRuntime() {
33
- if (typeof window !== "undefined") return "browser";
34
- if (typeof process !== "undefined" && process.versions?.node) return "node";
35
- return "unknown";
36
- }
37
-
38
29
  //#endregion
39
30
  //#region src/inspect.ts
40
31
  const defaultSerializeSnapshot = (snapshot) => ({
@@ -174,11 +165,29 @@ function createInspector(options = {}) {
174
165
  for (const handler of set) handler(data);
175
166
  }
176
167
  const actors = /* @__PURE__ */ new Map();
168
+ const resolvedSessionIds = /* @__PURE__ */ new WeakMap();
169
+ const actorsByResolvedSessionId = /* @__PURE__ */ new Map();
177
170
  const manualSessionIds = /* @__PURE__ */ new Map();
178
171
  /** Tracks which actors we've already emitted local actor events for. */
179
172
  const locallyRegistered = /* @__PURE__ */ new Set();
180
173
  /** v5 emits transition facets separately; accumulate them until snapshot. */
181
174
  const pendingTransitions = /* @__PURE__ */ new Map();
175
+ function sessionIdOf(actorRef) {
176
+ const existing = resolvedSessionIds.get(actorRef);
177
+ if (existing) return existing;
178
+ const resolved = options.resolveSessionId?.(actorRef, actorRef.sessionId) ?? actorRef.sessionId;
179
+ if (typeof resolved !== "string" || resolved.length === 0) throw new Error("createInspector(): resolveSessionId must return a non-empty string.");
180
+ const claimedBy = actorsByResolvedSessionId.get(resolved);
181
+ if (claimedBy !== void 0 && claimedBy !== actorRef || claimedBy === void 0 && actors.has(resolved)) throw new Error(`createInspector(): resolveSessionId returned duplicate id "${resolved}".`);
182
+ resolvedSessionIds.set(actorRef, resolved);
183
+ actorsByResolvedSessionId.set(resolved, actorRef);
184
+ return resolved;
185
+ }
186
+ function rootSessionIdOf(runtimeRootId, actorRef) {
187
+ let rootRef = actorRef;
188
+ while (rootRef._parent) rootRef = rootRef._parent;
189
+ return rootRef.sessionId === runtimeRootId ? sessionIdOf(rootRef) : runtimeRootId;
190
+ }
182
191
  function emitRegisterOnce(entry) {
183
192
  if (locallyRegistered.has(entry.sessionId)) return;
184
193
  locallyRegistered.add(entry.sessionId);
@@ -200,10 +209,12 @@ function createInspector(options = {}) {
200
209
  }
201
210
  }
202
211
  function toEntry(actorRef, rootActorId, details) {
212
+ const sessionId = sessionIdOf(actorRef);
213
+ const parentRef = details?.parentRef ?? actorRef._parent;
203
214
  return {
204
- sessionId: actorRef.sessionId,
205
- actorId: details?.id ?? actorRef.id ?? actorRef.sessionId,
206
- parentSessionId: details?.parentRef?.sessionId ?? actorRef._parent?.sessionId ?? null,
215
+ sessionId,
216
+ actorId: details?.id ?? actorRef.id ?? sessionId,
217
+ parentSessionId: parentRef ? sessionIdOf(parentRef) : null,
207
218
  rootSessionId: rootActorId,
208
219
  systemId: actorRef.systemId,
209
220
  snapshot: details?.snapshot ? serializeSnapshot(details.snapshot) : snapshotValue(actorRef),
@@ -221,12 +232,17 @@ function createInspector(options = {}) {
221
232
  ...entry.stopped && { stopped: true }
222
233
  };
223
234
  }
235
+ function resolveActorTreeSessionIds(actorRef) {
236
+ sessionIdOf(actorRef);
237
+ const children = actorRef.getSnapshot()?.children ?? {};
238
+ for (const child of Object.values(children)) if (child) resolveActorTreeSessionIds(child);
239
+ }
224
240
  /**
225
241
  * Walk the actor tree and populate the local `actors` map. Idempotent —
226
242
  * existing entries stay in place but have their snapshot refreshed.
227
243
  */
228
244
  function backfillActorTree(actorRef, rootActorId) {
229
- const existing = actors.get(actorRef.sessionId);
245
+ const existing = actors.get(sessionIdOf(actorRef));
230
246
  const entry = existing ?? toEntry(actorRef, rootActorId);
231
247
  if (existing) {
232
248
  const snapshot = actorRef.getSnapshot();
@@ -260,7 +276,7 @@ function createInspector(options = {}) {
260
276
  initSent = true;
261
277
  }
262
278
  function handleActor(actorRef, rootActorId, details) {
263
- if (actors.has(actorRef.sessionId)) return;
279
+ if (actors.has(sessionIdOf(actorRef))) return;
264
280
  const entry = toEntry(actorRef, rootActorId, details);
265
281
  actors.set(entry.sessionId, entry);
266
282
  emitRegisterOnce(entry);
@@ -293,7 +309,7 @@ function createInspector(options = {}) {
293
309
  }
294
310
  function normalizeSentEvent(sentEvent) {
295
311
  return {
296
- ...sentEvent.targetRef?.sessionId && { targetSessionId: sentEvent.targetRef.sessionId },
312
+ ...sentEvent.targetRef?.sessionId && { targetSessionId: sessionIdOf(sentEvent.targetRef) },
297
313
  targetId: sentEvent.targetId,
298
314
  event: sentEvent.event,
299
315
  ...sentEvent.delay !== void 0 && { delay: sentEvent.delay },
@@ -301,10 +317,11 @@ function createInspector(options = {}) {
301
317
  };
302
318
  }
303
319
  function createPendingTransition(actorRef, event = null, sourceRef) {
320
+ const sessionId = sessionIdOf(actorRef);
304
321
  return {
305
- previousSnapshot: actors.get(actorRef.sessionId)?.snapshot ?? null,
322
+ previousSnapshot: actors.get(sessionId)?.snapshot ?? null,
306
323
  event,
307
- sourceSessionId: sourceRef?.sessionId ?? null,
324
+ sourceSessionId: sourceRef ? sessionIdOf(sourceRef) : null,
308
325
  actions: [],
309
326
  transitions: [],
310
327
  sent: []
@@ -325,15 +342,17 @@ function createInspector(options = {}) {
325
342
  emitLocal("event", inspectedEvent);
326
343
  }
327
344
  function getPendingTransition(actorRef, event) {
328
- const existing = pendingTransitions.get(actorRef.sessionId);
345
+ const sessionId = sessionIdOf(actorRef);
346
+ const existing = pendingTransitions.get(sessionId);
329
347
  if (existing) return existing;
330
348
  const pending = createPendingTransition(actorRef, event);
331
- pendingTransitions.set(actorRef.sessionId, pending);
349
+ pendingTransitions.set(sessionId, pending);
332
350
  return pending;
333
351
  }
334
352
  function handleTransition(actorRef, snapshot, triggeringEvent, rootActorId, transition) {
335
- if (!actors.has(actorRef.sessionId)) handleActor(actorRef, rootActorId);
336
- const entry = actors.get(actorRef.sessionId);
353
+ const sessionId = sessionIdOf(actorRef);
354
+ if (!actors.has(sessionId)) handleActor(actorRef, rootActorId);
355
+ const entry = actors.get(sessionId);
337
356
  if (!entry) return;
338
357
  const serialized = serializeSnapshot(snapshot);
339
358
  const inspectedSnapshot = {
@@ -378,7 +397,7 @@ function createInspector(options = {}) {
378
397
  function handleInspectionEvent(inspectionEvent) {
379
398
  if (destroyed) return;
380
399
  const event = inspectionEvent;
381
- const rootActorId = event.rootId;
400
+ const rootActorId = rootSessionIdOf(event.rootId, event.actorRef);
382
401
  const isNewRoot = !observedRootIds.has(rootActorId);
383
402
  observedRootIds.add(rootActorId);
384
403
  switch (event.type) {
@@ -390,11 +409,13 @@ function createInspector(options = {}) {
390
409
  snapshot: event.snapshot
391
410
  });
392
411
  break;
393
- case "@xstate.event":
394
- if (!actors.has(event.actorRef.sessionId)) handleActor(event.actorRef, rootActorId);
395
- handleEvent(event.actorRef.sessionId, event.event, event.sourceRef?.sessionId ?? null);
396
- pendingTransitions.set(event.actorRef.sessionId, createPendingTransition(event.actorRef, event.event, event.sourceRef));
412
+ case "@xstate.event": {
413
+ const sessionId = sessionIdOf(event.actorRef);
414
+ if (!actors.has(sessionId)) handleActor(event.actorRef, rootActorId);
415
+ handleEvent(sessionId, event.event, event.sourceRef ? sessionIdOf(event.sourceRef) : null);
416
+ pendingTransitions.set(sessionId, createPendingTransition(event.actorRef, event.event, event.sourceRef));
397
417
  break;
418
+ }
398
419
  case "@xstate.action":
399
420
  getPendingTransition(event.actorRef).actions.push(normalizeAction(event.action));
400
421
  break;
@@ -409,9 +430,9 @@ function createInspector(options = {}) {
409
430
  case "@xstate.transition":
410
431
  if (!event.actions || !event.microsteps || !event.sent) break;
411
432
  handleTransition(event.actorRef, event.snapshot, event.event, rootActorId, {
412
- previousSnapshot: actors.get(event.actorRef.sessionId)?.snapshot ?? null,
433
+ previousSnapshot: actors.get(sessionIdOf(event.actorRef))?.snapshot ?? null,
413
434
  event: event.event,
414
- sourceSessionId: event.sourceRef?.sessionId ?? null,
435
+ sourceSessionId: event.sourceRef ? sessionIdOf(event.sourceRef) : null,
415
436
  actions: event.actions.map(normalizeAction),
416
437
  transitions: event.microsteps.map(normalizeTakenTransition),
417
438
  sent: event.sent.map(normalizeSentEvent)
@@ -423,9 +444,10 @@ function createInspector(options = {}) {
423
444
  }
424
445
  function attachActor(actor) {
425
446
  const root = actor;
426
- const rootActorId = root.sessionId;
447
+ const rootActorId = sessionIdOf(root);
427
448
  const existing = inspectedRoots.get(rootActorId);
428
449
  if (existing) return existing.subscription;
450
+ resolveActorTreeSessionIds(root);
429
451
  observedRootIds.add(rootActorId);
430
452
  const subscription = root.system.inspect(handleInspectionEvent);
431
453
  inspectedRoots.set(rootActorId, {
@@ -443,8 +465,12 @@ function createInspector(options = {}) {
443
465
  return manualSessionIds.get(actorId) ?? `${producerId}:${actorId}`;
444
466
  }
445
467
  function manualRegister(id, opts) {
468
+ const existingManualSessionId = manualSessionIds.get(id);
446
469
  const sessionId = getManualSessionId(id);
447
- if (actors.has(sessionId)) return;
470
+ if (actors.has(sessionId)) {
471
+ if (existingManualSessionId === sessionId) return;
472
+ throw new Error(`createInspector(): manual actor session id "${sessionId}" conflicts with a resolved actor session id.`);
473
+ }
448
474
  manualSessionIds.set(id, sessionId);
449
475
  const parentSessionId = opts?.parent ? getManualSessionId(opts.parent) : null;
450
476
  const entry = {
@@ -565,6 +591,7 @@ function createInspector(options = {}) {
565
591
  exportManager.clear("Inspector destroyed");
566
592
  events.clear();
567
593
  actors.clear();
594
+ actorsByResolvedSessionId.clear();
568
595
  inspectedRoots.clear();
569
596
  observedRootIds.clear();
570
597
  pendingTransitions.clear();