@statelyai/sdk 0.20.3 → 0.21.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
@@ -44,6 +44,13 @@ embed.init({
44
44
  });
45
45
  ```
46
46
 
47
+ Custom profiles and formats can be supplied when the embed is created. Their
48
+ serializable manifests are sent to the iframe; detector, importer, exporter,
49
+ and validator implementations remain in the host and are called asynchronously.
50
+ RPC methods and payloads are validated before host code runs, and malformed
51
+ graphs returned by custom importers are rejected.
52
+ Use `defaultProfile` and `defaultFormat` to choose the initial custom pair.
53
+
47
54
  Restrict an embed by passing a resolved access policy:
48
55
 
49
56
  <!-- restricted MachineInitOptions from src/protocol.ts -->
package/dist/embed.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { i as StatelyGraph } from "./graph-yDK-MM3G.mjs";
2
- import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, UploadResult } from "./protocol.mjs";
1
+ import { l as ProfileManifest } from "./index-BABex8NE.mjs";
2
+ import { i as StatelyGraph } from "./graph-B4WM_nYg.mjs";
3
+ import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedExtensionsManifest, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, UploadResult } from "./protocol.mjs";
3
4
  import { AssetUploadAdapter } from "./assetStorage.mjs";
4
5
 
5
6
  //#region src/embed.d.ts
@@ -29,6 +30,45 @@ interface AssetConfig {
29
30
  */
30
31
  maxFileSize?: number;
31
32
  }
33
+ type EmbedEntity = {
34
+ data?: Record<string, unknown>;
35
+ };
36
+ type EmbedGraph = EmbedEntity & {
37
+ nodes?: EmbedEntity[];
38
+ edges?: EmbedEntity[];
39
+ };
40
+ type EmbedFormatContext = {
41
+ profile: EmbedProfileDefinition;
42
+ resolveGraphData(graph: EmbedGraph): Record<string, unknown>;
43
+ resolveNodeData(node: EmbedEntity): Record<string, unknown>;
44
+ resolveEdgeData(edge: EmbedEntity): Record<string, unknown>;
45
+ };
46
+ type EmbedProfileDefinition = Omit<ProfileManifest, 'validation'> & {
47
+ validation?: Array<{
48
+ name: string;
49
+ description: string;
50
+ validate?(context: {
51
+ graph: EmbedGraph;
52
+ profile: ProfileManifest;
53
+ revision?: number;
54
+ resolveGraphData(graph: EmbedGraph): Record<string, unknown>;
55
+ resolveNodeData(node: EmbedEntity): Record<string, unknown>;
56
+ resolveEdgeData(edge: EmbedEntity): Record<string, unknown>;
57
+ }): unknown | Promise<unknown>;
58
+ }>;
59
+ };
60
+ type EmbedFormatDefinition = {
61
+ id: string;
62
+ name: string;
63
+ file?: {
64
+ extension?: string;
65
+ mediaType?: string;
66
+ };
67
+ editorLanguage?: string;
68
+ detect?(source: string): boolean | number | Promise<boolean | number>;
69
+ import?(source: string, context: EmbedFormatContext): unknown | Promise<unknown>;
70
+ export?(graph: EmbedGraph, context: EmbedFormatContext): unknown | Promise<unknown>;
71
+ };
32
72
  interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
33
73
  baseUrl: string;
34
74
  apiKey?: string;
@@ -49,6 +89,10 @@ interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
49
89
  commentsByMachineId?: Record<string, CommentsConfig>;
50
90
  /** Asset upload configuration. If omitted, files are stored as base64 data URLs. */
51
91
  assets?: AssetConfig;
92
+ profiles?: readonly EmbedProfileDefinition[];
93
+ formats?: readonly EmbedFormatDefinition[];
94
+ defaultProfile?: string;
95
+ defaultFormat?: string;
52
96
  onReady?: () => void;
53
97
  onLoaded?: (graph: StatelyGraph) => void;
54
98
  onChange?: (graph: StatelyGraph, machineConfig: unknown) => void;
@@ -91,4 +135,4 @@ interface StatelyEmbed {
91
135
  }
92
136
  declare function createStatelyEmbed(options: StatelyEmbedOptions): StatelyEmbed;
93
137
  //#endregion
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 };
138
+ export { AssetConfig, type CapabilityDeniedEvent, type CommentsConfig, type EditorCapabilities, type EmbedDocument, type EmbedDocumentLanguage, EmbedEntity, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedExtensionsManifest, EmbedFormatContext, EmbedFormatDefinition, EmbedGraph, type EmbedMode, EmbedProfileDefinition, 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,13 +1,73 @@
1
- import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-DoNMw8g6.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-CNeiHhaT.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
3
3
 
4
4
  //#region src/embed.ts
5
+ function isRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function isEmbedEntity(value) {
9
+ return isRecord(value) && isRecord(value.data);
10
+ }
11
+ function isEmbedGraph(value) {
12
+ return isRecord(value) && isRecord(value.data) && Array.isArray(value.nodes) && value.nodes.every(isEmbedEntity) && Array.isArray(value.edges) && value.edges.every(isEmbedEntity);
13
+ }
14
+ function assertExtensionCall(value) {
15
+ if (!isRecord(value)) throw new Error("Invalid extension request.");
16
+ if (typeof value.requestId !== "string" || typeof value.extensionId !== "string" || ![
17
+ "detect",
18
+ "import",
19
+ "export",
20
+ "validate"
21
+ ].includes(String(value.method)) || !isRecord(value.payload)) throw new Error("Invalid extension request.");
22
+ const payload = value.payload;
23
+ if ((value.method === "detect" || value.method === "import") && typeof payload.source !== "string") throw new Error("Invalid extension source payload.");
24
+ if ((value.method === "import" || value.method === "export") && typeof payload.profileId !== "string") throw new Error("Invalid extension profile payload.");
25
+ if ((value.method === "export" || value.method === "validate") && !isEmbedGraph(payload.graph)) throw new Error("Invalid extension graph payload.");
26
+ if (value.method === "validate" && payload.revision !== void 0 && typeof payload.revision !== "number") throw new Error("Invalid extension revision payload.");
27
+ }
5
28
  function buildEmbedUrl(options) {
6
29
  const base = options.baseUrl.replace(/\/+$/, "") + "/embed";
7
30
  const url = new URL(base);
8
31
  if (options.apiKey) url.searchParams.set("api_key", options.apiKey);
9
32
  return url.toString();
10
33
  }
34
+ function serializeExtensions(options) {
35
+ if (!options.profiles?.length && !options.formats?.length) return options.extensions;
36
+ return {
37
+ profiles: (options.profiles ?? []).map((profile) => ({
38
+ profile: profile.profile,
39
+ name: profile.name,
40
+ description: profile.description,
41
+ namespace: profile.namespace,
42
+ extends: profile.extends,
43
+ formats: profile.formats,
44
+ defaultFormat: profile.defaultFormat,
45
+ graph: profile.graph,
46
+ authoring: profile.authoring,
47
+ operations: profile.operations,
48
+ restrictFormatsToListed: profile.restrictFormatsToListed,
49
+ features: profile.features,
50
+ implementations: profile.implementations,
51
+ rules: profile.rules,
52
+ editorDefaults: profile.editorDefaults,
53
+ validation: profile.validation?.map(({ name, description }) => ({
54
+ name,
55
+ description
56
+ }))
57
+ })),
58
+ formats: (options.formats ?? []).map((format) => ({
59
+ id: format.id,
60
+ name: format.name,
61
+ file: format.file,
62
+ editorLanguage: format.editorLanguage,
63
+ detect: !!format.detect,
64
+ import: !!format.import,
65
+ export: !!format.export
66
+ })),
67
+ defaultProfile: options.defaultProfile,
68
+ defaultFormat: options.defaultFormat
69
+ };
70
+ }
11
71
  function extractInitOptions(options) {
12
72
  if (options.machines) return {
13
73
  machines: options.machines,
@@ -26,6 +86,7 @@ function extractInitOptions(options) {
26
86
  machine: options.machine,
27
87
  documents: options.documents,
28
88
  format: options.format,
89
+ extensions: serializeExtensions(options),
29
90
  mode: options.mode,
30
91
  theme: options.theme,
31
92
  readOnly: options.readOnly,
@@ -41,7 +102,7 @@ function extractInitOptions(options) {
41
102
  }
42
103
  function createStatelyEmbed(options) {
43
104
  const embedUrl = buildEmbedUrl(options);
44
- const targetOrigin = options.origin ?? "*";
105
+ const targetOrigin = options.origin ?? new URL(embedUrl).origin;
45
106
  let iframe = null;
46
107
  let transport = null;
47
108
  let ownedIframe = false;
@@ -49,6 +110,9 @@ function createStatelyEmbed(options) {
49
110
  let editorProtocolCompatible;
50
111
  const pendingMessages = [];
51
112
  const events = createEventRegistry();
113
+ const profiles = new Map((options.profiles ?? []).map((profile) => [profile.profile, profile]));
114
+ const formats = new Map((options.formats ?? []).map((format) => [format.id, format]));
115
+ const bundledExtensions = serializeExtensions(options);
52
116
  const exportManager = createPendingExportManager((message) => send(message));
53
117
  const assetUploadAdapter = options.assets?.adapter;
54
118
  const uploadAsset = options.assets?.onUploadRequest ? (file, context) => options.assets.onUploadRequest(file, context) : assetUploadAdapter ? (file, context) => assetUploadAdapter.upload({
@@ -72,9 +136,73 @@ function createStatelyEmbed(options) {
72
136
  transport.send(msg);
73
137
  }
74
138
  }
139
+ function formatContext(profile) {
140
+ const namespace = profile.namespace ?? /^(@[^/]+)\//.exec(profile.profile)?.[1];
141
+ if (!namespace) throw new Error(`Profile ${profile.profile} has no namespace.`);
142
+ const resolve = (data) => Object.fromEntries(Object.entries(data).filter(([key]) => key.startsWith(`${namespace}.`)).map(([key, value]) => [key.slice(namespace.length + 1), value]));
143
+ return {
144
+ profile,
145
+ resolveGraphData: (graph) => resolve(graph.data ?? {}),
146
+ resolveNodeData: (node) => resolve(node.data ?? {}),
147
+ resolveEdgeData: (edge) => resolve(edge.data ?? {})
148
+ };
149
+ }
150
+ async function handleExtensionCall(input) {
151
+ const requestId = isRecord(input) && typeof input.requestId === "string" ? input.requestId : void 0;
152
+ try {
153
+ assertExtensionCall(input);
154
+ const call = input;
155
+ const payload = call.payload;
156
+ let result;
157
+ if (call.method === "validate") {
158
+ const profile = profiles.get(call.extensionId);
159
+ if (!profile) throw new Error(`Unknown profile ${call.extensionId}.`);
160
+ const context = formatContext(profile);
161
+ result = (await Promise.all((profile.validation ?? []).filter((validator) => validator.validate).map((validator) => validator.validate({
162
+ graph: payload.graph,
163
+ revision: typeof payload.revision === "number" ? payload.revision : void 0,
164
+ ...context
165
+ })))).flat();
166
+ } else {
167
+ const format = formats.get(call.extensionId);
168
+ if (!format) throw new Error(`Unknown format ${call.extensionId}.`);
169
+ if (call.method === "detect") {
170
+ if (!format.detect) throw new Error("Format has no detector.");
171
+ result = await format.detect(String(payload.source ?? ""));
172
+ } else {
173
+ const profile = profiles.get(String(payload.profileId ?? ""));
174
+ if (!profile) throw new Error(`Unknown profile ${payload.profileId}.`);
175
+ const context = formatContext(profile);
176
+ if (call.method === "import") {
177
+ if (!format.import) throw new Error("Format has no importer.");
178
+ result = await format.import(payload.source, context);
179
+ if (!isEmbedGraph(result)) throw new Error("Format importer returned an invalid graph.");
180
+ } else {
181
+ if (!format.export) throw new Error("Format has no exporter.");
182
+ result = await format.export(payload.graph, context);
183
+ }
184
+ }
185
+ }
186
+ send({
187
+ type: "@statelyai.extension.result",
188
+ requestId: call.requestId,
189
+ result
190
+ });
191
+ } catch (error) {
192
+ if (!requestId) return;
193
+ send({
194
+ type: "@statelyai.extension.result",
195
+ requestId,
196
+ error: error instanceof Error ? error.message : String(error)
197
+ });
198
+ }
199
+ }
75
200
  function handleMessage(data) {
76
201
  if (destroyed) return;
77
202
  switch (data.type) {
203
+ case "@statelyai.extension.call":
204
+ handleExtensionCall(data);
205
+ break;
78
206
  case "@statelyai.ready": {
79
207
  const ready = data;
80
208
  if (ready.protocolVersion !== void 0) {
@@ -257,7 +385,10 @@ function createStatelyEmbed(options) {
257
385
  return el;
258
386
  },
259
387
  init(opts) {
260
- send(toInitMessage(opts));
388
+ send(toInitMessage("machine" in opts ? {
389
+ ...opts,
390
+ extensions: opts.extensions ?? bundledExtensions
391
+ } : opts));
261
392
  },
262
393
  updateMachine(machine, format, sourceLocations) {
263
394
  send({
@@ -1,4 +1,4 @@
1
- import { r as CodeExpression } from "./index-BAkQThnl.mjs";
1
+ import { r as CodeExpression } from "./index-BABex8NE.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-yDK-MM3G.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-B4WM_nYg.mjs";
2
2
  export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };
@@ -2451,6 +2451,70 @@ declare function raw(code: string): RawCode;
2451
2451
  declare function serializeJS(value: unknown, indent?: number, step?: number): string; //#endregion
2452
2452
  //#region src/profiles/xgraphMetadata.d.ts
2453
2453
  //#endregion
2454
+ //#region src/profiles/types.d.ts
2455
+ type FormatId = string;
2456
+ type ProfileFormatManifest = {
2457
+ format: FormatId;
2458
+ import?: boolean;
2459
+ export?: boolean;
2460
+ sourcePreserving?: boolean;
2461
+ warning?: string;
2462
+ };
2463
+ type ProfileEntityType = {
2464
+ kind: string;
2465
+ label: string;
2466
+ description?: string;
2467
+ authorable?: boolean;
2468
+ terminal?: boolean;
2469
+ canContain?: boolean; /** Logical, unnamespaced profile data stored canonically under the profile namespace. */
2470
+ dataSchema?: JSONSchema7;
2471
+ children?: {
2472
+ types: readonly string[];
2473
+ min?: number;
2474
+ max?: number;
2475
+ };
2476
+ };
2477
+ type ProfileValidationDefinition = {
2478
+ name: string;
2479
+ description: string;
2480
+ };
2481
+ type ProfileAuthoringManifest = {
2482
+ terminology: {
2483
+ node: string;
2484
+ edge: string;
2485
+ graph: string;
2486
+ };
2487
+ nodeTypes: readonly ProfileEntityType[];
2488
+ edgeTypes: readonly ProfileEntityType[];
2489
+ attachments?: Partial<Record<'actions' | 'guards' | 'invokes' | 'tags', boolean>>;
2490
+ supportsInitialNode?: boolean;
2491
+ supportsTargetlessEdges?: boolean;
2492
+ supportsReenterEdges?: boolean;
2493
+ };
2494
+ type ProfileManifest = {
2495
+ profile: ResolvedProfileRef;
2496
+ name: string;
2497
+ description?: string; /** Namespace for canonical profile data, for example `@mastra`. */
2498
+ namespace?: `@${string}`;
2499
+ extends?: ProfileSpecifier;
2500
+ formats: ProfileFormatManifest[];
2501
+ defaultFormat?: FormatId;
2502
+ graph?: {
2503
+ dataSchema?: JSONSchema7;
2504
+ }; /** Profile-owned editor vocabulary. The canvas itself only assumes a graph. */
2505
+ authoring?: ProfileAuthoringManifest;
2506
+ operations?: Partial<Record<'simulate' | 'validate' | 'export', boolean>>;
2507
+ restrictFormatsToListed?: boolean;
2508
+ features?: Record<string, boolean | Record<string, unknown>>;
2509
+ implementations?: Partial<Record<'actions' | 'guards' | 'actors' | 'delays', {
2510
+ mode: 'allowlist' | 'any';
2511
+ items: Record<string, Record<string, unknown>>;
2512
+ }>>;
2513
+ rules?: Array<Record<string, unknown>>;
2514
+ validation?: ProfileValidationDefinition[];
2515
+ editorDefaults?: Record<string, unknown>;
2516
+ };
2517
+ //#endregion
2454
2518
  //#region src/graphToXStateTS.d.ts
2455
2519
  interface XStateTSOptions extends MachineConfigOptions {
2456
2520
  exportStyle?: 'named' | 'default' | 'none';
@@ -2888,4 +2952,4 @@ declare const graphPatchSchema: ZodDiscriminatedUnion<[ZodObject<{
2888
2952
  type GraphPatch = output<typeof graphPatchSchema>;
2889
2953
  /** AI-only schema: semantic ops + shared ops (no generic graph ops) */
2890
2954
  //#endregion
2891
- export { $strip as A, ZodObject as C, ZodUnion as D, ZodString as E, ZodUnknown as O, ZodNumber as S, ZodRecord as T, serializeJS as _, EditorStateType as a, ZodLiteral as b, MachineConfigOptions as c, contextSchemaToTSType as d, eventsSchemaToTSType as f, raw as g, jsonSchemaToTSType as h, CodeGenGraph as i, output as k, RawCode as l, graphToXStateTS as m, CanvasColor as n, GraphPatch as o, graphToMachineConfig as p, CodeExpression as r, ImplementationSourceType as s, ActionLocation as t, XStateTSOptions as u, ZodArray as v, ZodOptional as w, ZodNullable as x, ZodEnum as y };
2955
+ export { output as A, ZodNumber as C, ZodString as D, ZodRecord as E, ZodUnion as O, ZodNullable as S, ZodOptional as T, raw as _, EditorStateType as a, ZodEnum as b, MachineConfigOptions as c, XStateTSOptions as d, contextSchemaToTSType as f, jsonSchemaToTSType as g, graphToXStateTS as h, CodeGenGraph as i, $strip as j, ZodUnknown as k, ProfileManifest as l, graphToMachineConfig as m, CanvasColor as n, GraphPatch as o, eventsSchemaToTSType as p, CodeExpression as r, ImplementationSourceType as s, ActionLocation as t, RawCode as u, serializeJS as v, ZodObject as w, ZodLiteral as x, ZodArray as y };
package/dist/index.d.mts CHANGED
@@ -1,13 +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-BAkQThnl.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-yDK-MM3G.mjs";
2
+ import { _ as raw, c as MachineConfigOptions, d as XStateTSOptions, f as contextSchemaToTSType, g as jsonSchemaToTSType, h as graphToXStateTS, i as CodeGenGraph, m as graphToMachineConfig, o as GraphPatch, p as eventsSchemaToTSType, t as ActionLocation, u as RawCode, v as serializeJS } from "./index-BABex8NE.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-B4WM_nYg.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
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";
8
- import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
8
+ import { AssetConfig, EmbedEntity, EmbedFormatContext, EmbedFormatDefinition, EmbedGraph, EmbedProfileDefinition, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
9
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-YSppd-am.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-CjnsqD8j.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 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 };
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 };
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
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-DoNMw8g6.mjs";
2
+ import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-CNeiHhaT.mjs";
3
3
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
4
4
  import { createStatelyEmbed } from "./embed.mjs";
5
5
  import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-CCTwvUOB.mjs";
6
6
  import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-DHGspwII.mjs";
7
- 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-Cesya0Pk.mjs";
7
+ 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-mii-qTXd.mjs";
8
8
  import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
9
- import { n as createStatelyInspector, t as createInspector } from "./inspect-DU-gHyef.mjs";
9
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-CnOHdMYX.mjs";
10
10
  import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
11
11
  import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
12
12
  import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
@@ -1,5 +1,5 @@
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-DoNMw8g6.mjs";
2
+ import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-CNeiHhaT.mjs";
3
3
 
4
4
  //#region src/openBrowser.ts
5
5
  async function openBrowser(url) {
package/dist/inspect.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./version-DoNMw8g6.mjs";
2
- import { n as createStatelyInspector, t as createInspector } from "./inspect-DU-gHyef.mjs";
1
+ import "./version-CNeiHhaT.mjs";
2
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-CnOHdMYX.mjs";
3
3
 
4
4
  export { createInspector, createStatelyInspector };
@@ -1,2 +1,2 @@
1
- import { a as EditorStateType, n as CanvasColor, o as GraphPatch, s as ImplementationSourceType, t as ActionLocation } from "./index-BAkQThnl.mjs";
1
+ import { a as EditorStateType, n as CanvasColor, o as GraphPatch, s as ImplementationSourceType, t as ActionLocation } from "./index-BABex8NE.mjs";
2
2
  export { type ActionLocation, type CanvasColor, type EditorStateType, type GraphPatch, type ImplementationSourceType };
@@ -1,4 +1,5 @@
1
- import { i as StatelyGraph } from "./graph-yDK-MM3G.mjs";
1
+ import { l as ProfileManifest } from "./index-BABex8NE.mjs";
2
+ import { i as StatelyGraph } from "./graph-B4WM_nYg.mjs";
2
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";
3
4
 
4
5
  //#region src/protocol.d.ts
@@ -173,11 +174,30 @@ interface EmbedEventMap {
173
174
  }
174
175
  type EmbedEventName = keyof EmbedEventMap;
175
176
  type EmbedEventHandler<K extends EmbedEventName> = (data: EmbedEventMap[K]) => void;
177
+ interface EmbedFormatManifest {
178
+ id: string;
179
+ name: string;
180
+ file?: {
181
+ extension?: string;
182
+ mediaType?: string;
183
+ };
184
+ editorLanguage?: string;
185
+ detect?: boolean;
186
+ import?: boolean;
187
+ export?: boolean;
188
+ }
189
+ interface EmbedExtensionsManifest {
190
+ profiles: ProfileManifest[];
191
+ formats: EmbedFormatManifest[];
192
+ defaultProfile?: string;
193
+ defaultFormat?: string;
194
+ }
176
195
  interface MachineInitOptions {
177
196
  machine: unknown;
178
197
  /** Ephemeral, read-only reference documents owned by the embed host. */
179
198
  documents?: EmbedDocument[];
180
199
  format?: string;
200
+ extensions?: EmbedExtensionsManifest;
181
201
  mode?: EmbedMode;
182
202
  theme?: 'light' | 'dark';
183
203
  readOnly?: boolean;
@@ -237,6 +257,7 @@ interface InitMessage {
237
257
  machine: unknown;
238
258
  documents?: EmbedDocument[];
239
259
  format?: string;
260
+ extensions?: EmbedExtensionsManifest;
240
261
  mode?: EmbedMode;
241
262
  theme?: 'light' | 'dark';
242
263
  readOnly?: boolean;
@@ -539,10 +560,23 @@ interface UploadResponseMessage {
539
560
  requestId: string;
540
561
  result: UploadResult;
541
562
  }
563
+ interface ExtensionCallMessage {
564
+ type: '@statelyai.extension.call';
565
+ requestId: string;
566
+ extensionId: string;
567
+ method: 'detect' | 'import' | 'export' | 'validate';
568
+ payload: unknown;
569
+ }
570
+ interface ExtensionResultMessage {
571
+ type: '@statelyai.extension.result';
572
+ requestId: string;
573
+ result?: unknown;
574
+ error?: string;
575
+ }
542
576
  /** All messages a client (embed/inspector) can send to the viz. */
543
- type ClientMessage = InitMessage | SetApiKeyMessage | EditorHandshakeMessage | SavedMessage | ClipboardReadResponseMessage | ClipboardWriteResponseMessage | ProjectInitMessage | ProjectUpdateMessage | ProjectSelectMachineMessage | UpdateMessage | SetModeMessage | SetThemeMessage | SetSettingsMessage | RetrieveMessage | ToastMessage | InspectSnapshotMessage | SystemInitMessage | SystemSelectActorMessage | SystemActorRegisteredMessage | SystemActorEventMessage | SystemActorSnapshotMessage | SystemActorStoppedMessage | UploadCapabilitiesMessage | UploadResponseMessage | ErrorMessage;
577
+ type ClientMessage = InitMessage | SetApiKeyMessage | EditorHandshakeMessage | SavedMessage | ClipboardReadResponseMessage | ClipboardWriteResponseMessage | ProjectInitMessage | ProjectUpdateMessage | ProjectSelectMachineMessage | UpdateMessage | SetModeMessage | SetThemeMessage | SetSettingsMessage | RetrieveMessage | ToastMessage | InspectSnapshotMessage | SystemInitMessage | SystemSelectActorMessage | SystemActorRegisteredMessage | SystemActorEventMessage | SystemActorSnapshotMessage | SystemActorStoppedMessage | UploadCapabilitiesMessage | UploadResponseMessage | ExtensionResultMessage | ErrorMessage;
544
578
  /** All messages the viz can send back to a client. */
545
- type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | CapabilityDeniedMessage | ClipboardReadMessage | ClipboardWriteMessage | UploadRequestMessage;
579
+ type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | CapabilityDeniedMessage | ClipboardReadMessage | ClipboardWriteMessage | UploadRequestMessage | ExtensionCallMessage;
546
580
  interface InspectionClientMetadata {
547
581
  name?: string;
548
582
  machineId?: string;
@@ -571,4 +605,4 @@ declare const PREFIX = "@statelyai.";
571
605
  /** Current WebSocket inspection protocol version. */
572
606
  declare const INSPECTION_PROTOCOL_VERSION = 2;
573
607
  //#endregion
574
- export { ActorSystemEntry, CapabilityDeniedCapability, CapabilityDeniedEvent, CapabilityDeniedMessage, ChangeMessage, ClientMessage, ClipboardReadMessage, ClipboardReadResponseMessage, ClipboardWriteMessage, ClipboardWriteResponseMessage, CommentsConfig, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, EditorCapabilities, EditorHandshakeMessage, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ErrorMessage, ExportCallOptions, ExportFormat, ExportFormatMap, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, InitMessage, InitOptions, InspectSnapshotMessage, InspectionAction, InspectionClientMetadata, InspectionRoomUrls, InspectionSentEvent, InspectionTakenTransition, LoadedMessage, MachineInitOptions, MachineSourceLocations, PREFIX, ProjectEmbedMachine, ProjectInitMessage, ProjectInitOptions, ProjectMachineSelectedMessage, ProjectSelectMachineMessage, ProjectUpdateMessage, ProtocolMessage, ReadOnlyReason, ReadyMessage, RegisterMessage, RegisteredMessage, RetrieveMessage, RetrievedMessage, SaveMessage, SavedMessage, SessionMessage, SetApiKeyMessage, SetModeMessage, SetSettingsMessage, SetThemeMessage, SourceLocation, SourceRange, StateSourceLocation, SystemActorEventMessage, SystemActorRegisteredMessage, SystemActorSnapshotMessage, SystemActorStoppedMessage, SystemInitMessage, SystemSelectActorMessage, ToastMessage, UpdateMessage, UploadCapabilitiesMessage, UploadFileInfo, UploadRequestMessage, UploadResponseMessage, UploadResult, ValidationIssue, VizMessage, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId };
608
+ export { ActorSystemEntry, CapabilityDeniedCapability, CapabilityDeniedEvent, CapabilityDeniedMessage, ChangeMessage, ClientMessage, ClipboardReadMessage, ClipboardReadResponseMessage, ClipboardWriteMessage, ClipboardWriteResponseMessage, CommentsConfig, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, EditorCapabilities, EditorHandshakeMessage, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedExtensionsManifest, EmbedFormatManifest, EmbedMode, ErrorMessage, ExportCallOptions, ExportFormat, ExportFormatMap, ExtensionCallMessage, ExtensionResultMessage, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, InitMessage, InitOptions, InspectSnapshotMessage, InspectionAction, InspectionClientMetadata, InspectionRoomUrls, InspectionSentEvent, InspectionTakenTransition, LoadedMessage, MachineInitOptions, MachineSourceLocations, PREFIX, ProjectEmbedMachine, ProjectInitMessage, ProjectInitOptions, ProjectMachineSelectedMessage, ProjectSelectMachineMessage, ProjectUpdateMessage, ProtocolMessage, ReadOnlyReason, ReadyMessage, RegisterMessage, RegisteredMessage, RetrieveMessage, RetrievedMessage, SaveMessage, SavedMessage, SessionMessage, SetApiKeyMessage, SetModeMessage, SetSettingsMessage, SetThemeMessage, SourceLocation, SourceRange, StateSourceLocation, SystemActorEventMessage, SystemActorRegisteredMessage, SystemActorSnapshotMessage, SystemActorStoppedMessage, SystemInitMessage, SystemSelectActorMessage, ToastMessage, UpdateMessage, UploadCapabilitiesMessage, UploadFileInfo, UploadRequestMessage, UploadResponseMessage, UploadResult, ValidationIssue, VizMessage, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId };
@@ -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 "./schemas-b9wG-zYl.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
@@ -4410,6 +4409,92 @@ function guardCondition(value) {
4410
4409
  firstParam: params.startsWith("(") && params.endsWith(")") ? params.slice(1, -1).trim() : params
4411
4410
  };
4412
4411
  }
4412
+ const V6_ARG_BINDINGS = [
4413
+ "context",
4414
+ "event",
4415
+ "actions",
4416
+ "children",
4417
+ "self",
4418
+ "system"
4419
+ ];
4420
+ const V6_IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
4421
+ function inferV6ArgBindings(code) {
4422
+ return V6_ARG_BINDINGS.filter((name) => new RegExp(`\\b${name}\\b`).test(code));
4423
+ }
4424
+ /** Splits a destructuring pattern body on its top-level commas. */
4425
+ function splitV6PatternEntries(body) {
4426
+ const entries = [];
4427
+ let depth = 0;
4428
+ let start = 0;
4429
+ let quote;
4430
+ for (let index = 0; index < body.length; index++) {
4431
+ const char = body[index];
4432
+ if (quote) {
4433
+ if (char === "\\") index++;
4434
+ else if (char === quote) quote = void 0;
4435
+ continue;
4436
+ }
4437
+ if (char === "\"" || char === "'" || char === "`") quote = char;
4438
+ else if (char === "{" || char === "[" || char === "(") depth++;
4439
+ else if (char === "}" || char === "]" || char === ")") {
4440
+ depth--;
4441
+ if (depth < 0) return void 0;
4442
+ } else if (char === "," && depth === 0) {
4443
+ entries.push(body.slice(start, index));
4444
+ start = index + 1;
4445
+ }
4446
+ }
4447
+ if (depth !== 0 || quote) return void 0;
4448
+ entries.push(body.slice(start));
4449
+ return entries.map((entry) => entry.trim()).filter(Boolean);
4450
+ }
4451
+ /** Local name a destructuring entry binds, or `undefined` if not a plain one. */
4452
+ function getV6PatternBinding(entry) {
4453
+ const colon = entry.indexOf(":");
4454
+ const name = (colon < 0 ? entry : entry.slice(colon + 1)).split("=")[0].trim();
4455
+ return V6_IDENTIFIER.test(name) ? name : void 0;
4456
+ }
4457
+ /**
4458
+ * Unions the bindings referenced by generated code into the parameter authored
4459
+ * on a guard, so a collapsed transition function never references unbound
4460
+ * variables. Returns `undefined` when the authored parameter cannot be
4461
+ * extended safely, in which case the transition array is kept as-is.
4462
+ */
4463
+ function mergeV6FirstParam(authoredFirstParam, inferred) {
4464
+ if (!authoredFirstParam) return {
4465
+ firstParam: inferred.length ? `{ ${inferred.join(", ")} }` : "_",
4466
+ prelude: []
4467
+ };
4468
+ if (inferred.length === 0) return {
4469
+ firstParam: authoredFirstParam,
4470
+ prelude: []
4471
+ };
4472
+ if (V6_IDENTIFIER.test(authoredFirstParam)) {
4473
+ if (inferred.includes(authoredFirstParam)) return void 0;
4474
+ return {
4475
+ firstParam: authoredFirstParam,
4476
+ prelude: [`const { ${inferred.join(", ")} } = ${authoredFirstParam};`]
4477
+ };
4478
+ }
4479
+ if (!authoredFirstParam.startsWith("{") || !authoredFirstParam.endsWith("}")) return;
4480
+ const entries = splitV6PatternEntries(authoredFirstParam.slice(1, -1));
4481
+ if (!entries) return void 0;
4482
+ const bound = new Set(entries.map(getV6PatternBinding).filter((name) => name !== void 0));
4483
+ const missing = inferred.filter((name) => !bound.has(name));
4484
+ if (missing.length === 0) return {
4485
+ firstParam: authoredFirstParam,
4486
+ prelude: []
4487
+ };
4488
+ const restIndex = entries.findIndex((entry) => entry.startsWith("..."));
4489
+ return {
4490
+ firstParam: `{ ${(restIndex < 0 ? [...entries, ...missing] : [
4491
+ ...entries.slice(0, restIndex),
4492
+ ...missing,
4493
+ ...entries.slice(restIndex)
4494
+ ]).join(", ")} }`,
4495
+ prelude: []
4496
+ };
4497
+ }
4413
4498
  function buildV6TransitionFunction(transitions) {
4414
4499
  const branches = [];
4415
4500
  let authoredFirstParam;
@@ -4435,24 +4520,23 @@ function buildV6TransitionFunction(transitions) {
4435
4520
  if (!returnValue) return;
4436
4521
  const body = [...rendered.statements.map(formatV6Statement), `return ${returnValue};`];
4437
4522
  if (body.length === 0) return;
4438
- if (guard.condition === "true") branches.push(...body.map((line) => ` ${line}`));
4439
- else {
4440
- branches.push(` if (${guard.condition}) {`);
4441
- branches.push(...body.map((line) => ` ${line}`));
4442
- branches.push(" }");
4443
- }
4523
+ branches.push({
4524
+ condition: guard.condition,
4525
+ body
4526
+ });
4444
4527
  }
4445
4528
  if (branches.length === 0) return;
4446
- const referenced = branches.join("\n");
4447
- const inferredBindings = [
4448
- "context",
4449
- "event",
4450
- "actions",
4451
- "children",
4452
- "self",
4453
- "system"
4454
- ].filter((name) => new RegExp(`\\b${name}\\b`).test(referenced));
4455
- return raw(`(${authoredFirstParam ?? (inferredBindings.length ? `{ ${inferredBindings.join(", ")} }` : "_")}, enq) => {\n${branches.join("\n")}\n}`);
4529
+ const generated = branches.flatMap((branch) => branch.body).join("\n");
4530
+ const merged = mergeV6FirstParam(authoredFirstParam, inferV6ArgBindings(generated));
4531
+ if (!merged) return;
4532
+ const lines = merged.prelude.map((statement) => ` ${statement}`);
4533
+ for (const branch of branches) if (branch.condition === "true") lines.push(...branch.body.map((line) => ` ${line}`));
4534
+ else {
4535
+ lines.push(` if (${branch.condition}) {`);
4536
+ lines.push(...branch.body.map((line) => ` ${line}`));
4537
+ lines.push(" }");
4538
+ }
4539
+ return raw(`(${merged.firstParam}, enq) => {\n${lines.join("\n")}\n}`);
4456
4540
  }
4457
4541
  function toV6ActionField(actions) {
4458
4542
  if (actions.length === 1) {
@@ -4470,15 +4554,7 @@ function buildV6ActionFunction(actions, transition) {
4470
4554
  let returnValue = rendered.contextValue ? `{ context: ${rendered.contextValue} }` : void 0;
4471
4555
  if (transition) returnValue = buildV6TransitionReturnValue(transition, rendered.contextValue);
4472
4556
  if (statements.length === 0 && !returnValue) return void 0;
4473
- const referenced = [...statements, returnValue ?? ""].join("\n");
4474
- const bindings = [
4475
- "context",
4476
- "event",
4477
- "actions",
4478
- "children",
4479
- "self",
4480
- "system"
4481
- ].filter((name) => new RegExp(`\\b${name}\\b`).test(referenced));
4557
+ const bindings = inferV6ArgBindings([...statements, returnValue ?? ""].join("\n"));
4482
4558
  return raw(`(${bindings.length ? `{ ${bindings.join(", ")} }` : "_"}, enq) => {\n${[...statements.map((statement) => ` ${formatV6Statement(statement)}`), ...returnValue ? [` return ${returnValue};`] : []].join("\n")}\n}`);
4483
4559
  }
4484
4560
  function formatV6Statement(statement) {
@@ -1,4 +1,4 @@
1
- import { A as $strip, C as ZodObject, D as ZodUnion, E as ZodString, O as ZodUnknown, S as ZodNumber, T as ZodRecord, b as ZodLiteral, k as output, v as ZodArray, w as ZodOptional, x as ZodNullable, y as ZodEnum } from "./index-BAkQThnl.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-BABex8NE.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-YSppd-am.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-CjnsqD8j.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-yDK-MM3G.mjs";
2
- import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-YSppd-am.mjs";
1
+ import { b as DigraphConfig, i as StatelyGraph } from "./graph-B4WM_nYg.mjs";
2
+ import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-CjnsqD8j.mjs";
3
3
  import { GraphDiff } from "@statelyai/graph";
4
4
 
5
5
  //#region src/sync.d.ts
package/dist/sync.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as createStatelyClient } from "./studio-DHGspwII.mjs";
2
- 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-Cesya0Pk.mjs";
2
+ 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-mii-qTXd.mjs";
3
3
  import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
4
4
  import * as ts$1 from "typescript";
5
5
  import ts from "typescript";
@@ -134,6 +134,7 @@ function toInitMessage(options) {
134
134
  machine: options.machine,
135
135
  documents: options.documents,
136
136
  format: options.format,
137
+ extensions: options.extensions,
137
138
  mode: options.mode,
138
139
  theme: options.theme,
139
140
  readOnly: options.readOnly,
@@ -159,9 +160,9 @@ function createPostMessageTransport(options) {
159
160
  const messageHandlers = /* @__PURE__ */ new Set();
160
161
  function handleMessage(e) {
161
162
  if (destroyed) return;
163
+ const expectedSource = options.source ?? iframe.contentWindow;
164
+ if (e.source !== expectedSource) return;
162
165
  if (targetOrigin !== "*") {
163
- const expectedSource = options.source ?? iframe.contentWindow;
164
- if (e.source !== expectedSource) return;
165
166
  if (e.origin !== targetOrigin) return;
166
167
  }
167
168
  const data = e.data;
@@ -328,7 +329,7 @@ function createWebSocketTransport(options) {
328
329
 
329
330
  //#endregion
330
331
  //#region src/version.ts
331
- const SDK_VERSION = "0.20.3";
332
+ const SDK_VERSION = "0.21.0";
332
333
  function inspectionRuntime() {
333
334
  if (typeof window !== "undefined") return "browser";
334
335
  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.20.3",
3
+ "version": "0.21.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.4",
97
- "@statelyai/graph-tools": "0.1.1"
96
+ "@statelyai/api-contract": "0.3.6",
97
+ "@statelyai/graph-tools": "0.2.0"
98
98
  },
99
99
  "engines": {
100
100
  "node": ">=22.4"