@statelyai/sdk 0.4.1 → 0.5.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/LICENSE +7 -675
- package/README.md +269 -161
- package/dist/cli.d.mts +24 -5
- package/dist/cli.mjs +719 -18
- package/dist/embed.d.mts +3 -3
- package/dist/embed.mjs +23 -9
- package/dist/graph.mjs +27 -19
- package/dist/{graphToXStateTS-Cfp_fxSH.mjs → graphToXStateTS-CtecEESq.mjs} +58 -20
- package/dist/index.d.mts +20 -35
- package/dist/index.mjs +2 -2
- package/dist/inspect-ttRIjoCu.d.mts +206 -0
- package/dist/inspect.d.mts +3 -49
- package/dist/inspect.mjs +229 -62
- package/dist/patchTypes.d.mts +249 -0
- package/dist/patchTypes.mjs +1 -0
- package/dist/protocol-BPuwbNCz.d.mts +401 -0
- package/dist/sync.mjs +1 -1
- package/dist/{transport-C1fRAuv-.mjs → transport-DoCHBLTu.mjs} +19 -14
- package/package.json +12 -4
- package/dist/protocol-CZVFCSg3.d.mts +0 -225
package/dist/embed.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as EmbedMode, c as ExportFormatMap,
|
|
1
|
+
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, u as MachineSourceLocations } from "./protocol-BPuwbNCz.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/embed.d.ts
|
|
4
4
|
interface AssetConfig {
|
|
@@ -44,7 +44,7 @@ interface StatelyEmbed {
|
|
|
44
44
|
/** Send init message (queued if iframe not ready yet). */
|
|
45
45
|
init(options: InitOptions): void;
|
|
46
46
|
/** Update the machine (shorthand for update message). */
|
|
47
|
-
updateMachine(machine: unknown, format?: string): void;
|
|
47
|
+
updateMachine(machine: unknown, format?: string, sourceLocations?: MachineSourceLocations): void;
|
|
48
48
|
/** Change the embed mode. */
|
|
49
49
|
setMode(mode: EmbedMode): void;
|
|
50
50
|
/** Change the embed theme. */
|
|
@@ -64,4 +64,4 @@ interface StatelyEmbed {
|
|
|
64
64
|
}
|
|
65
65
|
declare function createStatelyEmbed(options: StatelyEmbedOptions): StatelyEmbed;
|
|
66
66
|
//#endregion
|
|
67
|
-
export { AssetConfig, type CommentsConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type InitOptions, StatelyEmbed, StatelyEmbedOptions, type UploadResult, createStatelyEmbed };
|
|
67
|
+
export { AssetConfig, type CommentsConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type InitOptions, type MachineSourceLocations, StatelyEmbed, StatelyEmbedOptions, type UploadResult, createStatelyEmbed };
|
package/dist/embed.mjs
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as toInitMessage, i as createPendingExportManager, r as createEventRegistry, t as createPostMessageTransport } from "./transport-DoCHBLTu.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/embed.ts
|
|
4
|
-
function
|
|
4
|
+
function buildEmbedUrl(options) {
|
|
5
5
|
const base = options.baseUrl.replace(/\/+$/, "") + "/embed";
|
|
6
|
-
const
|
|
7
|
-
|
|
6
|
+
const url = new URL(base);
|
|
7
|
+
if (options.apiKey) url.searchParams.set("api_key", options.apiKey);
|
|
8
|
+
return url.toString();
|
|
9
|
+
}
|
|
10
|
+
function createStatelyEmbed(options) {
|
|
11
|
+
const embedUrl = buildEmbedUrl(options);
|
|
12
|
+
const targetOrigin = options.origin ?? "*";
|
|
8
13
|
let iframe = null;
|
|
9
14
|
let transport = null;
|
|
10
15
|
let ownedIframe = false;
|
|
@@ -45,7 +50,10 @@ function createStatelyEmbed(options) {
|
|
|
45
50
|
case "@statelyai.loaded": {
|
|
46
51
|
const loaded = data;
|
|
47
52
|
options.onLoaded?.(loaded.graph);
|
|
48
|
-
events.emit("loaded", {
|
|
53
|
+
events.emit("loaded", {
|
|
54
|
+
graph: loaded.graph,
|
|
55
|
+
sourceLocations: loaded.sourceLocations
|
|
56
|
+
});
|
|
49
57
|
break;
|
|
50
58
|
}
|
|
51
59
|
case "@statelyai.change": {
|
|
@@ -53,7 +61,9 @@ function createStatelyEmbed(options) {
|
|
|
53
61
|
options.onChange?.(change.graph, change.machineConfig);
|
|
54
62
|
events.emit("change", {
|
|
55
63
|
graph: change.graph,
|
|
56
|
-
machineConfig: change.machineConfig
|
|
64
|
+
machineConfig: change.machineConfig,
|
|
65
|
+
patches: change.patches,
|
|
66
|
+
sourceLocations: change.sourceLocations
|
|
57
67
|
});
|
|
58
68
|
break;
|
|
59
69
|
}
|
|
@@ -62,7 +72,10 @@ function createStatelyEmbed(options) {
|
|
|
62
72
|
options.onSave?.(save.graph, save.machineConfig);
|
|
63
73
|
events.emit("save", {
|
|
64
74
|
graph: save.graph,
|
|
65
|
-
machineConfig: save.machineConfig
|
|
75
|
+
machineConfig: save.machineConfig,
|
|
76
|
+
patches: save.patches,
|
|
77
|
+
validations: save.validations,
|
|
78
|
+
sourceLocations: save.sourceLocations
|
|
66
79
|
});
|
|
67
80
|
break;
|
|
68
81
|
}
|
|
@@ -169,11 +182,12 @@ function createStatelyEmbed(options) {
|
|
|
169
182
|
init(opts) {
|
|
170
183
|
send(toInitMessage(opts));
|
|
171
184
|
},
|
|
172
|
-
updateMachine(machine, format) {
|
|
185
|
+
updateMachine(machine, format, sourceLocations) {
|
|
173
186
|
send({
|
|
174
187
|
type: "@statelyai.update",
|
|
175
188
|
machine,
|
|
176
|
-
format
|
|
189
|
+
format,
|
|
190
|
+
sourceLocations
|
|
177
191
|
});
|
|
178
192
|
},
|
|
179
193
|
setMode(mode) {
|
package/dist/graph.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createFormatConverter, createGraph } from "@statelyai/graph";
|
|
2
2
|
|
|
3
3
|
//#region src/graph.ts
|
|
4
|
+
const EXPR_ACTION_TYPE = "xstate.expr";
|
|
4
5
|
function toJsonObject(value) {
|
|
5
6
|
return value;
|
|
6
7
|
}
|
|
@@ -31,17 +32,17 @@ function normalizeStudioHistory(history) {
|
|
|
31
32
|
if (history === true) return "shallow";
|
|
32
33
|
return history || void 0;
|
|
33
34
|
}
|
|
34
|
-
function toActionSource(
|
|
35
|
+
function toActionSource(implementation) {
|
|
35
36
|
return {
|
|
36
37
|
type: "action",
|
|
37
|
-
id:
|
|
38
|
-
name:
|
|
39
|
-
...
|
|
40
|
-
...
|
|
41
|
-
lang:
|
|
38
|
+
id: implementation.id,
|
|
39
|
+
name: implementation.name,
|
|
40
|
+
...implementation.description ? { description: implementation.description } : {},
|
|
41
|
+
...implementation.icon ? { icon: implementation.icon } : {},
|
|
42
|
+
lang: implementation.code?.lang ?? "js",
|
|
42
43
|
imports: [],
|
|
43
|
-
code:
|
|
44
|
-
...
|
|
44
|
+
code: implementation.code?.body,
|
|
45
|
+
...implementation.paramsSchema ? { paramsSchema: implementation.paramsSchema } : {}
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
function toGuardSource(guard) {
|
|
@@ -72,16 +73,16 @@ function toActorSource(actor) {
|
|
|
72
73
|
...actor.outputSchema ? { outputSchema: actor.outputSchema } : {}
|
|
73
74
|
};
|
|
74
75
|
}
|
|
75
|
-
function fromActionSource(
|
|
76
|
+
function fromActionSource(source) {
|
|
76
77
|
return {
|
|
77
|
-
id:
|
|
78
|
-
name:
|
|
79
|
-
description:
|
|
80
|
-
...
|
|
81
|
-
paramsSchema:
|
|
82
|
-
...
|
|
83
|
-
body:
|
|
84
|
-
...
|
|
78
|
+
id: source.id,
|
|
79
|
+
name: source.name,
|
|
80
|
+
description: source.description ?? null,
|
|
81
|
+
...source.icon ? { icon: source.icon } : {},
|
|
82
|
+
paramsSchema: source.paramsSchema ?? null,
|
|
83
|
+
...source.code ? { code: {
|
|
84
|
+
body: source.code,
|
|
85
|
+
...source.lang ? { lang: source.lang } : {}
|
|
85
86
|
} } : {}
|
|
86
87
|
};
|
|
87
88
|
}
|
|
@@ -113,6 +114,10 @@ function fromActorSource(actor) {
|
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
116
|
function toStudioAction(action) {
|
|
117
|
+
if (action.type === EXPR_ACTION_TYPE && typeof action.params?.code === "string") return {
|
|
118
|
+
kind: "inline",
|
|
119
|
+
action: { expr: action.params.code }
|
|
120
|
+
};
|
|
116
121
|
return {
|
|
117
122
|
kind: "named",
|
|
118
123
|
action: {
|
|
@@ -123,8 +128,11 @@ function toStudioAction(action) {
|
|
|
123
128
|
}
|
|
124
129
|
function fromStudioAction(action) {
|
|
125
130
|
if (action.kind === "inline") return {
|
|
126
|
-
type:
|
|
127
|
-
params: {
|
|
131
|
+
type: EXPR_ACTION_TYPE,
|
|
132
|
+
params: {
|
|
133
|
+
code: action.action.expr,
|
|
134
|
+
lang: "ts"
|
|
135
|
+
}
|
|
128
136
|
};
|
|
129
137
|
if ("params" in action.action && action.action.params) return {
|
|
130
138
|
type: action.action.type,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - Single-quoted strings
|
|
6
6
|
* - Omits undefined values
|
|
7
7
|
* - Supports RawCode for verbatim expressions
|
|
8
|
+
* - Supports inline expression directives for verbatim expressions
|
|
8
9
|
*/
|
|
9
10
|
const VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
10
11
|
var RawCode = class {
|
|
@@ -17,6 +18,7 @@ function raw(code) {
|
|
|
17
18
|
}
|
|
18
19
|
function serializeJS(value, indent = 0, step = 2) {
|
|
19
20
|
if (value instanceof RawCode) return value.code;
|
|
21
|
+
if (isInlineExpressionDirective(value)) return value.expr;
|
|
20
22
|
if (value === void 0) return "undefined";
|
|
21
23
|
if (value === null) return "null";
|
|
22
24
|
if (typeof value === "string") return `'${escapeString(value)}'`;
|
|
@@ -45,10 +47,18 @@ function serializeObject(obj, indent, step) {
|
|
|
45
47
|
return `{\n${entries.map(([key, val]) => {
|
|
46
48
|
const k = VALID_IDENT.test(key) ? key : `'${escapeString(key)}'`;
|
|
47
49
|
const serialized = serializeJS(val, inner, step);
|
|
48
|
-
if (val
|
|
50
|
+
if (isRawExpression(val) && serialized.includes("\n")) return `${pad}${k}: ${indentRawCode(serialized, inner)}`;
|
|
49
51
|
return `${pad}${k}: ${serialized}`;
|
|
50
52
|
}).join(",\n")},\n${closePad}}`;
|
|
51
53
|
}
|
|
54
|
+
function isRawExpression(value) {
|
|
55
|
+
return value instanceof RawCode || isInlineExpressionDirective(value);
|
|
56
|
+
}
|
|
57
|
+
function isInlineExpressionDirective(value) {
|
|
58
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
59
|
+
const directive = value;
|
|
60
|
+
return directive["@type"] === "code" && typeof directive.expr === "string";
|
|
61
|
+
}
|
|
52
62
|
function indentRawCode(code, indent) {
|
|
53
63
|
const lines = code.split("\n");
|
|
54
64
|
if (lines.length <= 1) return code;
|
|
@@ -84,14 +94,17 @@ function stripExportDefault(code) {
|
|
|
84
94
|
|
|
85
95
|
//#endregion
|
|
86
96
|
//#region src/graphToMachineConfig.ts
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
97
|
+
function isAutoGeneratedId(id) {
|
|
98
|
+
return !!id && id.startsWith("$auto-");
|
|
99
|
+
}
|
|
100
|
+
function getSerializedNodeId(node) {
|
|
101
|
+
return node.data.nodeId ?? void 0;
|
|
102
|
+
}
|
|
103
|
+
function getDefaultNodeId(graph, node) {
|
|
104
|
+
if (!node.parentId) return "(machine)";
|
|
105
|
+
const parentNode = graph.nodes.find((candidate) => candidate.id === node.parentId);
|
|
106
|
+
if (!parentNode) return `${node.parentId}.${node.data.key}`;
|
|
107
|
+
return `${getSerializedNodeId(parentNode) ?? getDefaultNodeId(graph, parentNode)}.${node.data.key}`;
|
|
95
108
|
}
|
|
96
109
|
/** Unwrap single-element arrays to a single value (XState single-or-array convention) */
|
|
97
110
|
function singleOrArray(arr) {
|
|
@@ -169,6 +182,7 @@ function formatEventParam(event) {
|
|
|
169
182
|
*/
|
|
170
183
|
function serializeActionItem(action) {
|
|
171
184
|
const { type, params } = action;
|
|
185
|
+
const exprCode = type === "xstate.expr" && typeof params?.code === "string" ? params.code : void 0;
|
|
172
186
|
switch (type) {
|
|
173
187
|
case "xstate.raise": {
|
|
174
188
|
const eventStr = formatEventParam(params?.event);
|
|
@@ -196,9 +210,14 @@ function serializeActionItem(action) {
|
|
|
196
210
|
}
|
|
197
211
|
case "xstate.stopChild": return raw(`stopChild(${params?.actorRef ? `'${params.actorRef}'` : `'unknown'`})`);
|
|
198
212
|
case "xstate.log": return raw(`log(${(params?.label ? `'${params.label}'` : void 0) ?? ""})`);
|
|
199
|
-
case "xstate.assign":
|
|
213
|
+
case "xstate.assign": {
|
|
214
|
+
const assignments = params?.assignment && typeof params.assignment === "object" && !Array.isArray(params.assignment) ? params.assignment : params;
|
|
215
|
+
const entries = Object.entries(assignments ?? {}).filter(([k, v]) => k && v !== void 0);
|
|
216
|
+
if (entries.length === 0) return raw(`assign({ /* ... */ })`);
|
|
217
|
+
return raw(`assign({ ${entries.map(([k, v]) => `${JSON.stringify(k)}: ${formatAssignValue(v)}`).join(", ")} })`);
|
|
218
|
+
}
|
|
200
219
|
default:
|
|
201
|
-
if (
|
|
220
|
+
if (exprCode) return raw(stripExportDefault(exprCode));
|
|
202
221
|
if (!params || Object.keys(params).length === 0) return { type };
|
|
203
222
|
return {
|
|
204
223
|
type,
|
|
@@ -206,6 +225,12 @@ function serializeActionItem(action) {
|
|
|
206
225
|
};
|
|
207
226
|
}
|
|
208
227
|
}
|
|
228
|
+
function formatAssignValue(value) {
|
|
229
|
+
if (typeof value !== "string") return JSON.stringify(value);
|
|
230
|
+
const templateExpression = value.match(/^\{\{([\s\S]*)\}\}$/);
|
|
231
|
+
if (templateExpression) return templateExpression[1];
|
|
232
|
+
return JSON.stringify(value);
|
|
233
|
+
}
|
|
209
234
|
/** Normalize tag to string — handles both `string` and `{ name: string }` */
|
|
210
235
|
function tagToString(tag) {
|
|
211
236
|
return typeof tag === "string" ? tag : tag.name;
|
|
@@ -215,8 +240,10 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
215
240
|
const config = {};
|
|
216
241
|
function getNodeConfig(node) {
|
|
217
242
|
const nodeConfig = node.parentId ? {} : config;
|
|
218
|
-
const
|
|
219
|
-
const
|
|
243
|
+
const isRoot = !node.parentId;
|
|
244
|
+
const authoredNodeId = getSerializedNodeId(node) ?? (isRoot ? graph.id : void 0);
|
|
245
|
+
const defaultNodeId = getDefaultNodeId(graph, node);
|
|
246
|
+
const resolvedNodeId = isAutoGeneratedId(authoredNodeId) ? void 0 : isRoot ? authoredNodeId : defaultNodeId === authoredNodeId ? void 0 : authoredNodeId;
|
|
220
247
|
const initialNode = node.data.initialId ? graph.nodes.find((n) => n.id === node.data.initialId) : null;
|
|
221
248
|
const nodeType = [
|
|
222
249
|
"final",
|
|
@@ -233,7 +260,8 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
233
260
|
...node.data.invokes?.length ? { invoke: node.data.invokes.map((inv) => ({
|
|
234
261
|
src: inv.src,
|
|
235
262
|
id: inv.id,
|
|
236
|
-
...inv.input ? { input: inv.input } : void 0
|
|
263
|
+
...inv.input ? { input: inv.input } : void 0,
|
|
264
|
+
...inv.output ? { output: inv.output } : void 0
|
|
237
265
|
})) } : void 0,
|
|
238
266
|
...tags?.length ? { tags: tags.map(tagToString) } : void 0,
|
|
239
267
|
...showDescriptions && node.data.description ? { description: node.data.description } : void 0,
|
|
@@ -303,6 +331,11 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
303
331
|
};
|
|
304
332
|
});
|
|
305
333
|
}
|
|
334
|
+
if (Array.isArray(nodeConfig.invoke)) nodeConfig.invoke = nodeConfig.invoke.map((inv) => {
|
|
335
|
+
if (!isAutoGeneratedId(inv.id)) return inv;
|
|
336
|
+
const { id: _id, ...rest } = inv;
|
|
337
|
+
return rest;
|
|
338
|
+
});
|
|
306
339
|
if (childNodes.length > 0) {
|
|
307
340
|
nodeConfig.states = {};
|
|
308
341
|
for (const childState of childNodes) nodeConfig.states[childState.data.key] = getNodeConfig(childState);
|
|
@@ -442,17 +475,22 @@ function scanInlineCodeForBuiltins(code, used) {
|
|
|
442
475
|
const expr = stripExportDefault(code);
|
|
443
476
|
for (const importName of Object.values(BUILTIN_ACTION_IMPORTS)) if (new RegExp(`\\b${importName}\\b`).test(expr)) used.add(importName);
|
|
444
477
|
}
|
|
478
|
+
function getExprActionCode(action) {
|
|
479
|
+
return action.type === "xstate.expr" && typeof action.params?.code === "string" ? action.params.code : void 0;
|
|
480
|
+
}
|
|
445
481
|
function getUsedBuiltInActions(graph) {
|
|
446
482
|
const used = /* @__PURE__ */ new Set();
|
|
447
483
|
for (const node of graph.nodes) for (const action of [...node.data.entry ?? [], ...node.data.exit ?? []]) {
|
|
448
484
|
const imp = BUILTIN_ACTION_IMPORTS[action.type];
|
|
449
485
|
if (imp) used.add(imp);
|
|
450
|
-
|
|
486
|
+
const exprCode = getExprActionCode(action);
|
|
487
|
+
if (exprCode) scanInlineCodeForBuiltins(exprCode, used);
|
|
451
488
|
}
|
|
452
489
|
for (const edge of graph.edges) for (const action of edge.data.actions ?? []) {
|
|
453
490
|
const imp = BUILTIN_ACTION_IMPORTS[action.type];
|
|
454
491
|
if (imp) used.add(imp);
|
|
455
|
-
|
|
492
|
+
const exprCode = getExprActionCode(action);
|
|
493
|
+
if (exprCode) scanInlineCodeForBuiltins(exprCode, used);
|
|
456
494
|
}
|
|
457
495
|
return used;
|
|
458
496
|
}
|
|
@@ -497,10 +535,10 @@ function hasSchemaProperties(schema) {
|
|
|
497
535
|
}
|
|
498
536
|
function buildActionsBlock(actions) {
|
|
499
537
|
const block = {};
|
|
500
|
-
for (const
|
|
501
|
-
const params = hasSchemaProperties(
|
|
502
|
-
block[
|
|
503
|
-
} else block[
|
|
538
|
+
for (const implementation of actions) if (implementation.code?.body) {
|
|
539
|
+
const params = hasSchemaProperties(implementation.paramsSchema) ? `, params: ${jsonSchemaToTSType(implementation.paramsSchema)}` : "";
|
|
540
|
+
block[implementation.name] = raw(`function ({ context, event }${params ? params : ""}) {\n ${dedent(implementation.code.body)}\n}`);
|
|
541
|
+
} else block[implementation.name] = raw(`function ({ context, event }) {\n // TODO: implement ${implementation.name}\n}`);
|
|
504
542
|
return block;
|
|
505
543
|
}
|
|
506
544
|
function buildGuardsBlock(guards) {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,59 +1,43 @@
|
|
|
1
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
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
3
|
import { PlanSyncOptions, PullSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
|
|
4
|
-
import { a as EmbedMode, c as ExportFormatMap,
|
|
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-BPuwbNCz.mjs";
|
|
5
5
|
import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
|
|
6
|
-
import { CreateInspectorOptions,
|
|
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-ttRIjoCu.mjs";
|
|
7
|
+
import { ActionLocation, GraphPatch } from "./patchTypes.mjs";
|
|
7
8
|
import { JSONSchema7 } from "json-schema";
|
|
8
9
|
import { UnknownMachineConfig } from "xstate";
|
|
9
10
|
|
|
10
|
-
//#region src/transport.d.ts
|
|
11
|
-
interface Transport {
|
|
12
|
-
send(msg: ProtocolMessage): void;
|
|
13
|
-
onMessage(handler: (msg: ProtocolMessage) => void): () => void;
|
|
14
|
-
destroy(): void;
|
|
15
|
-
readonly ready: boolean;
|
|
16
|
-
onReady(handler: () => void): () => void;
|
|
17
|
-
}
|
|
18
|
-
interface PostMessageTransportOptions {
|
|
19
|
-
iframe: HTMLIFrameElement;
|
|
20
|
-
targetOrigin: string;
|
|
21
|
-
/** Filter by source. Defaults to iframe.contentWindow. */
|
|
22
|
-
source?: Window;
|
|
23
|
-
}
|
|
24
|
-
declare function createPostMessageTransport(options: PostMessageTransportOptions): Transport;
|
|
25
|
-
interface WebSocketTransportOptions {
|
|
26
|
-
url: string;
|
|
27
|
-
role: 'client' | 'viz';
|
|
28
|
-
sessionId: string;
|
|
29
|
-
metadata?: {
|
|
30
|
-
name?: string;
|
|
31
|
-
machineId?: string;
|
|
32
|
-
};
|
|
33
|
-
/** Reconnect on disconnect. Default true. */
|
|
34
|
-
reconnect?: boolean;
|
|
35
|
-
/** Max reconnect attempts. Default 10. */
|
|
36
|
-
maxReconnectAttempts?: number;
|
|
37
|
-
}
|
|
38
|
-
declare function createWebSocketTransport(options: WebSocketTransportOptions): Transport;
|
|
39
|
-
//#endregion
|
|
40
11
|
//#region src/codegenTypes.d.ts
|
|
41
12
|
interface CodeGenAction {
|
|
42
13
|
type: string;
|
|
43
14
|
params?: Record<string, unknown>;
|
|
44
|
-
code?: string;
|
|
45
15
|
}
|
|
46
16
|
interface CodeGenGuard {
|
|
47
17
|
type: string;
|
|
48
18
|
code?: string;
|
|
49
19
|
params?: Record<string, unknown>;
|
|
50
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Serialized inline expression directive.
|
|
23
|
+
*
|
|
24
|
+
* Code generation treats this object as JavaScript/TypeScript source, not as a
|
|
25
|
+
* machine config object. It is used for fields such as invoke `input` and
|
|
26
|
+
* `output` where XState accepts mapper expressions.
|
|
27
|
+
*/
|
|
28
|
+
interface CodeExpression {
|
|
29
|
+
'@type': 'code';
|
|
30
|
+
lang: 'js' | 'ts';
|
|
31
|
+
expr: string;
|
|
32
|
+
}
|
|
51
33
|
interface CodeGenInvoke {
|
|
52
34
|
src: string;
|
|
53
35
|
id: string;
|
|
54
|
-
input?: unknown;
|
|
36
|
+
input?: Record<string, unknown> | CodeExpression;
|
|
37
|
+
output?: Record<string, unknown> | CodeExpression;
|
|
55
38
|
}
|
|
56
39
|
interface CodeGenNodeData {
|
|
40
|
+
nodeId?: string | null;
|
|
57
41
|
key: string;
|
|
58
42
|
type?: 'normal' | 'parallel' | 'final' | 'history' | null;
|
|
59
43
|
initialId?: string | null;
|
|
@@ -155,6 +139,7 @@ declare function graphToXStateTS(graph: CodeGenGraph, options?: XStateTSOptions)
|
|
|
155
139
|
* - Single-quoted strings
|
|
156
140
|
* - Omits undefined values
|
|
157
141
|
* - Supports RawCode for verbatim expressions
|
|
142
|
+
* - Supports inline expression directives for verbatim expressions
|
|
158
143
|
*/
|
|
159
144
|
declare class RawCode {
|
|
160
145
|
code: string;
|
|
@@ -176,4 +161,4 @@ declare function contextSchemaToTSType(context: Record<string, JSONSchema7> | nu
|
|
|
176
161
|
*/
|
|
177
162
|
declare function eventsSchemaToTSType(events: Record<string, JSONSchema7> | null | undefined): string | null;
|
|
178
163
|
//#endregion
|
|
179
|
-
export { 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
|
|
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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-
|
|
1
|
+
import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-DoCHBLTu.mjs";
|
|
2
2
|
import { createStatelyEmbed } from "./embed.mjs";
|
|
3
3
|
import { createStatelyInspector } from "./inspect.mjs";
|
|
4
4
|
import { StudioApiError, createStatelyClient } from "./studio.mjs";
|
|
5
5
|
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-
|
|
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
7
|
|
|
8
8
|
export { RawCode, StudioApiError, contextSchemaToTSType, createPostMessageTransport, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, fromStudioMachine, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { c as ExportFormatMap, d as ProtocolMessage, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-BPuwbNCz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/transport.d.ts
|
|
4
|
+
interface Transport {
|
|
5
|
+
send(msg: ProtocolMessage): void;
|
|
6
|
+
onMessage(handler: (msg: ProtocolMessage) => void): () => void;
|
|
7
|
+
destroy(): void;
|
|
8
|
+
readonly ready: boolean;
|
|
9
|
+
onReady(handler: () => void): () => void;
|
|
10
|
+
}
|
|
11
|
+
interface PostMessageTransportOptions {
|
|
12
|
+
iframe: HTMLIFrameElement;
|
|
13
|
+
targetOrigin: string;
|
|
14
|
+
/** Filter by source. Defaults to iframe.contentWindow. */
|
|
15
|
+
source?: Window;
|
|
16
|
+
}
|
|
17
|
+
declare function createPostMessageTransport(options: PostMessageTransportOptions): Transport;
|
|
18
|
+
interface WebSocketTransportOptions {
|
|
19
|
+
url: string;
|
|
20
|
+
role: 'client' | 'viz';
|
|
21
|
+
sessionId: string;
|
|
22
|
+
metadata?: {
|
|
23
|
+
name?: string;
|
|
24
|
+
machineId?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Reconnect on disconnect. Default true. */
|
|
27
|
+
reconnect?: boolean;
|
|
28
|
+
/** Max reconnect attempts. Default 10. */
|
|
29
|
+
maxReconnectAttempts?: number;
|
|
30
|
+
}
|
|
31
|
+
declare function createWebSocketTransport(options: WebSocketTransportOptions): Transport;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/inspect.d.ts
|
|
34
|
+
interface MinimalActorRef {
|
|
35
|
+
id: string;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
systemId?: string;
|
|
38
|
+
_parent?: MinimalActorRef;
|
|
39
|
+
logic?: {
|
|
40
|
+
config?: unknown;
|
|
41
|
+
};
|
|
42
|
+
getSnapshot(): MinimalSnapshot;
|
|
43
|
+
system: {
|
|
44
|
+
inspect: (observer: (event: InspectionEvent) => void) => {
|
|
45
|
+
unsubscribe: () => void;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface MinimalSnapshot {
|
|
50
|
+
value: unknown;
|
|
51
|
+
status: unknown;
|
|
52
|
+
context?: unknown;
|
|
53
|
+
children?: Record<string, MinimalActorRef>;
|
|
54
|
+
}
|
|
55
|
+
type InspectionEvent = {
|
|
56
|
+
type: '@xstate.actor';
|
|
57
|
+
actorRef: MinimalActorRef;
|
|
58
|
+
rootId: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: '@xstate.snapshot';
|
|
61
|
+
actorRef: MinimalActorRef;
|
|
62
|
+
rootId: string;
|
|
63
|
+
snapshot: MinimalSnapshot;
|
|
64
|
+
event: unknown;
|
|
65
|
+
} | {
|
|
66
|
+
type: '@xstate.event';
|
|
67
|
+
actorRef: MinimalActorRef;
|
|
68
|
+
rootId: string;
|
|
69
|
+
sourceRef?: MinimalActorRef;
|
|
70
|
+
event: unknown;
|
|
71
|
+
} | {
|
|
72
|
+
type: '@xstate.microstep';
|
|
73
|
+
actorRef: MinimalActorRef;
|
|
74
|
+
rootId: string;
|
|
75
|
+
snapshot: MinimalSnapshot;
|
|
76
|
+
event: unknown;
|
|
77
|
+
} | {
|
|
78
|
+
type: '@xstate.action';
|
|
79
|
+
actorRef: MinimalActorRef;
|
|
80
|
+
rootId: string;
|
|
81
|
+
action: {
|
|
82
|
+
type: string;
|
|
83
|
+
params: unknown;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
interface AdoptedActor {
|
|
87
|
+
/** `actor.sessionId` from xstate. Unique across the system. */
|
|
88
|
+
actorId: string;
|
|
89
|
+
/** Parent actor's sessionId, or `null` for the root. */
|
|
90
|
+
parentActorId: string | null;
|
|
91
|
+
/** Root actor's sessionId (equal to `actorId` for the root). */
|
|
92
|
+
rootId: string;
|
|
93
|
+
/** `actor.id` — a human-facing local name. */
|
|
94
|
+
id: string;
|
|
95
|
+
/** `actor.systemId`, if registered under one. */
|
|
96
|
+
systemId: string | undefined;
|
|
97
|
+
/** Latest serialized snapshot streamed for this actor. */
|
|
98
|
+
snapshot: unknown | null;
|
|
99
|
+
/** Machine config sent to the visualizer, or `null` for non-machine actors. */
|
|
100
|
+
machineConfig: unknown;
|
|
101
|
+
}
|
|
102
|
+
interface InspectorEvents {
|
|
103
|
+
register: AdoptedActor;
|
|
104
|
+
snapshot: AdoptedActor;
|
|
105
|
+
stopped: {
|
|
106
|
+
actorId: string;
|
|
107
|
+
};
|
|
108
|
+
error: EmbedEventMap['error'];
|
|
109
|
+
}
|
|
110
|
+
type EventName = keyof InspectorEvents;
|
|
111
|
+
type Handler<E extends EventName> = (data: InspectorEvents[E]) => void;
|
|
112
|
+
interface ManualActorOptions {
|
|
113
|
+
/** Initial snapshot. */
|
|
114
|
+
snapshot?: unknown;
|
|
115
|
+
/** Machine config for the visualizer. Without this, the actor shows as a generic node. */
|
|
116
|
+
machine?: unknown;
|
|
117
|
+
/** Parent actor id (for hierarchy). */
|
|
118
|
+
parent?: string;
|
|
119
|
+
/** System-level id (optional alias). */
|
|
120
|
+
systemId?: string;
|
|
121
|
+
}
|
|
122
|
+
interface CreateInspectorOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Root xstate actor to adopt. The inspector walks its `system`.
|
|
125
|
+
* Omit this for manual-only mode where you call `.actor()` / `.snapshot()`.
|
|
126
|
+
*/
|
|
127
|
+
actor?: any;
|
|
128
|
+
/** WebSocket URL of the devtools server. Default: `'ws://localhost:4242'`. */
|
|
129
|
+
url?: string;
|
|
130
|
+
/** Auto-open browser to visualizer. Default: `true`. */
|
|
131
|
+
autoOpen?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Relay session id. Defaults to the root actor's `sessionId` (auto mode)
|
|
134
|
+
* or a random id (manual mode). This is the `?session=<id>` value the viz
|
|
135
|
+
* iframe connects with.
|
|
136
|
+
*/
|
|
137
|
+
sessionId?: string;
|
|
138
|
+
/** Display name for this system in the visualizer. */
|
|
139
|
+
name?: string;
|
|
140
|
+
/**
|
|
141
|
+
* Serialize a snapshot for the wire. Defaults to `{value, status}` —
|
|
142
|
+
* dropping context entirely because xstate contexts routinely contain
|
|
143
|
+
* spawned actor refs which are not JSON-safe.
|
|
144
|
+
*/
|
|
145
|
+
serializeSnapshot?: (snapshot: MinimalSnapshot) => unknown;
|
|
146
|
+
/**
|
|
147
|
+
* Extract the machine config for a given actor. Defaults to reading
|
|
148
|
+
* `actor.logic.config`. Return `null` for non-machine actors.
|
|
149
|
+
*/
|
|
150
|
+
extractMachineConfig?: (actor: any) => unknown;
|
|
151
|
+
/** Selected actor id to focus on first. Defaults to the root actor. */
|
|
152
|
+
selectedActorId?: string;
|
|
153
|
+
/** Panel layout forwarded into the system init message. */
|
|
154
|
+
panels?: {
|
|
155
|
+
leftPanels?: string[];
|
|
156
|
+
rightPanels?: string[];
|
|
157
|
+
activePanels?: string[];
|
|
158
|
+
};
|
|
159
|
+
theme?: 'light' | 'dark';
|
|
160
|
+
readOnly?: boolean;
|
|
161
|
+
depth?: number;
|
|
162
|
+
/**
|
|
163
|
+
* Advanced: inject a pre-built transport (e.g. a channel from a
|
|
164
|
+
* multiplexed connection). When provided, `url`/`name` are ignored and the
|
|
165
|
+
* inspector shares that transport instead of opening its own WebSocket.
|
|
166
|
+
*/
|
|
167
|
+
transport?: Transport;
|
|
168
|
+
}
|
|
169
|
+
interface Inspector {
|
|
170
|
+
/** Snapshot of currently-adopted actors keyed by `actorId`. */
|
|
171
|
+
readonly actors: ReadonlyMap<string, AdoptedActor>;
|
|
172
|
+
/** The relay sessionId this inspector registered under. */
|
|
173
|
+
readonly sessionId: string;
|
|
174
|
+
/** Subscribe to lifecycle / error events. Returns an unsubscribe function. */
|
|
175
|
+
on<E extends EventName>(event: E, handler: Handler<E>): () => void;
|
|
176
|
+
off<E extends EventName>(event: E, handler: Handler<E>): void;
|
|
177
|
+
/** Export the currently-viewed machine in a given format. */
|
|
178
|
+
export<F extends ExportFormat>(format: F, options?: ExportCallOptions<F>): Promise<ExportFormatMap[F]['result']>;
|
|
179
|
+
/**
|
|
180
|
+
* Register a manual actor. In auto mode this adds an actor alongside the
|
|
181
|
+
* xstate-discovered ones; in manual mode it's the only way to add actors.
|
|
182
|
+
*/
|
|
183
|
+
actor(id: string, options?: ManualActorOptions): void;
|
|
184
|
+
/**
|
|
185
|
+
* Push a snapshot update for an actor. The actor is auto-registered if
|
|
186
|
+
* it hasn't been `.actor()`'d yet.
|
|
187
|
+
*/
|
|
188
|
+
snapshot(actorId: string, snapshot: unknown, event?: unknown): void;
|
|
189
|
+
/**
|
|
190
|
+
* Log an event targeting an actor. Sends a snapshot message with the
|
|
191
|
+
* actor's current snapshot + the new event so it appears in the event log.
|
|
192
|
+
*/
|
|
193
|
+
event(actorId: string, event: string | {
|
|
194
|
+
type: string;
|
|
195
|
+
[key: string]: unknown;
|
|
196
|
+
}, options?: {
|
|
197
|
+
source?: string;
|
|
198
|
+
}): void;
|
|
199
|
+
/** Mark an actor as stopped and remove it from the tree. */
|
|
200
|
+
stop(actorId: string): void;
|
|
201
|
+
/** Tear down the WebSocket + xstate subscription. */
|
|
202
|
+
destroy(): void;
|
|
203
|
+
}
|
|
204
|
+
declare function createStatelyInspector(options: CreateInspectorOptions): Inspector;
|
|
205
|
+
//#endregion
|
|
206
|
+
export { ManualActorOptions as a, createPostMessageTransport as c, InspectorEvents as i, createWebSocketTransport as l, CreateInspectorOptions as n, createStatelyInspector as o, Inspector as r, Transport as s, AdoptedActor as t };
|