@statelyai/sdk 0.5.1 → 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/README.md +155 -82
- package/dist/api.d.mts +20 -0
- package/dist/api.mjs +56 -0
- package/dist/cli.d.mts +100 -2
- package/dist/cli.mjs +584 -13
- package/dist/embed.d.mts +21 -3
- package/dist/embed.mjs +52 -2
- package/dist/graph.d.mts +1 -1
- package/dist/graph.mjs +20 -7
- package/dist/graphToXStateTS-CvXM8wHL.mjs +344 -0
- package/dist/index.d.mts +29 -140
- package/dist/index.mjs +4 -3
- package/dist/{inspect-ttRIjoCu.d.mts → inspect-DIxB2Tr3.d.mts} +1 -1
- package/dist/inspect.d.mts +2 -2
- package/dist/inspect.mjs +1 -1
- package/dist/{protocol-BPuwbNCz.d.mts → protocol-CEbWQPYe.d.mts} +70 -5
- package/dist/studio.d.mts +112 -2
- package/dist/studio.mjs +73 -11
- package/dist/sync.d.mts +19 -3
- package/dist/sync.mjs +128 -6
- package/dist/{transport-DoCHBLTu.mjs → transport-C0eTgNNu.mjs} +14 -0
- package/package.json +24 -15
- package/schemas/statelyai.schema.json +128 -0
- package/dist/graphToXStateTS-CtecEESq.mjs +0 -568
- package/dist/studio-D2uQhrvX.d.mts +0 -54
- /package/dist/{graph-BfezxFKJ.d.mts → graph-CB-ALrdk.d.mts} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,130 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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-
|
|
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/
|
|
12
|
-
interface
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
interface CodeGenInvoke {
|
|
34
|
-
src: string;
|
|
35
|
-
id: string;
|
|
36
|
-
input?: Record<string, unknown> | CodeExpression;
|
|
37
|
-
output?: Record<string, unknown> | CodeExpression;
|
|
38
|
-
}
|
|
39
|
-
interface CodeGenNodeData {
|
|
40
|
-
nodeId?: string | null;
|
|
41
|
-
key: string;
|
|
42
|
-
type?: 'normal' | 'parallel' | 'final' | 'history' | null;
|
|
43
|
-
initialId?: string | null;
|
|
44
|
-
history?: 'shallow' | 'deep' | boolean;
|
|
45
|
-
entry?: CodeGenAction[];
|
|
46
|
-
exit?: CodeGenAction[];
|
|
47
|
-
invokes?: CodeGenInvoke[];
|
|
48
|
-
tags?: Array<string | {
|
|
49
|
-
name: string;
|
|
50
|
-
}>;
|
|
51
|
-
description?: string | null;
|
|
52
|
-
meta?: Record<string, unknown> | null;
|
|
53
|
-
color?: string;
|
|
54
|
-
parentId?: string | null;
|
|
55
|
-
temp?: boolean;
|
|
56
|
-
}
|
|
57
|
-
interface CodeGenEdgeData {
|
|
58
|
-
eventType: string;
|
|
59
|
-
transitionType?: 'normal' | 'targetless' | 'reenter';
|
|
60
|
-
guard?: CodeGenGuard | null;
|
|
61
|
-
actions?: CodeGenAction[];
|
|
62
|
-
description?: string | null;
|
|
63
|
-
color?: string;
|
|
64
|
-
meta?: Record<string, unknown> | null;
|
|
65
|
-
temp?: boolean;
|
|
66
|
-
}
|
|
67
|
-
interface CodeGenImplementation {
|
|
68
|
-
id: string;
|
|
69
|
-
name: string;
|
|
70
|
-
description?: string | null;
|
|
71
|
-
icon?: string;
|
|
72
|
-
paramsSchema?: JSONSchema7 | null;
|
|
73
|
-
code?: {
|
|
74
|
-
body: string;
|
|
75
|
-
lang?: string;
|
|
76
|
-
} | null;
|
|
77
|
-
}
|
|
78
|
-
interface CodeGenActorImplementation {
|
|
79
|
-
id: string;
|
|
80
|
-
name: string;
|
|
81
|
-
description?: string | null;
|
|
82
|
-
icon?: string;
|
|
83
|
-
inputSchema?: JSONSchema7 | null;
|
|
84
|
-
outputSchema?: JSONSchema7 | null;
|
|
85
|
-
code?: {
|
|
86
|
-
body: string;
|
|
87
|
-
lang?: string;
|
|
88
|
-
} | null;
|
|
89
|
-
}
|
|
90
|
-
interface CodeGenGraphData {
|
|
91
|
-
schemas?: {
|
|
92
|
-
context?: Record<string, JSONSchema7> | null;
|
|
93
|
-
events?: Record<string, JSONSchema7> | null;
|
|
94
|
-
input?: JSONSchema7 | null;
|
|
95
|
-
output?: JSONSchema7 | null;
|
|
96
|
-
} | null;
|
|
97
|
-
implementations?: {
|
|
98
|
-
actions: CodeGenImplementation[];
|
|
99
|
-
guards: CodeGenImplementation[];
|
|
100
|
-
actors: CodeGenActorImplementation[];
|
|
101
|
-
delays: CodeGenImplementation[];
|
|
102
|
-
} | null;
|
|
103
|
-
}
|
|
104
|
-
interface CodeGenNode {
|
|
105
|
-
id: string;
|
|
106
|
-
parentId?: string | null;
|
|
107
|
-
data: CodeGenNodeData;
|
|
108
|
-
}
|
|
109
|
-
interface CodeGenEdge {
|
|
110
|
-
id: string;
|
|
111
|
-
sourceId: string;
|
|
112
|
-
targetId: string;
|
|
113
|
-
data: CodeGenEdgeData;
|
|
114
|
-
}
|
|
115
|
-
interface CodeGenGraph {
|
|
116
|
-
id: string;
|
|
117
|
-
nodes: CodeGenNode[];
|
|
118
|
-
edges: CodeGenEdge[];
|
|
119
|
-
data: CodeGenGraphData;
|
|
120
|
-
}
|
|
121
|
-
//#endregion
|
|
122
|
-
//#region src/graphToMachineConfig.d.ts
|
|
123
|
-
interface MachineConfigOptions {
|
|
124
|
-
showDescriptions?: boolean;
|
|
125
|
-
showMeta?: boolean;
|
|
126
|
-
}
|
|
127
|
-
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;
|
|
128
33
|
//#endregion
|
|
129
34
|
//#region src/graphToXStateTS.d.ts
|
|
130
35
|
interface XStateTSOptions extends MachineConfigOptions {
|
|
@@ -132,22 +37,6 @@ interface XStateTSOptions extends MachineConfigOptions {
|
|
|
132
37
|
}
|
|
133
38
|
declare function graphToXStateTS(graph: CodeGenGraph, options?: XStateTSOptions): string;
|
|
134
39
|
//#endregion
|
|
135
|
-
//#region src/serializeJS.d.ts
|
|
136
|
-
/**
|
|
137
|
-
* Serializes JavaScript values as JS source code (not JSON).
|
|
138
|
-
* - Unquoted keys for valid identifiers
|
|
139
|
-
* - Single-quoted strings
|
|
140
|
-
* - Omits undefined values
|
|
141
|
-
* - Supports RawCode for verbatim expressions
|
|
142
|
-
* - Supports inline expression directives for verbatim expressions
|
|
143
|
-
*/
|
|
144
|
-
declare class RawCode {
|
|
145
|
-
code: string;
|
|
146
|
-
constructor(code: string);
|
|
147
|
-
}
|
|
148
|
-
declare function raw(code: string): RawCode;
|
|
149
|
-
declare function serializeJS(value: unknown, indent?: number, step?: number): string;
|
|
150
|
-
//#endregion
|
|
151
40
|
//#region src/jsonSchemaToTSType.d.ts
|
|
152
41
|
declare function jsonSchemaToTSType(schema: JSONSchema7 | undefined | null): string;
|
|
153
42
|
/**
|
|
@@ -161,4 +50,4 @@ declare function contextSchemaToTSType(context: Record<string, JSONSchema7> | nu
|
|
|
161
50
|
*/
|
|
162
51
|
declare function eventsSchemaToTSType(events: Record<string, JSONSchema7> | null | undefined): string | null;
|
|
163
52
|
//#endregion
|
|
164
|
-
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-
|
|
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-CtecEESq.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,
|
|
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 {
|
package/dist/inspect.d.mts
CHANGED
|
@@ -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-
|
|
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-
|
|
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-
|
|
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) => ({
|
|
@@ -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[];
|
|
@@ -74,7 +79,7 @@ interface ExportFormatMap {
|
|
|
74
79
|
options: object;
|
|
75
80
|
result: string;
|
|
76
81
|
};
|
|
77
|
-
|
|
82
|
+
redux: {
|
|
78
83
|
options: object;
|
|
79
84
|
result: string;
|
|
80
85
|
};
|
|
@@ -105,17 +110,20 @@ interface EmbedEventMap {
|
|
|
105
110
|
};
|
|
106
111
|
loaded: {
|
|
107
112
|
graph: unknown;
|
|
113
|
+
machineId?: string;
|
|
108
114
|
sourceLocations?: MachineSourceLocations;
|
|
109
115
|
};
|
|
110
116
|
change: {
|
|
111
117
|
graph: unknown;
|
|
112
118
|
machineConfig: unknown;
|
|
119
|
+
machineId?: string;
|
|
113
120
|
patches?: unknown[];
|
|
114
121
|
sourceLocations?: MachineSourceLocations;
|
|
115
122
|
};
|
|
116
123
|
save: {
|
|
117
124
|
graph: unknown;
|
|
118
125
|
machineConfig: unknown;
|
|
126
|
+
machineId?: string;
|
|
119
127
|
patches?: unknown[];
|
|
120
128
|
validations?: ValidationIssue[];
|
|
121
129
|
sourceLocations?: MachineSourceLocations;
|
|
@@ -128,10 +136,13 @@ interface EmbedEventMap {
|
|
|
128
136
|
snapshot: unknown;
|
|
129
137
|
event: unknown | null;
|
|
130
138
|
};
|
|
139
|
+
machineSelected: {
|
|
140
|
+
machineId: string;
|
|
141
|
+
};
|
|
131
142
|
}
|
|
132
143
|
type EmbedEventName = keyof EmbedEventMap;
|
|
133
144
|
type EmbedEventHandler<K extends EmbedEventName> = (data: EmbedEventMap[K]) => void;
|
|
134
|
-
interface
|
|
145
|
+
interface MachineInitOptions {
|
|
135
146
|
machine: unknown;
|
|
136
147
|
format?: string;
|
|
137
148
|
mode?: EmbedMode;
|
|
@@ -162,6 +173,25 @@ interface InitOptions {
|
|
|
162
173
|
mode?: 'structural' | 'all';
|
|
163
174
|
};
|
|
164
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;
|
|
165
195
|
interface InitMessage {
|
|
166
196
|
type: '@statelyai.init';
|
|
167
197
|
machine: unknown;
|
|
@@ -183,6 +213,34 @@ interface InitMessage {
|
|
|
183
213
|
/** Optional session id override (multiplexed clients only). */
|
|
184
214
|
sessionId?: string;
|
|
185
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
|
+
}
|
|
186
244
|
interface UpdateMessage {
|
|
187
245
|
type: '@statelyai.update';
|
|
188
246
|
machine: unknown;
|
|
@@ -280,12 +338,14 @@ interface ReadyMessage {
|
|
|
280
338
|
interface LoadedMessage {
|
|
281
339
|
type: '@statelyai.loaded';
|
|
282
340
|
graph: unknown;
|
|
341
|
+
machineId?: string;
|
|
283
342
|
sourceLocations?: MachineSourceLocations;
|
|
284
343
|
}
|
|
285
344
|
interface ChangeMessage {
|
|
286
345
|
type: '@statelyai.change';
|
|
287
346
|
graph: unknown;
|
|
288
347
|
machineConfig: unknown;
|
|
348
|
+
machineId?: string;
|
|
289
349
|
patches?: unknown[];
|
|
290
350
|
sourceLocations?: MachineSourceLocations;
|
|
291
351
|
}
|
|
@@ -293,10 +353,15 @@ interface SaveMessage {
|
|
|
293
353
|
type: '@statelyai.save';
|
|
294
354
|
graph: unknown;
|
|
295
355
|
machineConfig: unknown;
|
|
356
|
+
machineId?: string;
|
|
296
357
|
patches?: unknown[];
|
|
297
358
|
validations?: ValidationIssue[];
|
|
298
359
|
sourceLocations?: MachineSourceLocations;
|
|
299
360
|
}
|
|
361
|
+
interface ProjectMachineSelectedMessage {
|
|
362
|
+
type: '@statelyai.project.machineSelected';
|
|
363
|
+
machineId: string;
|
|
364
|
+
}
|
|
300
365
|
interface RetrievedMessage {
|
|
301
366
|
type: '@statelyai.retrieved';
|
|
302
367
|
requestId: string;
|
|
@@ -349,9 +414,9 @@ interface UploadResponseMessage {
|
|
|
349
414
|
result: UploadResult;
|
|
350
415
|
}
|
|
351
416
|
/** All messages a client (embed/inspector) can send to the viz. */
|
|
352
|
-
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;
|
|
353
418
|
/** All messages the viz can send back to a client. */
|
|
354
|
-
type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | RetrievedMessage | ErrorMessage | UploadRequestMessage;
|
|
419
|
+
type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | UploadRequestMessage;
|
|
355
420
|
interface RegisterMessage {
|
|
356
421
|
type: '@statelyai.register';
|
|
357
422
|
role: 'client' | 'viz';
|
|
@@ -398,4 +463,4 @@ type SessionMessage = RegisterMessage | RegisteredMessage | RequestOpenMessage |
|
|
|
398
463
|
/** Any valid protocol message. */
|
|
399
464
|
type ProtocolMessage = ClientMessage | VizMessage | SessionMessage;
|
|
400
465
|
//#endregion
|
|
401
|
-
export { EmbedMode as a, ExportFormatMap as c,
|
|
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
|
-
|
|
2
|
-
|
|
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(
|
|
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: {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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", {
|
package/dist/sync.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CreateProjectInput, ProjectData, StudioClient, StudioMachineRecord, XStateVersion } from "./studio.mjs";
|
|
2
|
+
import { b as DigraphConfig, i as StatelyGraph } from "./graph-CB-ALrdk.mjs";
|
|
3
3
|
import { GraphDiff } from "@statelyai/graph";
|
|
4
4
|
|
|
5
5
|
//#region src/sync.d.ts
|
|
@@ -19,6 +19,7 @@ interface ResolvedSyncInput {
|
|
|
19
19
|
locator: string;
|
|
20
20
|
format: SyncInputFormat;
|
|
21
21
|
graph: StatelyGraph;
|
|
22
|
+
remoteMachineId?: string;
|
|
22
23
|
}
|
|
23
24
|
interface SyncPlanSummary {
|
|
24
25
|
hasChanges: boolean;
|
|
@@ -37,7 +38,22 @@ interface PullSyncResult {
|
|
|
37
38
|
target: ResolvedSyncInput;
|
|
38
39
|
outputPath: string;
|
|
39
40
|
}
|
|
41
|
+
interface PushSyncProjectOptions extends CreateProjectInput {
|
|
42
|
+
projectId?: string;
|
|
43
|
+
projectVersionId?: string;
|
|
44
|
+
}
|
|
45
|
+
interface PushSyncOptions extends Omit<PlanSyncOptions, 'target'> {
|
|
46
|
+
project?: PushSyncProjectOptions;
|
|
47
|
+
xstateVersion?: XStateVersion;
|
|
48
|
+
}
|
|
49
|
+
interface PushSyncResult {
|
|
50
|
+
source: ResolvedSyncInput;
|
|
51
|
+
project: ProjectData;
|
|
52
|
+
machine: StudioMachineRecord<DigraphConfig>;
|
|
53
|
+
outputPath?: string;
|
|
54
|
+
}
|
|
40
55
|
declare function planSync(options: PlanSyncOptions): Promise<SyncPlan>;
|
|
41
56
|
declare function pullSync(options: PlanSyncOptions): Promise<PullSyncResult>;
|
|
57
|
+
declare function pushSync(options: PushSyncOptions): Promise<PushSyncResult>;
|
|
42
58
|
//#endregion
|
|
43
|
-
export { PlanSyncOptions, PullSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary, planSync, pullSync };
|
|
59
|
+
export { PlanSyncOptions, PullSyncResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary, planSync, pullSync, pushSync };
|