@statelyai/sdk 0.5.0 → 0.6.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/dist/index.d.mts CHANGED
@@ -1,117 +1,35 @@
1
- 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-BfezxFKJ.mjs";
2
- import { a as ProjectMachine, c as StudioClientOptions, i as ProjectData, l as VerifyApiKeyResponse, n as ExtractedMachine, o as StudioApiError, r as GetMachineOptions, s as StudioClient, t as ExtractMachinesResponse, u as createStatelyClient } from "./studio-D2uQhrvX.mjs";
3
- import { PlanSyncOptions, PullSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
4
- import { a as EmbedMode, c as ExportFormatMap, f as UploadResult, i as EmbedEventName, l as InitOptions, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat, t as CommentsConfig } from "./protocol-B1cNV7QB.mjs";
1
+ import { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
2
+ import { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, EnsureProjectInput, ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, ProjectVisibility, RepoType, StudioApiError, StudioClient, StudioClientOptions, StudioMachineRecord, VerifyApiKeyResponse, XStateVersion, createStatelyClient } from "./studio.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-CB-ALrdk.mjs";
4
+ import { PlanSyncOptions, PullSyncResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
5
+ import { a as EmbedMode, c as ExportFormatMap, f as ProjectEmbedMachine, i as EmbedEventName, l as InitOptions, m as UploadResult, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat, t as CommentsConfig } from "./protocol-CEbWQPYe.mjs";
5
6
  import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
6
- import { a as ManualActorOptions, c as createPostMessageTransport, i as InspectorEvents, l as createWebSocketTransport, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-WUC2inmJ.mjs";
7
+ import { a as ManualActorOptions, c as createPostMessageTransport, i as InspectorEvents, l as createWebSocketTransport, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-DIxB2Tr3.mjs";
7
8
  import { ActionLocation, GraphPatch } from "./patchTypes.mjs";
9
+ import { CodeGenGraph, MachineConfigOptions, RawCode, graphToMachineConfig, raw, serializeJS } from "@statelyai/graph-tools";
8
10
  import { JSONSchema7 } from "json-schema";
9
- import { UnknownMachineConfig } from "xstate";
10
11
 
11
- //#region src/codegenTypes.d.ts
12
- interface CodeGenAction {
13
- type: string;
14
- params?: Record<string, unknown>;
15
- }
16
- interface CodeGenGuard {
17
- type: string;
18
- code?: string;
19
- params?: Record<string, unknown>;
20
- }
21
- interface CodeGenInvoke {
22
- src: string;
23
- id: string;
24
- input?: unknown;
25
- }
26
- interface CodeGenNodeData {
27
- nodeId?: string | null;
28
- key: string;
29
- type?: 'normal' | 'parallel' | 'final' | 'history' | null;
30
- initialId?: string | null;
31
- history?: 'shallow' | 'deep' | boolean;
32
- entry?: CodeGenAction[];
33
- exit?: CodeGenAction[];
34
- invokes?: CodeGenInvoke[];
35
- tags?: Array<string | {
36
- name: string;
37
- }>;
38
- description?: string | null;
39
- meta?: Record<string, unknown> | null;
40
- color?: string;
41
- parentId?: string | null;
42
- temp?: boolean;
43
- }
44
- interface CodeGenEdgeData {
45
- eventType: string;
46
- transitionType?: 'normal' | 'targetless' | 'reenter';
47
- guard?: CodeGenGuard | null;
48
- actions?: CodeGenAction[];
49
- description?: string | null;
50
- color?: string;
51
- meta?: Record<string, unknown> | null;
52
- temp?: boolean;
53
- }
54
- interface CodeGenImplementation {
55
- id: string;
56
- name: string;
57
- description?: string | null;
58
- icon?: string;
59
- paramsSchema?: JSONSchema7 | null;
60
- code?: {
61
- body: string;
62
- lang?: string;
63
- } | null;
64
- }
65
- interface CodeGenActorImplementation {
66
- id: string;
67
- name: string;
68
- description?: string | null;
69
- icon?: string;
70
- inputSchema?: JSONSchema7 | null;
71
- outputSchema?: JSONSchema7 | null;
72
- code?: {
73
- body: string;
74
- lang?: string;
75
- } | null;
76
- }
77
- interface CodeGenGraphData {
78
- schemas?: {
79
- context?: Record<string, JSONSchema7> | null;
80
- events?: Record<string, JSONSchema7> | null;
81
- input?: JSONSchema7 | null;
82
- output?: JSONSchema7 | null;
83
- } | null;
84
- implementations?: {
85
- actions: CodeGenImplementation[];
86
- guards: CodeGenImplementation[];
87
- actors: CodeGenActorImplementation[];
88
- delays: CodeGenImplementation[];
89
- } | null;
90
- }
91
- interface CodeGenNode {
92
- id: string;
93
- parentId?: string | null;
94
- data: CodeGenNodeData;
95
- }
96
- interface CodeGenEdge {
97
- id: string;
98
- sourceId: string;
99
- targetId: string;
100
- data: CodeGenEdgeData;
101
- }
102
- interface CodeGenGraph {
103
- id: string;
104
- nodes: CodeGenNode[];
105
- edges: CodeGenEdge[];
106
- data: CodeGenGraphData;
107
- }
108
- //#endregion
109
- //#region src/graphToMachineConfig.d.ts
110
- interface MachineConfigOptions {
111
- showDescriptions?: boolean;
112
- showMeta?: boolean;
113
- }
114
- declare function graphToMachineConfig(graph: CodeGenGraph, options?: MachineConfigOptions): UnknownMachineConfig;
12
+ //#region src/statelyPragma.d.ts
13
+ interface StatelyPragma {
14
+ tag: '@statelyai';
15
+ id?: string;
16
+ fields: Record<string, string>;
17
+ start: number;
18
+ end: number;
19
+ }
20
+ interface StatelyPragmaAttachment {
21
+ machineStart: number;
22
+ attachStart: number;
23
+ pragma?: StatelyPragma;
24
+ }
25
+ interface UpsertStatelyPragmaOptions {
26
+ fileName?: string;
27
+ machineIndex?: number;
28
+ lineEnding?: '\n' | '\r\n';
29
+ }
30
+ declare function findStatelyPragmaAttachments(sourceText: string, fileName?: string): StatelyPragmaAttachment[];
31
+ declare function getStatelyPragma(sourceText: string, fileName?: string, machineIndex?: number): StatelyPragma | undefined;
32
+ declare function upsertStatelyPragma(sourceText: string, id: string, options?: UpsertStatelyPragmaOptions): string;
115
33
  //#endregion
116
34
  //#region src/graphToXStateTS.d.ts
117
35
  interface XStateTSOptions extends MachineConfigOptions {
@@ -119,21 +37,6 @@ interface XStateTSOptions extends MachineConfigOptions {
119
37
  }
120
38
  declare function graphToXStateTS(graph: CodeGenGraph, options?: XStateTSOptions): string;
121
39
  //#endregion
122
- //#region src/serializeJS.d.ts
123
- /**
124
- * Serializes JavaScript values as JS source code (not JSON).
125
- * - Unquoted keys for valid identifiers
126
- * - Single-quoted strings
127
- * - Omits undefined values
128
- * - Supports RawCode for verbatim expressions
129
- */
130
- declare class RawCode {
131
- code: string;
132
- constructor(code: string);
133
- }
134
- declare function raw(code: string): RawCode;
135
- declare function serializeJS(value: unknown, indent?: number, step?: number): string;
136
- //#endregion
137
40
  //#region src/jsonSchemaToTSType.d.ts
138
41
  declare function jsonSchemaToTSType(schema: JSONSchema7 | undefined | null): string;
139
42
  /**
@@ -147,4 +50,4 @@ declare function contextSchemaToTSType(context: Record<string, JSONSchema7> | nu
147
50
  */
148
51
  declare function eventsSchemaToTSType(events: Record<string, JSONSchema7> | null | undefined): string | null;
149
52
  //#endregion
150
- export { type ActionLocation, type AdoptedActor, type AssetConfig, type CodeGenGraph, type CommentsConfig, type CreateInspectorOptions, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesResponse, type ExtractedMachine, type GetMachineOptions, type GraphPatch, type InitOptions, type Inspector, type InspectorEvents, type MachineConfigOptions, type ManualActorOptions, type PlanSyncOptions, type ProjectData, type ProjectMachine, type PullSyncResult, RawCode, type ResolvedSyncInput, type StateNodeJSONData, type StatelyAction, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StudioAction, StudioApiError, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioNode, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type UploadResult, type VerifyApiKeyResponse, type XStateTSOptions, contextSchemaToTSType, createPostMessageTransport, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, fromStudioMachine, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine };
53
+ export { type ActionLocation, type AdoptedActor, type AssetConfig, type CodeGenGraph, type CommentsConfig, type ConnectedRepo, type CreateInspectorOptions, type CreateMachineFromDefinitionInput, type CreateMachineFromTemplateInput, type CreateMachineInput, type CreateMachineTemplate, type CreateProjectInput, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EnsureProjectInput, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesResponse, type ExtractedMachine, type GetMachineOptions, type GraphPatch, type InitOptions, type Inspector, type InspectorEvents, type MachineConfigOptions, type ManualActorOptions, type PlanSyncOptions, type ProjectData, type ProjectEmbedMachine, type ProjectMachine, type ProjectVisibility, type PullSyncResult, type PushSyncOptions, type PushSyncProjectOptions, type PushSyncResult, RawCode, type RepoType, type ResolvedSyncInput, type StateNodeJSONData, type StatelyAction, type StatelyApiClientOptions, StatelyApiError, type StatelyApiUrlOptions, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StatelyPragma, type StatelyPragmaAttachment, type StudioAction, StudioApiError, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioMachineRecord, type StudioNode, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type UploadResult, type UpsertStatelyPragmaOptions, type VerifyApiKeyResponse, type XStateTSOptions, type XStateVersion, contextSchemaToTSType, createPostMessageTransport, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
package/dist/index.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-lomH7b0v.mjs";
1
+ import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-C0eTgNNu.mjs";
2
2
  import { createStatelyEmbed } from "./embed.mjs";
3
3
  import { createStatelyInspector } from "./inspect.mjs";
4
4
  import { StudioApiError, createStatelyClient } from "./studio.mjs";
5
+ import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
6
+ import { a as RawCode, c as graphToMachineConfig, d as upsertStatelyPragma, i as jsonSchemaToTSType, l as findStatelyPragmaAttachments, n as contextSchemaToTSType, o as raw, r as eventsSchemaToTSType, s as serializeJS, t as graphToXStateTS, u as getStatelyPragma } from "./graphToXStateTS-CvXM8wHL.mjs";
5
7
  import { fromStudioMachine, studioMachineConverter, toStudioMachine } from "./graph.mjs";
6
- import { a as graphToMachineConfig, c as serializeJS, i as jsonSchemaToTSType, n as contextSchemaToTSType, o as RawCode, r as eventsSchemaToTSType, s as raw, t as graphToXStateTS } from "./graphToXStateTS-BSUj97r0.mjs";
7
8
 
8
- export { RawCode, StudioApiError, contextSchemaToTSType, createPostMessageTransport, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, fromStudioMachine, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine };
9
+ export { RawCode, StatelyApiError, StudioApiError, contextSchemaToTSType, createPostMessageTransport, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
@@ -1,4 +1,4 @@
1
- import { c as ExportFormatMap, d as ProtocolMessage, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-B1cNV7QB.mjs";
1
+ import { c as ExportFormatMap, o as ExportCallOptions, p as ProtocolMessage, r as EmbedEventMap, s as ExportFormat } from "./protocol-CEbWQPYe.mjs";
2
2
 
3
3
  //#region src/transport.d.ts
4
4
  interface Transport {
@@ -1,3 +1,3 @@
1
- import { a as EmbedMode, c as ExportFormatMap, i as EmbedEventName, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-B1cNV7QB.mjs";
2
- import { a as ManualActorOptions, i as InspectorEvents, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-WUC2inmJ.mjs";
1
+ import { a as EmbedMode, c as ExportFormatMap, i as EmbedEventName, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-CEbWQPYe.mjs";
2
+ import { a as ManualActorOptions, i as InspectorEvents, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-DIxB2Tr3.mjs";
3
3
  export { AdoptedActor, CreateInspectorOptions, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, Inspector, InspectorEvents, ManualActorOptions, Transport, createStatelyInspector };
package/dist/inspect.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as createPendingExportManager, n as createWebSocketTransport, r as createEventRegistry } from "./transport-lomH7b0v.mjs";
1
+ import { i as createPendingExportManager, n as createWebSocketTransport, r as createEventRegistry } from "./transport-C0eTgNNu.mjs";
2
2
 
3
3
  //#region src/inspect.ts
4
4
  const defaultSerializeSnapshot = (snapshot) => ({
@@ -8,6 +8,7 @@ type ActionLocation = {
8
8
  edgeId: string;
9
9
  group: 'transition';
10
10
  };
11
+ type ImplementationSourceType = 'action' | 'guard' | 'actor' | 'delay';
11
12
  type GraphPatch = {
12
13
  op: 'createNode';
13
14
  description?: string;
@@ -163,6 +164,29 @@ type GraphPatch = {
163
164
  description?: string;
164
165
  nodeId: string;
165
166
  invokeId: string;
167
+ } | {
168
+ op: 'createImplementation';
169
+ description?: string;
170
+ sourceType: ImplementationSourceType;
171
+ implementation: {
172
+ id: string;
173
+ name?: string;
174
+ code?: string;
175
+ };
176
+ } | {
177
+ op: 'updateImplementation';
178
+ description?: string;
179
+ sourceType: ImplementationSourceType;
180
+ implementationId: string;
181
+ data: {
182
+ name?: string;
183
+ code?: string;
184
+ };
185
+ } | {
186
+ op: 'deleteImplementation';
187
+ description?: string;
188
+ sourceType: ImplementationSourceType;
189
+ implementationId: string;
166
190
  } | {
167
191
  op: 'setGuard';
168
192
  description?: string;
@@ -222,4 +246,4 @@ type GraphPatch = {
222
246
  };
223
247
  };
224
248
  //#endregion
225
- export { ActionLocation, CanvasColor, EditorStateType, GraphPatch };
249
+ export { ActionLocation, CanvasColor, EditorStateType, GraphPatch, ImplementationSourceType };
@@ -7,6 +7,11 @@ interface CommentsConfig {
7
7
  authEndpoint?: string;
8
8
  baseUrl?: string;
9
9
  }
10
+ interface ProjectEmbedMachine {
11
+ id: string;
12
+ name?: string;
13
+ machine: unknown;
14
+ }
10
15
  interface ValidationIssue {
11
16
  nodeIds: string[];
12
17
  edgeIds: string[];
@@ -62,6 +67,10 @@ interface ExportFormatMap {
62
67
  };
63
68
  result: Record<string, unknown>;
64
69
  };
70
+ xgraph: {
71
+ options: object;
72
+ result: Record<string, unknown>;
73
+ };
65
74
  digraph: {
66
75
  options: object;
67
76
  result: Record<string, unknown>;
@@ -70,7 +79,7 @@ interface ExportFormatMap {
70
79
  options: object;
71
80
  result: string;
72
81
  };
73
- rtk: {
82
+ redux: {
74
83
  options: object;
75
84
  result: string;
76
85
  };
@@ -101,17 +110,20 @@ interface EmbedEventMap {
101
110
  };
102
111
  loaded: {
103
112
  graph: unknown;
113
+ machineId?: string;
104
114
  sourceLocations?: MachineSourceLocations;
105
115
  };
106
116
  change: {
107
117
  graph: unknown;
108
118
  machineConfig: unknown;
119
+ machineId?: string;
109
120
  patches?: unknown[];
110
121
  sourceLocations?: MachineSourceLocations;
111
122
  };
112
123
  save: {
113
124
  graph: unknown;
114
125
  machineConfig: unknown;
126
+ machineId?: string;
115
127
  patches?: unknown[];
116
128
  validations?: ValidationIssue[];
117
129
  sourceLocations?: MachineSourceLocations;
@@ -124,10 +136,13 @@ interface EmbedEventMap {
124
136
  snapshot: unknown;
125
137
  event: unknown | null;
126
138
  };
139
+ machineSelected: {
140
+ machineId: string;
141
+ };
127
142
  }
128
143
  type EmbedEventName = keyof EmbedEventMap;
129
144
  type EmbedEventHandler<K extends EmbedEventName> = (data: EmbedEventMap[K]) => void;
130
- interface InitOptions {
145
+ interface MachineInitOptions {
131
146
  machine: unknown;
132
147
  format?: string;
133
148
  mode?: EmbedMode;
@@ -158,6 +173,25 @@ interface InitOptions {
158
173
  mode?: 'structural' | 'all';
159
174
  };
160
175
  }
176
+ interface ProjectInitOptions {
177
+ machines: ProjectEmbedMachine[];
178
+ currentMachineId?: string;
179
+ mode?: EmbedMode;
180
+ theme?: 'light' | 'dark';
181
+ readOnly?: boolean;
182
+ depth?: number;
183
+ panels?: {
184
+ leftPanels?: string[];
185
+ rightPanels?: string[];
186
+ activePanels?: string[];
187
+ };
188
+ commentsByMachineId?: Record<string, CommentsConfig>;
189
+ unsavedIndicator?: {
190
+ enabled?: boolean;
191
+ mode?: 'structural' | 'all';
192
+ };
193
+ }
194
+ type InitOptions = MachineInitOptions | ProjectInitOptions;
161
195
  interface InitMessage {
162
196
  type: '@statelyai.init';
163
197
  machine: unknown;
@@ -179,6 +213,34 @@ interface InitMessage {
179
213
  /** Optional session id override (multiplexed clients only). */
180
214
  sessionId?: string;
181
215
  }
216
+ interface ProjectInitMessage {
217
+ type: '@statelyai.project.init';
218
+ machines: ProjectEmbedMachine[];
219
+ currentMachineId?: string;
220
+ mode?: EmbedMode;
221
+ theme?: 'light' | 'dark';
222
+ readOnly?: boolean;
223
+ depth?: number;
224
+ leftPanels?: string[];
225
+ rightPanels?: string[];
226
+ activePanels?: string[];
227
+ commentsByMachineId?: Record<string, CommentsConfig>;
228
+ unsavedIndicator?: {
229
+ enabled?: boolean;
230
+ mode?: 'structural' | 'all';
231
+ };
232
+ sessionId?: string;
233
+ }
234
+ interface ProjectUpdateMessage {
235
+ type: '@statelyai.project.update';
236
+ machines: ProjectEmbedMachine[];
237
+ currentMachineId?: string;
238
+ commentsByMachineId?: Record<string, CommentsConfig>;
239
+ }
240
+ interface ProjectSelectMachineMessage {
241
+ type: '@statelyai.project.selectMachine';
242
+ machineId: string;
243
+ }
182
244
  interface UpdateMessage {
183
245
  type: '@statelyai.update';
184
246
  machine: unknown;
@@ -276,12 +338,14 @@ interface ReadyMessage {
276
338
  interface LoadedMessage {
277
339
  type: '@statelyai.loaded';
278
340
  graph: unknown;
341
+ machineId?: string;
279
342
  sourceLocations?: MachineSourceLocations;
280
343
  }
281
344
  interface ChangeMessage {
282
345
  type: '@statelyai.change';
283
346
  graph: unknown;
284
347
  machineConfig: unknown;
348
+ machineId?: string;
285
349
  patches?: unknown[];
286
350
  sourceLocations?: MachineSourceLocations;
287
351
  }
@@ -289,10 +353,15 @@ interface SaveMessage {
289
353
  type: '@statelyai.save';
290
354
  graph: unknown;
291
355
  machineConfig: unknown;
356
+ machineId?: string;
292
357
  patches?: unknown[];
293
358
  validations?: ValidationIssue[];
294
359
  sourceLocations?: MachineSourceLocations;
295
360
  }
361
+ interface ProjectMachineSelectedMessage {
362
+ type: '@statelyai.project.machineSelected';
363
+ machineId: string;
364
+ }
296
365
  interface RetrievedMessage {
297
366
  type: '@statelyai.retrieved';
298
367
  requestId: string;
@@ -345,9 +414,9 @@ interface UploadResponseMessage {
345
414
  result: UploadResult;
346
415
  }
347
416
  /** All messages a client (embed/inspector) can send to the viz. */
348
- type ClientMessage = InitMessage | UpdateMessage | SetModeMessage | SetThemeMessage | SetSettingsMessage | RetrieveMessage | ToastMessage | InspectSnapshotMessage | SystemInitMessage | SystemActorRegisteredMessage | SystemActorSnapshotMessage | SystemActorStoppedMessage | UploadCapabilitiesMessage | UploadResponseMessage | ErrorMessage;
417
+ type ClientMessage = InitMessage | ProjectInitMessage | ProjectUpdateMessage | ProjectSelectMachineMessage | UpdateMessage | SetModeMessage | SetThemeMessage | SetSettingsMessage | RetrieveMessage | ToastMessage | InspectSnapshotMessage | SystemInitMessage | SystemActorRegisteredMessage | SystemActorSnapshotMessage | SystemActorStoppedMessage | UploadCapabilitiesMessage | UploadResponseMessage | ErrorMessage;
349
418
  /** All messages the viz can send back to a client. */
350
- type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | RetrievedMessage | ErrorMessage | UploadRequestMessage;
419
+ type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | UploadRequestMessage;
351
420
  interface RegisterMessage {
352
421
  type: '@statelyai.register';
353
422
  role: 'client' | 'viz';
@@ -394,4 +463,4 @@ type SessionMessage = RegisterMessage | RegisteredMessage | RequestOpenMessage |
394
463
  /** Any valid protocol message. */
395
464
  type ProtocolMessage = ClientMessage | VizMessage | SessionMessage;
396
465
  //#endregion
397
- export { EmbedMode as a, ExportFormatMap as c, ProtocolMessage as d, UploadResult as f, EmbedEventName as i, InitOptions as l, EmbedEventHandler as n, ExportCallOptions as o, EmbedEventMap as r, ExportFormat as s, CommentsConfig as t, MachineSourceLocations as u };
466
+ export { EmbedMode as a, ExportFormatMap as c, MachineSourceLocations as d, ProjectEmbedMachine as f, EmbedEventName as i, InitOptions as l, UploadResult as m, EmbedEventHandler as n, ExportCallOptions as o, ProtocolMessage as p, EmbedEventMap as r, ExportFormat as s, CommentsConfig as t, MachineInitOptions as u };
package/dist/studio.d.mts CHANGED
@@ -1,2 +1,112 @@
1
- import { a as ProjectMachine, c as StudioClientOptions, i as ProjectData, l as VerifyApiKeyResponse, n as ExtractedMachine, o as StudioApiError, r as GetMachineOptions, s as StudioClient, t as ExtractMachinesResponse, u as createStatelyClient } from "./studio-D2uQhrvX.mjs";
2
- export { ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, StudioApiError, StudioClient, StudioClientOptions, VerifyApiKeyResponse, createStatelyClient };
1
+ //#region src/studio.d.ts
2
+ interface StudioClientOptions {
3
+ baseUrl?: string;
4
+ apiKey?: string;
5
+ fetch?: typeof fetch;
6
+ }
7
+ interface VerifyApiKeyResponse {
8
+ valid: boolean;
9
+ }
10
+ type ProjectVisibility = 'Public' | 'Private' | 'Unlisted';
11
+ type RepoType = 'GITHUB';
12
+ interface ConnectedRepo {
13
+ id?: string;
14
+ type?: RepoType;
15
+ url: string;
16
+ owner: string;
17
+ repo: string;
18
+ branch: string;
19
+ treeSha: string;
20
+ autoSync?: boolean;
21
+ pathForNewFiles?: string;
22
+ selectedPaths?: string[];
23
+ lastSyncedAt?: string;
24
+ }
25
+ interface ProjectMachine {
26
+ machineId: string;
27
+ name: string;
28
+ }
29
+ interface ProjectData {
30
+ projectId: string;
31
+ machines: ProjectMachine[];
32
+ id?: string;
33
+ name?: string;
34
+ description?: string | null;
35
+ keywords?: string[];
36
+ visibility?: ProjectVisibility;
37
+ projectVersionId?: string;
38
+ connectedRepo?: ConnectedRepo | null;
39
+ }
40
+ interface ExtractedMachine {
41
+ id?: string;
42
+ config: Record<string, unknown>;
43
+ setupConfig?: Record<string, unknown>;
44
+ implementations?: Record<string, unknown>;
45
+ _type: 'setup.createMachine' | 'createMachine';
46
+ }
47
+ interface ExtractMachinesResponse {
48
+ machines: ExtractedMachine[];
49
+ error?: string;
50
+ }
51
+ interface GetMachineOptions {
52
+ version?: string;
53
+ }
54
+ interface CreateProjectInput {
55
+ name: string;
56
+ visibility: ProjectVisibility;
57
+ description?: string;
58
+ keywords?: string[];
59
+ repo?: ConnectedRepo;
60
+ }
61
+ interface EnsureProjectInput extends CreateProjectInput {
62
+ matchConnectedRepo?: boolean;
63
+ }
64
+ type XStateVersion = 4 | 5;
65
+ type CreateMachineTemplate = 'blank' | 'starter';
66
+ interface CreateMachineFromDefinitionInput<TDefinition = Record<string, unknown>> {
67
+ projectVersionId: string;
68
+ definition: TDefinition;
69
+ xstateVersion?: XStateVersion;
70
+ }
71
+ interface CreateMachineFromTemplateInput {
72
+ projectVersionId: string;
73
+ name: string;
74
+ template: CreateMachineTemplate;
75
+ xstateVersion?: XStateVersion;
76
+ }
77
+ type CreateMachineInput<TDefinition = Record<string, unknown>> = CreateMachineFromDefinitionInput<TDefinition> | CreateMachineFromTemplateInput;
78
+ interface StudioMachineRecord<TDefinition = Record<string, unknown>> {
79
+ id: string;
80
+ name: string;
81
+ definition: TDefinition;
82
+ projectVersionId?: string;
83
+ [key: string]: unknown;
84
+ }
85
+ declare class StudioApiError extends Error {
86
+ readonly status: number;
87
+ constructor(message: string, status: number);
88
+ }
89
+ interface StudioClient {
90
+ auth: {
91
+ verify(apiKey?: string): Promise<VerifyApiKeyResponse>;
92
+ };
93
+ projects: {
94
+ list(): Promise<ProjectData[]>;
95
+ create(input: CreateProjectInput): Promise<ProjectData>;
96
+ ensure(input: EnsureProjectInput): Promise<ProjectData>;
97
+ get(projectId: string): Promise<ProjectData>;
98
+ };
99
+ machines: {
100
+ create<TMachine = Record<string, unknown>>(input: CreateMachineInput<TMachine>): Promise<StudioMachineRecord<TMachine>>;
101
+ createMany<TMachine = Record<string, unknown>>(input: CreateMachineInput<TMachine>): Promise<Array<StudioMachineRecord<TMachine>>>;
102
+ get<TMachine = Record<string, unknown>>(machineId: string, options?: GetMachineOptions): Promise<TMachine>;
103
+ };
104
+ code: {
105
+ extractMachines(code: string, options?: {
106
+ apiKey?: string | null;
107
+ }): Promise<ExtractMachinesResponse>;
108
+ };
109
+ }
110
+ declare function createStatelyClient(options?: StudioClientOptions): StudioClient;
111
+ //#endregion
112
+ export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, EnsureProjectInput, ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, ProjectVisibility, RepoType, StudioApiError, StudioClient, StudioClientOptions, StudioMachineRecord, VerifyApiKeyResponse, XStateVersion, createStatelyClient };
package/dist/studio.mjs CHANGED
@@ -19,6 +19,37 @@ async function parseJson(response) {
19
19
  if (!response.headers.get("content-type")?.includes("application/json")) return null;
20
20
  return response.json().catch(() => null);
21
21
  }
22
+ function getErrorMessage(data, status) {
23
+ if (typeof data === "object" && data !== null) {
24
+ if ("error" in data && typeof data.error === "string") return data.error;
25
+ if ("error" in data) {
26
+ const error = data.error;
27
+ if (typeof error === "object" && error !== null && "json" in error) {
28
+ const errorJson = error.json;
29
+ if (typeof errorJson === "object" && errorJson !== null && "message" in errorJson && typeof errorJson.message === "string") return errorJson.message;
30
+ }
31
+ }
32
+ }
33
+ if (Array.isArray(data)) for (const item of data) {
34
+ const message = getErrorMessage(item, status);
35
+ if (message !== `HTTP ${status}`) return message;
36
+ }
37
+ return `HTTP ${status}`;
38
+ }
39
+ function unwrapResponseData(data) {
40
+ if (typeof data === "object" && data !== null && "data" in data) return data.data;
41
+ return data;
42
+ }
43
+ function normalizeRepoUrl(url) {
44
+ if (!url) return;
45
+ return url.replace(/\.git$/i, "").replace(/\/+$/, "");
46
+ }
47
+ function connectedReposMatch(left, right) {
48
+ if (!left || !right) return false;
49
+ const normalizedLeft = normalizeRepoUrl(left.url);
50
+ const normalizedRight = normalizeRepoUrl(right.url);
51
+ return normalizedLeft != null && normalizedRight != null && normalizedLeft === normalizedRight && left.branch === right.branch || left.owner === right.owner && left.repo === right.repo && left.branch === right.branch;
52
+ }
22
53
  function createStatelyClient(options = {}) {
23
54
  const baseUrl = options.baseUrl ?? "https://stately.ai";
24
55
  const fetchImpl = getFetch(options.fetch);
@@ -31,22 +62,53 @@ function createStatelyClient(options = {}) {
31
62
  headers
32
63
  });
33
64
  const data = await parseJson(response);
34
- if (!response.ok) throw new StudioApiError(typeof data === "object" && data !== null && "error" in data && typeof data.error === "string" ? data.error : `HTTP ${response.status}`, response.status);
35
- return data;
65
+ if (!response.ok) throw new StudioApiError(getErrorMessage(data, response.status), response.status);
66
+ return unwrapResponseData(data);
36
67
  }
37
68
  return {
38
69
  auth: { verify(apiKey) {
39
70
  return request("/verify", { method: "GET" }, apiKey);
40
71
  } },
41
- projects: { get(projectId) {
42
- return request(`/projects/${encodeURIComponent(projectId)}`, { method: "GET" });
43
- } },
44
- machines: { get(machineId, getOptions = {}) {
45
- const search = new URLSearchParams();
46
- if (getOptions.version) search.set("version", getOptions.version);
47
- const suffix = search.size > 0 ? `?${search.toString()}` : "";
48
- return request(`/machines/${encodeURIComponent(machineId)}${suffix}`, { method: "GET" });
49
- } },
72
+ projects: {
73
+ list() {
74
+ return request("/projects", { method: "GET" });
75
+ },
76
+ create(input) {
77
+ return request("/projects/create", {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json" },
80
+ body: JSON.stringify(input)
81
+ });
82
+ },
83
+ async ensure(input) {
84
+ if (input.repo && input.matchConnectedRepo !== false) {
85
+ const existingProject = (await this.list()).find((project) => connectedReposMatch(project.connectedRepo, input.repo));
86
+ if (existingProject) return existingProject;
87
+ }
88
+ return this.create(input);
89
+ },
90
+ get(projectId) {
91
+ return request(`/projects/${encodeURIComponent(projectId)}`, { method: "GET" });
92
+ }
93
+ },
94
+ machines: {
95
+ async create(input) {
96
+ return request("/machines/create", {
97
+ method: "POST",
98
+ headers: { "Content-Type": "application/json" },
99
+ body: JSON.stringify(input)
100
+ });
101
+ },
102
+ async createMany(input) {
103
+ return [await this.create(input)];
104
+ },
105
+ get(machineId, getOptions = {}) {
106
+ const search = new URLSearchParams();
107
+ if (getOptions.version) search.set("version", getOptions.version);
108
+ const suffix = search.size > 0 ? `?${search.toString()}` : "";
109
+ return request(`/machines/${encodeURIComponent(machineId)}${suffix}`, { method: "GET" });
110
+ }
111
+ },
50
112
  code: { extractMachines(code, extractOptions = {}) {
51
113
  const apiKey = extractOptions.apiKey ?? options.apiKey ?? "anonymous";
52
114
  return request("/code", {