@statelyai/sdk 0.21.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,6 +37,7 @@ embed.init({
37
37
  format: 'xstate',
38
38
  mode: 'editing',
39
39
  theme: 'dark',
40
+ settings: { canvas: { viewMode: 'list' } },
40
41
  documents: [
41
42
  { path: 'README.md', content: '# How this workflow works' },
42
43
  { path: 'src/machine.ts', content: machineSource },
@@ -44,6 +45,9 @@ embed.init({
44
45
  });
45
46
  ```
46
47
 
48
+ Use `viewMode: 'list'` on `createStatelyEmbed` to add `?view=list` to the
49
+ iframe URL, or subscribe to `viewModeChanged` when the user switches views.
50
+
47
51
  Custom profiles and formats can be supplied when the embed is created. Their
48
52
  serializable manifests are sent to the iframe; detector, importer, exporter,
49
53
  and validator implementations remain in the host and are called asynchronously.
@@ -90,6 +94,9 @@ CLI and editor-extension hosts use `EditorHostSession` from
90
94
  clipboard requests, and editor protocol negotiation. Use
91
95
  `createRemoteEditorSyncBackend` for two-way validation of the versioned Editor
92
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.
93
100
  Hosts keep ownership of files, credentials, UI, and transport adapters.
94
101
 
95
102
  Key capabilities:
@@ -1,9 +1,13 @@
1
- import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
2
- import { c as object, f as unknown, i as custom, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./schemas-b9wG-zYl.mjs";
1
+ import { c as object, f as unknown, i as custom, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./openapi-BTDjYWXd.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
3
 
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,4 +1,5 @@
1
- import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
2
- import { n as createRemoteEditorSyncBackend, r as fetchEditorSyncAccess, t as EditorHostSession } from "./editorHostSession-CCTwvUOB.mjs";
1
+ import "./openapi-BTDjYWXd.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
+ import { i as fetchEditorSyncAccess, n as EditorSyncError, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-BZE_Wm0m.mjs";
3
4
 
4
- 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 { l as ProfileManifest } from "./index-BABex8NE.mjs";
2
- import { i as StatelyGraph } from "./graph-B4WM_nYg.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
 
@@ -72,6 +72,8 @@ type EmbedFormatDefinition = {
72
72
  interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
73
73
  baseUrl: string;
74
74
  apiKey?: string;
75
+ /** Initial canvas view. Also reflected in the iframe URL as `?view=`. */
76
+ viewMode?: 'graph' | 'list';
75
77
  origin?: string;
76
78
  /**
77
79
  * Optional iframe to attach to immediately. Equivalent to calling
@@ -97,6 +99,7 @@ interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
97
99
  onLoaded?: (graph: StatelyGraph) => void;
98
100
  onChange?: (graph: StatelyGraph, machineConfig: unknown) => void;
99
101
  onSave?: (graph: StatelyGraph, machineConfig: unknown) => void;
102
+ onViewModeChanged?: (viewMode: 'graph' | 'list') => void;
100
103
  onError?: (error: {
101
104
  code: string;
102
105
  message: string;
package/dist/embed.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-CNeiHhaT.mjs";
2
- import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-D_h4y3rX.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-yzel-kpS.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
3
 
4
4
  //#region src/embed.ts
5
5
  function isRecord(value) {
@@ -29,6 +29,7 @@ function buildEmbedUrl(options) {
29
29
  const base = options.baseUrl.replace(/\/+$/, "") + "/embed";
30
30
  const url = new URL(base);
31
31
  if (options.apiKey) url.searchParams.set("api_key", options.apiKey);
32
+ if (options.viewMode) url.searchParams.set("view", options.viewMode);
32
33
  return url.toString();
33
34
  }
34
35
  function serializeExtensions(options) {
@@ -80,6 +81,7 @@ function extractInitOptions(options) {
80
81
  capabilities: options.capabilities,
81
82
  panels: options.panels,
82
83
  commentsByMachineId: options.commentsByMachineId,
84
+ settings: options.settings,
83
85
  unsavedIndicator: options.unsavedIndicator
84
86
  };
85
87
  if (options.machine !== void 0) return {
@@ -96,6 +98,7 @@ function extractInitOptions(options) {
96
98
  panels: options.panels,
97
99
  comments: options.comments,
98
100
  sourceLocations: options.sourceLocations,
101
+ settings: options.settings,
99
102
  unsavedIndicator: options.unsavedIndicator
100
103
  };
101
104
  return null;
@@ -275,6 +278,15 @@ function createStatelyEmbed(options) {
275
278
  case "@statelyai.project.machineSelected":
276
279
  events.emit("machineSelected", { machineId: String(data.machineId) });
277
280
  break;
281
+ case "@statelyai.viewModeChanged": {
282
+ const viewMode = data;
283
+ options.onViewModeChanged?.(viewMode.viewMode);
284
+ events.emit("viewModeChanged", {
285
+ viewMode: viewMode.viewMode,
286
+ machineId: viewMode.machineId
287
+ });
288
+ break;
289
+ }
278
290
  case "@statelyai.retrieved": {
279
291
  const retrieved = data;
280
292
  exportManager.resolve(retrieved.requestId, retrieved.data);
@@ -1,4 +1,4 @@
1
- import { r as CodeExpression } from "./index-BABex8NE.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-B4WM_nYg.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 };