@statelyai/sdk 0.22.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -240,10 +240,11 @@ may be producer-resolved. A room uses `producerId + sessionId` as the global
240
240
  actor identity.
241
241
  Observations captured before the first transport registration replay in order
242
242
  after the initial actor-tree baseline. Reconnects use the latest checkpoint.
243
- In Node, the inspector opens in the default browser automatically. The SDK
244
- connects to `wss://sky.stately.ai` and generates a UUID v4 `?r=` room bearer
245
- capability. Multiple producers and viewers can share that room. Anyone with the
246
- URL can inspect its data, so keep it private. Hosted replay expires after 24
243
+ The SDK connects to `wss://sky.stately.ai`, logs the inspector URL, and does not
244
+ open a browser by default. Pass `launch: 'browser'` to open it explicitly from
245
+ Node. It generates a UUID v4 `?r=` room bearer capability. Multiple producers
246
+ and viewers can share that room. Anyone with the URL can inspect its data, so
247
+ keep it private. Hosted replay expires after 24
247
248
  hours without activity. Only actor checkpoints and observations are replayed;
248
249
  export traffic is live-only, and auth/upload/embed-control messages are rejected.
249
250
  AI-backed features remain separately authenticated.
@@ -258,8 +259,11 @@ and request metadata. A source origin can identify a site or customer, so this
258
259
  is operational telemetry rather than anonymous data. Pass a self-hosted `url`
259
260
  to opt out of Stately-hosted collection.
260
261
 
261
- Set `autoOpen: false`, await `inspector.ready`, and navigate to
262
- `inspector.inspectorUrl` when a test runner or another process owns the browser.
262
+ `inspector.inspectorUrl` is available immediately. Await `inspector.ready` when
263
+ the next step depends on successful relay registration, or listen for the
264
+ `connected` event when reconnects matter. The default `launch: 'none'` is safe
265
+ for test runners, automation, and CI; pass `launch: 'browser'` only when the SDK
266
+ should open the default browser from Node.
263
267
  `inspectorBaseUrl` targets an inspector UI hosted separately from the WebSocket
264
268
  relay. An explicit `url` wins over `STATELY_INSPECT_URL`, which wins over the
265
269
  hosted default. See `@statelyai/sdk/protocol` for the versioned message and
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-yzel-kpS.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-D3ug8VHa.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
3
 
4
4
  //#region src/embed.ts
package/dist/index.d.mts CHANGED
@@ -6,7 +6,7 @@ import { AssetUploadAdapter, AssetUploadContext, AssetUploadRequest, CreateS3Ass
6
6
  import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
7
7
  import { c as fetchEditorSyncAccess, d as EditorHostInboundMessage, f as EditorHostInitOptions, i as EditorSyncBackend, l as EDITOR_PROTOCOL_VERSION, m as EditorHostValidationIssue, n as EditorHostSessionOptions, o as RemoteEditorSyncBackendOptions, p as EditorHostOutboundMessage, r as EditorSourceHost, s as createRemoteEditorSyncBackend, t as EditorHostSession, u as EditorHostExportFormat } from "./editorHostSession-CMwC9KKh.mjs";
8
8
  import { AssetConfig, EmbedEntity, EmbedFormatContext, EmbedFormatDefinition, EmbedGraph, EmbedProfileDefinition, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.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";
9
+ import { _ as createWebSocketTransport, a as InspectedTransition, c as InspectorDiscoveryEntry, d as ManualActorOptions, f as createInspector, g as createPostMessageTransport, h as TransportFailure, i as InspectedSnapshot, l as InspectorEvents, m as Transport, n as CreateInspectorOptions, o as Inspector, p as createStatelyInspector, r as InspectedEvent, s as InspectorConnection, t as AdoptedActor, u as InspectorInspectionEvent } from "./inspect-Br_vS_lK.mjs";
10
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-CkrbMK00.mjs";
11
11
  import { OAuthAuthorizationServerMetadata, OAuthClientRegistrationResponse, OAuthProtectedResourceMetadata, OAuthTokenResponse, PkcePair, buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
12
12
  import { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
@@ -33,4 +33,4 @@ declare function findStatelyPragmaAttachments(sourceText: string, fileName?: str
33
33
  declare function getStatelyPragma(sourceText: string, fileName?: string, machineIndex?: number): StatelyPragma | undefined;
34
34
  declare function upsertStatelyPragma(sourceText: string, id: string, options?: UpsertStatelyPragmaOptions): string;
35
35
  //#endregion
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 EmbedEntity, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedFormatContext, type EmbedFormatDefinition, type EmbedGraph, type EmbedMode, type EmbedProfileDefinition, 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 };
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 EmbedEntity, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedFormatContext, type EmbedFormatDefinition, type EmbedGraph, type EmbedMode, type EmbedProfileDefinition, 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 InspectorConnection, type InspectorDiscoveryEntry, 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,13 +1,13 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
2
  import { EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
3
- import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-yzel-kpS.mjs";
3
+ import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-D3ug8VHa.mjs";
4
4
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
5
5
  import { createStatelyEmbed } from "./embed.mjs";
6
6
  import { i as fetchEditorSyncAccess, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-BZE_Wm0m.mjs";
7
7
  import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-iNSHtNmP.mjs";
8
- import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, l as graphToMachineConfig, m as serializeJS, n as getStatelyPragma, o as contextSchemaToTSType, p as raw, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-DfKQ-kPr.mjs";
8
+ import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, l as graphToMachineConfig, m as serializeJS, n as getStatelyPragma, o as contextSchemaToTSType, p as raw, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-0djA1cnm.mjs";
9
9
  import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
10
- import { n as createStatelyInspector, t as createInspector } from "./inspect-CXkNcKu4.mjs";
10
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-Bz3dcNBH.mjs";
11
11
  import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
12
12
  import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
13
13
  import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
@@ -100,7 +100,16 @@ interface InspectedEvent {
100
100
  sourceSessionId: string | null;
101
101
  event: unknown;
102
102
  }
103
+ interface InspectorConnection {
104
+ inspectorUrl: string | null;
105
+ relayUrl: string | null;
106
+ roomId: string;
107
+ producerId: string;
108
+ }
109
+ /** Browser-page discovery metadata consumed by the Stately DevTools extension. */
110
+ type InspectorDiscoveryEntry = InspectorConnection;
103
111
  interface InspectorEvents {
112
+ connected: InspectorConnection;
104
113
  actor: AdoptedActor;
105
114
  event: InspectedEvent;
106
115
  snapshot: InspectedSnapshot;
@@ -148,7 +157,9 @@ interface CreateInspectorOptions {
148
157
  * is derived from the relay URL by replacing `ws` with `http`.
149
158
  */
150
159
  inspectorBaseUrl?: string;
151
- /** Auto-open browser to visualizer. Default: `true`. */
160
+ /** How to launch the inspector UI. Defaults to `none` in every runtime. */
161
+ launch?: 'none' | 'browser';
162
+ /** @deprecated Use `launch: 'browser'` or `launch: 'none'`. */
152
163
  autoOpen?: boolean;
153
164
  /**
154
165
  * Legacy name for the unguessable room capability.
@@ -260,4 +271,4 @@ declare function createInspector(options?: CreateInspectorOptions): Inspector;
260
271
  /** @deprecated Use {@link createInspector}. */
261
272
  declare const createStatelyInspector: typeof createInspector;
262
273
  //#endregion
263
- export { InspectedTransition as a, InspectorInspectionEvent as c, createStatelyInspector as d, Transport as f, createWebSocketTransport as h, InspectedSnapshot as i, ManualActorOptions as l, createPostMessageTransport as m, CreateInspectorOptions as n, Inspector as o, TransportFailure as p, InspectedEvent as r, InspectorEvents as s, AdoptedActor as t, createInspector as u };
274
+ export { createWebSocketTransport as _, InspectedTransition as a, InspectorDiscoveryEntry as c, ManualActorOptions as d, createInspector as f, createPostMessageTransport as g, TransportFailure as h, InspectedSnapshot as i, InspectorEvents as l, Transport as m, CreateInspectorOptions as n, Inspector as o, createStatelyInspector as p, InspectedEvent as r, InspectorConnection as s, AdoptedActor as t, InspectorInspectionEvent as u };
@@ -1,9 +1,9 @@
1
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-yzel-kpS.mjs";
2
+ import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-D3ug8VHa.mjs";
3
3
 
4
4
  //#region src/openBrowser.ts
5
5
  async function openBrowser(url) {
6
- if (typeof process === "undefined" || !process.versions?.node || typeof process.getBuiltinModule !== "function") return;
6
+ if (typeof process === "undefined" || !process.versions?.node || typeof process.getBuiltinModule !== "function") throw new Error("Opening a browser is not supported in this runtime.");
7
7
  const { spawn } = process.getBuiltinModule("node:child_process");
8
8
  const child = spawn(process.platform === "darwin" ? "open" : process.platform === "win32" ? "powershell.exe" : "xdg-open", process.platform === "win32" ? [
9
9
  "-NoProfile",
@@ -37,6 +37,19 @@ function isStoppedSnapshot(snapshot) {
37
37
  const status = snapshot?.status;
38
38
  return status === "done" || status === "stopped" || status === "error";
39
39
  }
40
+ const browserInspectorRegistryKey = "__statelyInspectorsV1";
41
+ function isBrowserRuntime() {
42
+ return typeof window !== "undefined" && window === globalThis;
43
+ }
44
+ function getBrowserInspectorRegistry() {
45
+ const global = globalThis;
46
+ if (!global.__statelyInspectorsV1) Object.defineProperty(global, browserInspectorRegistryKey, {
47
+ value: /* @__PURE__ */ new Map(),
48
+ enumerable: false,
49
+ configurable: true
50
+ });
51
+ return global.__statelyInspectorsV1;
52
+ }
40
53
  function generateRoomId() {
41
54
  if (!globalThis.crypto?.randomUUID) throw new Error("createInspector() requires crypto.randomUUID() to generate a secure room capability. Pass roomId explicitly in older runtimes.");
42
55
  return globalThis.crypto.randomUUID();
@@ -44,7 +57,8 @@ function generateRoomId() {
44
57
  function createInspector(options = {}) {
45
58
  const environmentUrl = typeof process !== "undefined" ? process.env?.STATELY_INSPECT_URL : void 0;
46
59
  const url = options.url ?? environmentUrl ?? "wss://sky.stately.ai";
47
- const { inspectorBaseUrl, autoOpen = true, name, serializeSnapshot = defaultSerializeSnapshot, selectedSessionId: configuredSelectedSessionId, selectedActorId, panels, theme, readOnly, depth, capabilities, transport: injectedTransport } = options;
60
+ const { inspectorBaseUrl, name, serializeSnapshot = defaultSerializeSnapshot, selectedSessionId: configuredSelectedSessionId, selectedActorId, panels, theme, readOnly, depth, capabilities, transport: injectedTransport } = options;
61
+ const launch = options.launch ?? (options.autoOpen === true ? "browser" : "none");
48
62
  const extractMachine = options.extractMachine ?? options.extractMachineConfig ?? defaultExtractMachineConfig;
49
63
  const roomId = options.roomId ?? options.sessionId ?? getInspectionRoomId(url) ?? generateRoomId();
50
64
  const producerId = options.producerId ?? generateRoomId();
@@ -55,13 +69,24 @@ function createInspector(options = {}) {
55
69
  });
56
70
  const relayUrl = roomUrls?.relayUrl ?? null;
57
71
  const inspectorUrl = roomUrls?.inspectorUrl ?? null;
72
+ const connection = {
73
+ inspectorUrl,
74
+ relayUrl,
75
+ roomId,
76
+ producerId
77
+ };
58
78
  const displayName = name ?? "system:manual";
79
+ if (inspectorUrl && launch === "none") console.info(`[Stately Inspector] ${inspectorUrl}`);
80
+ const browserRegistry = isBrowserRuntime() ? getBrowserInspectorRegistry() : void 0;
81
+ browserRegistry?.set(producerId, connection);
82
+ const browserLaunchUnsupported = launch === "browser" && isBrowserRuntime();
83
+ if (browserLaunchUnsupported) console.warn("createInspector({ launch: 'browser' }) cannot open a browser from a browser runtime. Open inspectorUrl from a user gesture or use the Stately DevTools extension.");
59
84
  let destroyed = false;
60
85
  let initSent = false;
61
86
  let initialized = false;
62
87
  let pendingTransportReady = false;
63
88
  let transportWasReady = false;
64
- let didAutoOpen = false;
89
+ let didLaunch = false;
65
90
  let resolveReady;
66
91
  let rejectReady;
67
92
  let readySettled = false;
@@ -106,8 +131,20 @@ function createInspector(options = {}) {
106
131
  initSent = false;
107
132
  sendInit();
108
133
  }
109
- if (autoOpen && !didAutoOpen && ownsTransport) {
110
- didAutoOpen = true;
134
+ queueMicrotask(() => {
135
+ if (!destroyed) emitLocal("connected", connection);
136
+ });
137
+ if (launch === "browser" && !didLaunch && ownsTransport) {
138
+ didLaunch = true;
139
+ if (browserLaunchUnsupported) {
140
+ const failure = {
141
+ code: "unsupported_launch",
142
+ message: "createInspector({ launch: 'browser' }) is unsupported in browser runtimes."
143
+ };
144
+ emitLocal("error", failure);
145
+ events.emit("error", failure);
146
+ return;
147
+ }
111
148
  if (inspectorUrl) openBrowser(inspectorUrl).catch((error) => {
112
149
  const failure = {
113
150
  code: "open_failed",
@@ -581,6 +618,7 @@ function createInspector(options = {}) {
581
618
  destroy() {
582
619
  if (destroyed) return;
583
620
  destroyed = true;
621
+ if (browserRegistry?.get(producerId) === connection) browserRegistry.delete(producerId);
584
622
  try {
585
623
  for (const { subscription } of inspectedRoots.values()) subscription.unsubscribe();
586
624
  } catch {}
@@ -1,3 +1,3 @@
1
1
  import { EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InspectionAction, InspectionSentEvent, InspectionTakenTransition } from "./protocol.mjs";
2
- import { a as InspectedTransition, c as InspectorInspectionEvent, d as createStatelyInspector, f as Transport, i as InspectedSnapshot, l as ManualActorOptions, n as CreateInspectorOptions, o as Inspector, r as InspectedEvent, s as InspectorEvents, t as AdoptedActor, u as createInspector } from "./inspect-CGJR4iZK.mjs";
3
- export { AdoptedActor, CreateInspectorOptions, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InspectedEvent, InspectedSnapshot, InspectedTransition, InspectionAction, InspectionSentEvent, InspectionTakenTransition, Inspector, InspectorEvents, InspectorInspectionEvent, ManualActorOptions, Transport, createInspector, createStatelyInspector };
2
+ import { a as InspectedTransition, c as InspectorDiscoveryEntry, d as ManualActorOptions, f as createInspector, i as InspectedSnapshot, l as InspectorEvents, m as Transport, n as CreateInspectorOptions, o as Inspector, p as createStatelyInspector, r as InspectedEvent, s as InspectorConnection, t as AdoptedActor, u as InspectorInspectionEvent } from "./inspect-Br_vS_lK.mjs";
3
+ export { AdoptedActor, CreateInspectorOptions, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InspectedEvent, InspectedSnapshot, InspectedTransition, InspectionAction, InspectionSentEvent, InspectionTakenTransition, Inspector, InspectorConnection, InspectorDiscoveryEntry, InspectorEvents, InspectorInspectionEvent, ManualActorOptions, Transport, createInspector, createStatelyInspector };
package/dist/inspect.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./version-yzel-kpS.mjs";
2
- import { n as createStatelyInspector, t as createInspector } from "./inspect-CXkNcKu4.mjs";
1
+ import "./version-D3ug8VHa.mjs";
2
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-Bz3dcNBH.mjs";
3
3
 
4
4
  export { createInspector, createStatelyInspector };
@@ -4077,10 +4077,13 @@ function collectBindings(file) {
4077
4077
  }
4078
4078
  function isCreateMachineCall(node) {
4079
4079
  const expression = node.expression;
4080
- if (ts.isIdentifier(expression)) return expression.text === "createMachine";
4081
- if (ts.isPropertyAccessExpression(expression)) return expression.name.text === "createMachine";
4080
+ if (ts.isIdentifier(expression)) return isMachineFactoryName(expression.text);
4081
+ if (ts.isPropertyAccessExpression(expression)) return isMachineFactoryName(expression.name.text);
4082
4082
  return false;
4083
4083
  }
4084
+ function isMachineFactoryName(name) {
4085
+ return name === "createMachine" || name === "createMachineFromConfig";
4086
+ }
4084
4087
  function setupCallForCreateMachine(node, bindings) {
4085
4088
  if (!ts.isPropertyAccessExpression(node.expression)) return null;
4086
4089
  let receiver = unwrapExpression(node.expression.expression);
@@ -4140,6 +4143,10 @@ function hasV6Syntax(source) {
4140
4143
  }
4141
4144
  function visitMachineCalls(node) {
4142
4145
  if (ts.isCallExpression(node) && isCreateMachineCall(node)) {
4146
+ if ((ts.isIdentifier(node.expression) ? node.expression.text : ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : void 0) === "createMachineFromConfig") {
4147
+ found = true;
4148
+ return;
4149
+ }
4143
4150
  const config = node.arguments[0];
4144
4151
  if (config) visitSyntax(config);
4145
4152
  const setupConfig = setupCallForCreateMachine(node, bindings)?.arguments[0];
package/dist/sync.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
2
  import { r as createStatelyClient } from "./studio-iNSHtNmP.mjs";
3
- import { f as normalizeMachineProfile, h as xstateSourceToConfig, i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as serializeJS, n as getStatelyPragma, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-DfKQ-kPr.mjs";
3
+ import { f as normalizeMachineProfile, h as xstateSourceToConfig, i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as serializeJS, n as getStatelyPragma, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-0djA1cnm.mjs";
4
4
  import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
5
5
  import * as ts$1 from "typescript";
6
6
  import ts from "typescript";
@@ -704,7 +704,8 @@ function getEnumMemberName(name) {
704
704
  return null;
705
705
  }
706
706
  function isCreateMachineExpression$1(expression) {
707
- return ts$1.isIdentifier(expression) && expression.text === "createMachine" || ts$1.isPropertyAccessExpression(expression) && expression.name.text === "createMachine";
707
+ const isMachineFactoryName = (name) => name === "createMachine" || name === "createMachineFromConfig";
708
+ return ts$1.isIdentifier(expression) && isMachineFactoryName(expression.text) || ts$1.isPropertyAccessExpression(expression) && isMachineFactoryName(expression.name.text);
708
709
  }
709
710
  function unwrapObjectLiteralExpression(expression) {
710
711
  const unwrapped = unwrapExpression$1(expression);
@@ -331,7 +331,7 @@ function createWebSocketTransport(options) {
331
331
 
332
332
  //#endregion
333
333
  //#region src/version.ts
334
- const SDK_VERSION = "0.22.1";
334
+ const SDK_VERSION = "0.23.0";
335
335
  function inspectionRuntime() {
336
336
  if (typeof window !== "undefined") return "browser";
337
337
  if (typeof process !== "undefined" && process.versions?.node) return "node";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/sdk",
3
- "version": "0.22.1",
3
+ "version": "0.23.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "stately-sdk": "./dist/bin.mjs"
@@ -93,8 +93,8 @@
93
93
  "jsdom": "^27.4.0",
94
94
  "tsdown": "0.21.0-beta.2",
95
95
  "vitest": "^3.2.4",
96
- "@statelyai/api-contract": "0.3.7",
97
- "@statelyai/graph-tools": "0.2.1"
96
+ "@statelyai/api-contract": "0.3.8",
97
+ "@statelyai/graph-tools": "0.2.2"
98
98
  },
99
99
  "engines": {
100
100
  "node": ">=22.4"