@statelyai/sdk 0.22.0 → 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
@@ -94,6 +94,9 @@ CLI and editor-extension hosts use `EditorHostSession` from
94
94
  clipboard requests, and editor protocol negotiation. Use
95
95
  `createRemoteEditorSyncBackend` for two-way validation of the versioned Editor
96
96
  Sync HTTP contract.
97
+ Remote authentication failures are surfaced as `EditorSyncError` with HTTP
98
+ status and protocol error code metadata so hosts can refresh credentials and
99
+ retry once without depending on response-message text.
97
100
  Hosts keep ownership of files, credentials, UI, and transport adapters.
98
101
 
99
102
  Key capabilities:
@@ -237,10 +240,11 @@ may be producer-resolved. A room uses `producerId + sessionId` as the global
237
240
  actor identity.
238
241
  Observations captured before the first transport registration replay in order
239
242
  after the initial actor-tree baseline. Reconnects use the latest checkpoint.
240
- In Node, the inspector opens in the default browser automatically. The SDK
241
- connects to `wss://sky.stately.ai` and generates a UUID v4 `?r=` room bearer
242
- capability. Multiple producers and viewers can share that room. Anyone with the
243
- 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
244
248
  hours without activity. Only actor checkpoints and observations are replayed;
245
249
  export traffic is live-only, and auth/upload/embed-control messages are rejected.
246
250
  AI-backed features remain separately authenticated.
@@ -255,8 +259,11 @@ and request metadata. A source origin can identify a site or customer, so this
255
259
  is operational telemetry rather than anonymous data. Pass a self-hosted `url`
256
260
  to opt out of Stately-hosted collection.
257
261
 
258
- Set `autoOpen: false`, await `inspector.ready`, and navigate to
259
- `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.
260
267
  `inspectorBaseUrl` targets an inspector UI hosted separately from the WebSocket
261
268
  relay. An explicit `url` wins over `STATELY_INSPECT_URL`, which wins over the
262
269
  hosted default. See `@statelyai/sdk/protocol` for the versioned message and
@@ -4,6 +4,10 @@ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs"
4
4
  //#region ../api-contract/dist/editor-sync.mjs
5
5
  const EDITOR_SYNC_PROTOCOL_VERSION = 1;
6
6
  const EDITOR_SYNC_PROTOCOL_HEADER = "X-Stately-Editor-Sync-Version";
7
+ const editorSyncErrorResponseSchema = object({
8
+ error: string(),
9
+ code: string().optional()
10
+ }).passthrough();
7
11
  const editorCapabilitiesSchema = object({
8
12
  edit: boolean().optional(),
9
13
  export: boolean().optional(),
@@ -102,6 +106,16 @@ const editorSyncAccessResponseSchema = object({ access: editorSyncAccessSchema }
102
106
 
103
107
  //#endregion
104
108
  //#region src/editorHostSession.ts
109
+ var EditorSyncError = class extends Error {
110
+ status;
111
+ code;
112
+ constructor(message, status, code) {
113
+ super(message);
114
+ this.name = "EditorSyncError";
115
+ this.status = status;
116
+ this.code = code;
117
+ }
118
+ };
105
119
  function createRemoteEditorSyncBackend(options) {
106
120
  const fetchImpl = options.fetch ?? globalThis.fetch;
107
121
  async function post(pathname, body) {
@@ -118,10 +132,7 @@ function createRemoteEditorSyncBackend(options) {
118
132
  });
119
133
  assertEditorSyncResponseProtocol(response);
120
134
  const data = await response.json().catch(() => null);
121
- if (!response.ok) {
122
- const message = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : `HTTP ${response.status}`;
123
- throw new Error(message);
124
- }
135
+ if (!response.ok) throwEditorSyncError(response.status, data);
125
136
  return data;
126
137
  }
127
138
  return {
@@ -144,12 +155,14 @@ async function fetchEditorSyncAccess(options) {
144
155
  });
145
156
  assertEditorSyncResponseProtocol(response);
146
157
  const data = await response.json().catch(() => null);
147
- if (!response.ok) {
148
- const message = data && typeof data === "object" && "error" in data && typeof data.error === "string" ? data.error : `HTTP ${response.status}`;
149
- throw new Error(message);
150
- }
158
+ if (!response.ok) throwEditorSyncError(response.status, data);
151
159
  return editorSyncAccessResponseSchema.parse(data).access;
152
160
  }
161
+ function throwEditorSyncError(status, data) {
162
+ const parsed = editorSyncErrorResponseSchema.safeParse(data);
163
+ const error = parsed.success ? parsed.data : void 0;
164
+ throw new EditorSyncError(error?.error ?? `HTTP ${status}`, status, error?.code);
165
+ }
153
166
  function assertEditorSyncResponseProtocol(response) {
154
167
  const selectedVersion = response.headers.get(EDITOR_SYNC_PROTOCOL_HEADER);
155
168
  if (selectedVersion === null || selectedVersion === String(EDITOR_SYNC_PROTOCOL_VERSION)) return;
@@ -476,4 +489,4 @@ function stateSourceLocationUris(sourceLocations) {
476
489
  }
477
490
 
478
491
  //#endregion
479
- export { createRemoteEditorSyncBackend as n, fetchEditorSyncAccess as r, EditorHostSession as t };
492
+ export { fetchEditorSyncAccess as i, EditorSyncError as n, createRemoteEditorSyncBackend as r, EditorHostSession as t };
@@ -125,6 +125,11 @@ interface RemoteEditorSyncBackendOptions {
125
125
  apiKey?: string;
126
126
  fetch?: typeof globalThis.fetch;
127
127
  }
128
+ declare class EditorSyncError extends Error {
129
+ readonly status: number;
130
+ readonly code: string | undefined;
131
+ constructor(message: string, status: number, code?: string);
132
+ }
128
133
  declare function createRemoteEditorSyncBackend(options: RemoteEditorSyncBackendOptions): EditorSyncBackend;
129
134
  declare function fetchEditorSyncAccess(options: RemoteEditorSyncBackendOptions): Promise<EditorSyncAccess>;
130
135
  interface EditorSourceHost {
@@ -181,4 +186,4 @@ declare class EditorHostSession {
181
186
  private resolveRetrieved;
182
187
  }
183
188
  //#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 };
189
+ export { EditorSyncError as a, fetchEditorSyncAccess as c, EditorHostInboundMessage as d, EditorHostInitOptions as f, EditorSyncBackend as i, EDITOR_PROTOCOL_VERSION as l, EditorHostValidationIssue as m, EditorHostSessionOptions as n, RemoteEditorSyncBackendOptions as o, EditorHostOutboundMessage as p, EditorSourceHost as r, createRemoteEditorSyncBackend as s, EditorHostSession as t, EditorHostExportFormat as u };
@@ -1,2 +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-lL7wPLnL.mjs";
2
- export { EDITOR_PROTOCOL_VERSION, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorSourceHost, EditorSyncBackend, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
1
+ import { a as EditorSyncError, 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";
2
+ export { EDITOR_PROTOCOL_VERSION, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorSourceHost, EditorSyncBackend, EditorSyncError, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
@@ -1,5 +1,5 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
- import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-HRuIaZ2G.mjs";
3
+ import { i as fetchEditorSyncAccess, n as EditorSyncError, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-BZE_Wm0m.mjs";
4
4
 
5
- export { EDITOR_PROTOCOL_VERSION, EditorHostSession, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
5
+ export { EDITOR_PROTOCOL_VERSION, EditorHostSession, EditorSyncError, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
package/dist/embed.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as ProfileManifest } from "./index-Bakx1tkW.mjs";
2
- import { i as StatelyGraph } from "./graph-DYjfFztq.mjs";
1
+ import { i as ProfileManifest } from "./index-D_pO_Pr8.mjs";
2
+ import { i as StatelyGraph } from "./graph-1fwR0Ynl.mjs";
3
3
  import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedExtensionsManifest, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, UploadResult } from "./protocol.mjs";
4
4
  import { AssetUploadAdapter } from "./assetStorage.mjs";
5
5
 
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-3cKMfysA.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
@@ -1,4 +1,4 @@
1
- import { t as CodeExpression } from "./index-Bakx1tkW.mjs";
1
+ import { t as CodeExpression } from "./index-D_pO_Pr8.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-DYjfFztq.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-1fwR0Ynl.mjs";
2
2
  export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };
@@ -2547,7 +2547,7 @@ declare const graphPatchSchema: ZodDiscriminatedUnion<[ZodObject<{
2547
2547
  type GraphPatch = output<typeof graphPatchSchema>;
2548
2548
  /** AI-only schema: semantic ops + shared ops (no generic graph ops) */
2549
2549
  //#endregion
2550
- //#region ../../node_modules/.pnpm/xstate@6.0.0-alpha.24/node_modules/xstate/dist/declarations/src/index.d.ts
2550
+ //#region ../../node_modules/.pnpm/xstate@6.0.0-alpha.47/node_modules/xstate/dist/declarations/src/index.d.ts
2551
2551
  declare global {
2552
2552
  interface SymbolConstructor {
2553
2553
  readonly observable: symbol;
package/dist/index.d.mts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
2
- import { _ as GraphPatch, a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, m as ActionLocation, n as CodeGenGraph, o as XStateTSOptions, p as serializeJS, r as MachineConfigOptions, s as contextSchemaToTSType, u as graphToXStateTS } from "./index-Bakx1tkW.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-DYjfFztq.mjs";
2
+ import { _ as GraphPatch, a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, m as ActionLocation, n as CodeGenGraph, o as XStateTSOptions, p as serializeJS, r as MachineConfigOptions, s as contextSchemaToTSType, u as graphToXStateTS } from "./index-D_pO_Pr8.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-1fwR0Ynl.mjs";
4
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
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-lL7wPLnL.mjs";
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";
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-DYI613t_.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
+ 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";
13
13
  import { CreateInspectionRelayOptions, InspectionRelay, InspectionRelayEffect, InspectionRelayPeer, InspectionRelayRole, InspectionRelaySnapshot, createInspectionRelay } from "./relay.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-3cKMfysA.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
- import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-HRuIaZ2G.mjs";
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-CokFTPgT.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-DDl5w1sy.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-3cKMfysA.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-3cKMfysA.mjs";
2
- import { n as createStatelyInspector, t as createInspector } from "./inspect-DDl5w1sy.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 };
@@ -1,2 +1,2 @@
1
- import { _ as GraphPatch, g as EditorStateType, h as CanvasColor, m as ActionLocation, v as ImplementationSourceType } from "./index-Bakx1tkW.mjs";
1
+ import { _ as GraphPatch, g as EditorStateType, h as CanvasColor, m as ActionLocation, v as ImplementationSourceType } from "./index-D_pO_Pr8.mjs";
2
2
  export { type ActionLocation, type CanvasColor, type EditorStateType, type GraphPatch, type ImplementationSourceType };
@@ -1,5 +1,5 @@
1
- import { i as ProfileManifest } from "./index-Bakx1tkW.mjs";
2
- import { i as StatelyGraph } from "./graph-DYjfFztq.mjs";
1
+ import { i as ProfileManifest } from "./index-D_pO_Pr8.mjs";
2
+ import { i as StatelyGraph } from "./graph-1fwR0Ynl.mjs";
3
3
  import { c as EditorSyncSourceLocation, f as MachineSourceLocations$1, l as EditorSyncSourceRange, t as EditorCapabilities$1, u as EditorSyncStateSourceLocation } from "./editor-sync-types-C-zWaaVk.mjs";
4
4
 
5
5
  //#region src/protocol.d.ts
@@ -1,6 +1,5 @@
1
1
  import { a as discriminatedUnion, c as object, d as union, 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 ts from "typescript";
3
- import "xstate";
4
3
  import "xstate/graph";
5
4
 
6
5
  //#region ../../node_modules/.pnpm/js-yaml@4.2.0/node_modules/js-yaml/dist/js-yaml.mjs
@@ -2472,7 +2471,7 @@ function stripExportDefault(code) {
2472
2471
  return trimmed;
2473
2472
  }
2474
2473
  const XSTATE_V5_PROFILE = "@statelyai/xstate@5.30.0";
2475
- const XSTATE_V6_PROFILE = "@statelyai/xstate@6.0.0-alpha.24";
2474
+ const XSTATE_V6_PROFILE = "@statelyai/xstate@6.0.0-alpha.47";
2476
2475
  const LEGACY_MACHINE_PROFILES = ["xstate-v5", "xstate-v6-alpha"];
2477
2476
  function normalizeMachineProfile(profile) {
2478
2477
  return profile === "xstate-v5" ? XSTATE_V5_PROFILE : profile === "xstate-v6-alpha" ? XSTATE_V6_PROFILE : profile;
@@ -2868,10 +2867,11 @@ function graphToMachineConfig(graph, options = {}) {
2868
2867
  Object.assign(nodeConfig, {
2869
2868
  id: resolvedNodeId,
2870
2869
  type: nodeType === "normal" ? void 0 : nodeType ?? void 0,
2871
- initial: initialNode ? node.data.initialInput !== void 0 ? {
2870
+ initial: initialNode ? nodeType === "history" ? void 0 : node.data.initialInput !== void 0 ? {
2872
2871
  target: initialNode.data.key,
2873
2872
  input: node.data.initialInput
2874
2873
  } : initialNode.data.key : void 0,
2874
+ target: nodeType === "history" && initialNode ? initialNode.data.key : void 0,
2875
2875
  ...node.data.timeout !== void 0 ? { timeout: node.data.timeout } : void 0,
2876
2876
  ...node.data.route !== void 0 ? { route: node.data.route } : void 0,
2877
2877
  ...node.data.entry?.length ? { entry: node.data.entry.map(serializeActionItem) } : void 0,
@@ -3817,10 +3817,28 @@ function guardParams(fn) {
3817
3817
  if (!param) return "()";
3818
3818
  return `(${param.getText()})`;
3819
3819
  }
3820
+ function transitionContextIdentity(fn) {
3821
+ const parameter = fn.parameters[0]?.name;
3822
+ if (!parameter) return null;
3823
+ if (ts.isIdentifier(parameter)) return `${parameter.text}.context`;
3824
+ if (!ts.isObjectBindingPattern(parameter)) return null;
3825
+ for (const element of parameter.elements) {
3826
+ if (!ts.isIdentifier(element.name)) continue;
3827
+ if ((element.propertyName ? propName(element.propertyName) : element.name.text) === "context") return element.name.text;
3828
+ }
3829
+ return null;
3830
+ }
3831
+ function omitIdentityTransitionContext(transition, identity) {
3832
+ const context = transition.context;
3833
+ if (!identity || !context || typeof context !== "object" || context["@type"] !== "code" || context.expr !== identity) return transition;
3834
+ const { context: _context, ...rest } = transition;
3835
+ return rest;
3836
+ }
3820
3837
  function normalizeFunctionTransition(fn, bindings, depth) {
3821
3838
  if (fn.body && ts.isBlock(fn.body) && hasUnsafeVariableInitializer(fn.body)) return fallbackFunctionTransition(fn);
3822
3839
  const branches = ts.isArrowFunction(fn) && !ts.isBlock(fn.body) ? expressionBranches(fn.body, bindings, depth + 1) : fn.body && ts.isBlock(fn.body) ? statementBranches(fn.body.statements, bindings, enqueueParamName(fn)) : [];
3823
3840
  if (branches.some((branch) => branch.unknown)) return fallbackFunctionTransition(fn);
3841
+ const contextIdentity = transitionContextIdentity(fn);
3824
3842
  const transitions = branches.map((branch) => {
3825
3843
  const transition = transitionFromValue(branch.result, branch.actions);
3826
3844
  if (!transition) return null;
@@ -3832,10 +3850,10 @@ function normalizeFunctionTransition(fn, bindings, depth) {
3832
3850
  } : transition;
3833
3851
  }
3834
3852
  const guard = guardFromConditions(branch.conds, guardParams(fn));
3835
- return guard ? {
3853
+ return omitIdentityTransitionContext(guard ? {
3836
3854
  ...transition,
3837
3855
  guard
3838
- } : transition;
3856
+ } : transition, contextIdentity);
3839
3857
  }).filter((transition) => Boolean(transition));
3840
3858
  if (transitions.length === 1) return transitions[0];
3841
3859
  if (transitions.length > 1) return transitions;
@@ -4059,10 +4077,13 @@ function collectBindings(file) {
4059
4077
  }
4060
4078
  function isCreateMachineCall(node) {
4061
4079
  const expression = node.expression;
4062
- if (ts.isIdentifier(expression)) return expression.text === "createMachine";
4063
- 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);
4064
4082
  return false;
4065
4083
  }
4084
+ function isMachineFactoryName(name) {
4085
+ return name === "createMachine" || name === "createMachineFromConfig";
4086
+ }
4066
4087
  function setupCallForCreateMachine(node, bindings) {
4067
4088
  if (!ts.isPropertyAccessExpression(node.expression)) return null;
4068
4089
  let receiver = unwrapExpression(node.expression.expression);
@@ -4122,6 +4143,10 @@ function hasV6Syntax(source) {
4122
4143
  }
4123
4144
  function visitMachineCalls(node) {
4124
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
+ }
4125
4150
  const config = node.arguments[0];
4126
4151
  if (config) visitSyntax(config);
4127
4152
  const setupConfig = setupCallForCreateMachine(node, bindings)?.arguments[0];
@@ -1,4 +1,4 @@
1
- import { A as output, C as ZodNumber, D as ZodString, E as ZodRecord, O as ZodUnion, S as ZodNullable, T as ZodOptional, b as ZodEnum, j as $strip, k as ZodUnknown, w as ZodObject, x as ZodLiteral, y as ZodArray } from "./index-Bakx1tkW.mjs";
1
+ import { A as output, C as ZodNumber, D as ZodString, E as ZodRecord, O as ZodUnion, S as ZodNullable, T as ZodOptional, b as ZodEnum, j as $strip, k as ZodUnknown, w as ZodObject, x as ZodLiteral, y as ZodArray } from "./index-D_pO_Pr8.mjs";
2
2
  import { n as StatelyCredential, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
3
3
 
4
4
  //#region ../api-contract/dist/errors.d.mts
package/dist/studio.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- 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, p as LegacyExtractMachinesOptions, 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-DYI613t_.mjs";
1
+ 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, p as LegacyExtractMachinesOptions, 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";
2
2
  export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, DEFAULT_STATELY_BASE_URL, EnsureProjectInput, ExtractMachinesInput, ExtractMachinesResponse, ExtractedMachine, ExtractedMachines, GetMachineOptions, LegacyExtractMachinesOptions, LegacyProjectVisibility, LegacyUpdateMachineInput, Machine, MachineVersion, Project, ProjectData, ProjectMachine, ProjectMachineSummary, ProjectSummary, ProjectVisibility, RepoType, ResourceErrorCode, StudioApiError, StudioApiErrorOptions, StudioClient, StudioClientOptions, StudioMachineRecord, StudioRequestOptions, UpdateMachineInput, UpdateProjectInput, VerifyApiKeyResponse, VerifyResult, XStateVersion, createStatelyClient };
package/dist/sync.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as DigraphConfig, i as StatelyGraph } from "./graph-DYjfFztq.mjs";
2
- import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-DYI613t_.mjs";
1
+ import { b as DigraphConfig, i as StatelyGraph } from "./graph-1fwR0Ynl.mjs";
2
+ import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-CkrbMK00.mjs";
3
3
  import { GraphDiff } from "@statelyai/graph";
4
4
 
5
5
  //#region src/sync.d.ts
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-CokFTPgT.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";
@@ -155,7 +155,10 @@ function collectXStateSourceLocations(sourceText, document, options = {}) {
155
155
  const rootProfile = detectXStateSourceProfile(sourceText);
156
156
  const referencedStateSymbols = new Set([...states, ...statesObjectLocations].map((state) => state.symbol).filter((symbol) => typeof symbol === "string"));
157
157
  const resolvedTransitionFunctions = collectResolvedTransitionFunctions(root, bindings);
158
- const inferredProfile = rootProfile === "xstate-v6-alpha" || resolvedTransitionFunctions.size > 0 || [...referencedStateSymbols].some((symbol) => detectXStateSourceProfile(bindings.get(symbol)?.sourceFile.text ?? "") === "xstate-v6-alpha") ? "xstate-v6-alpha" : rootProfile;
158
+ const inferredProfile = rootProfile === "xstate-v6-alpha" || resolvedTransitionFunctions.size > 0 || [...referencedStateSymbols].some((symbol) => {
159
+ const binding = bindings.get(symbol);
160
+ return binding?.kind === "createStateConfig" || detectXStateSourceProfile(binding?.sourceFile.text ?? "") === "xstate-v6-alpha";
161
+ }) ? "xstate-v6-alpha" : rootProfile;
159
162
  return {
160
163
  version: 1,
161
164
  profile: packageProfile?.profile ?? inferredProfile,
@@ -701,7 +704,8 @@ function getEnumMemberName(name) {
701
704
  return null;
702
705
  }
703
706
  function isCreateMachineExpression$1(expression) {
704
- 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);
705
709
  }
706
710
  function unwrapObjectLiteralExpression(expression) {
707
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.0";
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.0",
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.6",
97
- "@statelyai/graph-tools": "0.2.0"
96
+ "@statelyai/api-contract": "0.3.8",
97
+ "@statelyai/graph-tools": "0.2.2"
98
98
  },
99
99
  "engines": {
100
100
  "node": ">=22.4"