@statelyai/sdk 0.12.3 → 0.13.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 +10 -2
- package/dist/auth.d.mts +1 -1
- package/dist/embed.mjs +1 -1
- package/dist/{graph-Dq5ycdSq.d.mts → graph-R0sbxnZ7.d.mts} +1 -1
- package/dist/graph.d.mts +1 -1
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +6 -4
- package/dist/{inspect-BmZUcnZB.d.mts → inspect-BMHheAvx.d.mts} +85 -4
- package/dist/inspect-D9GyHTTW.mjs +469 -0
- package/dist/inspect.d.mts +3 -3
- package/dist/inspect.mjs +2 -305
- package/dist/patchTypes.d.mts +1 -1
- package/dist/protocol.d.mts +35 -6
- package/dist/protocol.mjs +3 -1
- package/dist/relay.d.mts +43 -0
- package/dist/relay.mjs +153 -0
- package/dist/studio.d.mts +1 -1
- package/dist/sync.d.mts +1 -1
- package/dist/sync.mjs +1 -1
- package/dist/{transport-DysvAtl5.mjs → transport-D2Ud05yg.mjs} +178 -2
- package/package.json +6 -1
- /package/dist/{auth-DO1-eQcU.d.mts → auth-DmPZiERd.d.mts} +0 -0
- /package/dist/{dist-C-AdA8Iw.mjs → dist-CHGcvOdQ.mjs} +0 -0
- /package/dist/{index-BRW2DecD.d.mts → index-DVjNSTuQ.d.mts} +0 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { a as createPendingExportManager, i as createEventRegistry, r as createWebSocketTransport } from "./transport-D2Ud05yg.mjs";
|
|
2
|
+
import { INSPECTION_PROTOCOL_VERSION } from "./protocol.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/openBrowser.ts
|
|
5
|
+
async function openBrowser(url) {
|
|
6
|
+
if (typeof process === "undefined" || !process.versions?.node || typeof process.getBuiltinModule !== "function") return;
|
|
7
|
+
const { spawn } = process.getBuiltinModule("node:child_process");
|
|
8
|
+
const child = spawn(process.platform === "darwin" ? "open" : process.platform === "win32" ? "powershell.exe" : "xdg-open", process.platform === "win32" ? [
|
|
9
|
+
"-NoProfile",
|
|
10
|
+
"-NonInteractive",
|
|
11
|
+
"-Command",
|
|
12
|
+
"Start-Process -FilePath $args[0]",
|
|
13
|
+
"--",
|
|
14
|
+
url
|
|
15
|
+
] : [url], {
|
|
16
|
+
detached: true,
|
|
17
|
+
stdio: "ignore",
|
|
18
|
+
windowsHide: true
|
|
19
|
+
});
|
|
20
|
+
await new Promise((resolve, reject) => {
|
|
21
|
+
child.once("spawn", () => {
|
|
22
|
+
child.unref();
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
child.once("error", (error) => reject(error));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/inspect.ts
|
|
31
|
+
const defaultSerializeSnapshot = (snapshot) => ({
|
|
32
|
+
value: snapshot?.value,
|
|
33
|
+
status: snapshot?.status
|
|
34
|
+
});
|
|
35
|
+
const defaultExtractMachineConfig = (actor, source) => actor?.logic?.config ?? source?.config ?? null;
|
|
36
|
+
let nextManualId = 0;
|
|
37
|
+
function generateSessionId() {
|
|
38
|
+
return `manual-${Date.now()}-${nextManualId++}`;
|
|
39
|
+
}
|
|
40
|
+
function createInspectorLaunchUrl(websocketUrl, sessionId) {
|
|
41
|
+
try {
|
|
42
|
+
const launchUrl = new URL(websocketUrl);
|
|
43
|
+
if (launchUrl.protocol === "ws:") launchUrl.protocol = "http:";
|
|
44
|
+
else if (launchUrl.protocol === "wss:") launchUrl.protocol = "https:";
|
|
45
|
+
else return null;
|
|
46
|
+
launchUrl.searchParams.set("session", sessionId);
|
|
47
|
+
return launchUrl.toString();
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function createInspector(options = {}) {
|
|
53
|
+
const { url = "ws://localhost:4242", autoOpen = true, name, serializeSnapshot = defaultSerializeSnapshot, extractMachineConfig = defaultExtractMachineConfig, selectedActorId, panels, theme, readOnly, depth, capabilities, transport: injectedTransport } = options;
|
|
54
|
+
const sessionId = options.sessionId ?? generateSessionId();
|
|
55
|
+
const displayName = name ?? "system:manual";
|
|
56
|
+
let destroyed = false;
|
|
57
|
+
let initSent = false;
|
|
58
|
+
let initialized = false;
|
|
59
|
+
let pendingTransportReady = false;
|
|
60
|
+
let didAutoOpen = false;
|
|
61
|
+
const pendingMessages = [];
|
|
62
|
+
const events = createEventRegistry();
|
|
63
|
+
const localListeners = {};
|
|
64
|
+
const transport = injectedTransport ?? createWebSocketTransport({
|
|
65
|
+
url,
|
|
66
|
+
role: "client",
|
|
67
|
+
sessionId,
|
|
68
|
+
metadata: { name: displayName }
|
|
69
|
+
});
|
|
70
|
+
const ownsTransport = !injectedTransport;
|
|
71
|
+
const exportManager = createPendingExportManager((message) => send(message));
|
|
72
|
+
function send(msg) {
|
|
73
|
+
if (!transport.ready) {
|
|
74
|
+
pendingMessages.push(msg);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
transport.send(msg);
|
|
78
|
+
}
|
|
79
|
+
function handleTransportReady() {
|
|
80
|
+
pendingMessages.length = 0;
|
|
81
|
+
initSent = false;
|
|
82
|
+
sendInit();
|
|
83
|
+
if (autoOpen && !didAutoOpen && ownsTransport) {
|
|
84
|
+
didAutoOpen = true;
|
|
85
|
+
const launchUrl = createInspectorLaunchUrl(url, sessionId);
|
|
86
|
+
if (launchUrl) openBrowser(launchUrl).catch((error) => {
|
|
87
|
+
const failure = {
|
|
88
|
+
code: "open_failed",
|
|
89
|
+
message: error instanceof Error ? error.message : "Unable to open the inspector browser"
|
|
90
|
+
};
|
|
91
|
+
emitLocal("error", failure);
|
|
92
|
+
events.emit("error", failure);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
transport.onReady(() => {
|
|
97
|
+
if (!initialized) {
|
|
98
|
+
pendingTransportReady = true;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
handleTransportReady();
|
|
102
|
+
});
|
|
103
|
+
transport.onMessage((msg) => {
|
|
104
|
+
if (destroyed) return;
|
|
105
|
+
switch (msg.type) {
|
|
106
|
+
case "@statelyai.retrieved":
|
|
107
|
+
exportManager.resolve(msg.requestId, msg.data);
|
|
108
|
+
break;
|
|
109
|
+
case "@statelyai.error":
|
|
110
|
+
exportManager.reject(new Error(msg.message), msg.requestId);
|
|
111
|
+
emitLocal("error", {
|
|
112
|
+
code: msg.code,
|
|
113
|
+
message: msg.message
|
|
114
|
+
});
|
|
115
|
+
events.emit("error", {
|
|
116
|
+
code: msg.code,
|
|
117
|
+
message: msg.message
|
|
118
|
+
});
|
|
119
|
+
break;
|
|
120
|
+
default: break;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
function emitLocal(event, data) {
|
|
124
|
+
const set = localListeners[event];
|
|
125
|
+
if (!set) return;
|
|
126
|
+
for (const handler of set) handler(data);
|
|
127
|
+
}
|
|
128
|
+
const actors = /* @__PURE__ */ new Map();
|
|
129
|
+
/** Tracks which actors we've already emitted local actor events for. */
|
|
130
|
+
const locallyRegistered = /* @__PURE__ */ new Set();
|
|
131
|
+
/** v5 emits transition facets separately; accumulate them until snapshot. */
|
|
132
|
+
const pendingTransitions = /* @__PURE__ */ new Map();
|
|
133
|
+
function emitRegisterOnce(entry) {
|
|
134
|
+
if (locallyRegistered.has(entry.actorId)) return;
|
|
135
|
+
locallyRegistered.add(entry.actorId);
|
|
136
|
+
emitLocal("actor", entry);
|
|
137
|
+
emitLocal("register", entry);
|
|
138
|
+
}
|
|
139
|
+
function snapshotValue(actorRef) {
|
|
140
|
+
try {
|
|
141
|
+
return serializeSnapshot(actorRef.getSnapshot());
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function toEntry(actorRef, rootActorId, details) {
|
|
147
|
+
return {
|
|
148
|
+
actorId: actorRef.sessionId,
|
|
149
|
+
parentActorId: details?.parentRef?.sessionId ?? actorRef._parent?.sessionId ?? null,
|
|
150
|
+
rootId: rootActorId,
|
|
151
|
+
id: details?.id ?? actorRef.id ?? actorRef.sessionId,
|
|
152
|
+
systemId: actorRef.systemId,
|
|
153
|
+
snapshot: details?.snapshot ? serializeSnapshot(details.snapshot) : snapshotValue(actorRef),
|
|
154
|
+
machineConfig: extractMachineConfig(actorRef, details?.source ?? actorRef.src)
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function toSystemEntry(entry) {
|
|
158
|
+
return {
|
|
159
|
+
actorId: entry.actorId,
|
|
160
|
+
parentActorId: entry.parentActorId,
|
|
161
|
+
id: entry.id,
|
|
162
|
+
machine: entry.machineConfig,
|
|
163
|
+
snapshot: entry.snapshot ?? void 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Walk the actor tree and populate the local `actors` map. Idempotent —
|
|
168
|
+
* existing entries stay in place but have their snapshot refreshed.
|
|
169
|
+
*/
|
|
170
|
+
function backfillActorTree(actorRef, rootActorId) {
|
|
171
|
+
const existing = actors.get(actorRef.sessionId);
|
|
172
|
+
const entry = existing ?? toEntry(actorRef, rootActorId);
|
|
173
|
+
if (existing) existing.snapshot = snapshotValue(actorRef);
|
|
174
|
+
else actors.set(entry.actorId, entry);
|
|
175
|
+
emitRegisterOnce(entry);
|
|
176
|
+
const children = actorRef.getSnapshot()?.children ?? {};
|
|
177
|
+
for (const child of Object.values(children)) if (child) backfillActorTree(child, rootActorId);
|
|
178
|
+
}
|
|
179
|
+
const inspectedRoots = /* @__PURE__ */ new Map();
|
|
180
|
+
function sendInit() {
|
|
181
|
+
for (const [rootActorId, { actor }] of inspectedRoots) backfillActorTree(actor, rootActorId);
|
|
182
|
+
send({
|
|
183
|
+
type: "@statelyai.system.init",
|
|
184
|
+
protocolVersion: INSPECTION_PROTOCOL_VERSION,
|
|
185
|
+
mode: "inspecting",
|
|
186
|
+
actors: Array.from(actors.values()).map(toSystemEntry),
|
|
187
|
+
selectedActorId: selectedActorId ?? inspectedRoots.keys().next().value ?? sessionId,
|
|
188
|
+
...theme && { theme },
|
|
189
|
+
...readOnly !== void 0 && { readOnly },
|
|
190
|
+
...depth !== void 0 && { depth },
|
|
191
|
+
...capabilities !== void 0 && { capabilities },
|
|
192
|
+
...panels?.leftPanels && { leftPanels: panels.leftPanels },
|
|
193
|
+
...panels?.rightPanels && { rightPanels: panels.rightPanels },
|
|
194
|
+
...panels?.activePanels && { activePanels: panels.activePanels }
|
|
195
|
+
});
|
|
196
|
+
initSent = true;
|
|
197
|
+
}
|
|
198
|
+
function handleActor(actorRef, rootActorId, details) {
|
|
199
|
+
if (actors.has(actorRef.sessionId)) return;
|
|
200
|
+
const entry = toEntry(actorRef, rootActorId, details);
|
|
201
|
+
actors.set(entry.actorId, entry);
|
|
202
|
+
emitRegisterOnce(entry);
|
|
203
|
+
if (initSent) send({
|
|
204
|
+
type: "@statelyai.system.actorRegistered",
|
|
205
|
+
actorId: entry.actorId,
|
|
206
|
+
parentActorId: entry.parentActorId,
|
|
207
|
+
id: entry.id,
|
|
208
|
+
machine: entry.machineConfig,
|
|
209
|
+
snapshot: entry.snapshot ?? void 0
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function normalizeAction(action) {
|
|
213
|
+
return {
|
|
214
|
+
type: action.type,
|
|
215
|
+
...action.params !== void 0 && { params: action.params }
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function normalizeTakenTransition(transition) {
|
|
219
|
+
const raw = transition;
|
|
220
|
+
const json = raw?.toJSON?.();
|
|
221
|
+
const source = raw?.source ?? json?.source;
|
|
222
|
+
const targets = raw?.target ?? json?.target ?? [];
|
|
223
|
+
return {
|
|
224
|
+
sourceStateId: typeof source === "string" ? source : source?.id ?? null,
|
|
225
|
+
targetStateIds: targets.map((target) => typeof target === "string" ? target : target.id ?? "").filter(Boolean),
|
|
226
|
+
...(raw?.eventType ?? json?.eventType) && { eventType: raw?.eventType ?? json?.eventType },
|
|
227
|
+
...(raw?.reenter ?? json?.reenter) !== void 0 && { reenter: raw?.reenter ?? json?.reenter }
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function normalizeSentEvent(sentEvent) {
|
|
231
|
+
return {
|
|
232
|
+
...sentEvent.targetRef?.sessionId && { targetActorId: sentEvent.targetRef.sessionId },
|
|
233
|
+
targetId: sentEvent.targetId,
|
|
234
|
+
event: sentEvent.event,
|
|
235
|
+
...sentEvent.delay !== void 0 && { delay: sentEvent.delay },
|
|
236
|
+
...sentEvent.id !== void 0 && { id: sentEvent.id }
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function createPendingTransition(actorRef, event = null, sourceRef) {
|
|
240
|
+
return {
|
|
241
|
+
previousSnapshot: actors.get(actorRef.sessionId)?.snapshot ?? null,
|
|
242
|
+
event,
|
|
243
|
+
sourceActorId: sourceRef?.sessionId ?? null,
|
|
244
|
+
actions: [],
|
|
245
|
+
transitions: [],
|
|
246
|
+
sent: []
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function getPendingTransition(actorRef, event) {
|
|
250
|
+
const existing = pendingTransitions.get(actorRef.sessionId);
|
|
251
|
+
if (existing) return existing;
|
|
252
|
+
const pending = createPendingTransition(actorRef, event);
|
|
253
|
+
pendingTransitions.set(actorRef.sessionId, pending);
|
|
254
|
+
return pending;
|
|
255
|
+
}
|
|
256
|
+
function handleTransition(actorRef, snapshot, triggeringEvent, rootActorId, transition) {
|
|
257
|
+
if (!actors.has(actorRef.sessionId)) handleActor(actorRef, rootActorId);
|
|
258
|
+
const entry = actors.get(actorRef.sessionId);
|
|
259
|
+
if (!entry) return;
|
|
260
|
+
const serialized = serializeSnapshot(snapshot);
|
|
261
|
+
const inspectedTransition = {
|
|
262
|
+
actorId: entry.actorId,
|
|
263
|
+
sourceActorId: transition.sourceActorId,
|
|
264
|
+
previousSnapshot: transition.previousSnapshot,
|
|
265
|
+
snapshot: serialized,
|
|
266
|
+
event: triggeringEvent ?? transition.event ?? null,
|
|
267
|
+
actions: transition.actions,
|
|
268
|
+
transitions: transition.transitions,
|
|
269
|
+
sent: transition.sent
|
|
270
|
+
};
|
|
271
|
+
entry.snapshot = serialized;
|
|
272
|
+
pendingTransitions.delete(entry.actorId);
|
|
273
|
+
if (initSent) send({
|
|
274
|
+
type: "@statelyai.system.actorSnapshot",
|
|
275
|
+
actorId: entry.actorId,
|
|
276
|
+
previousSnapshot: inspectedTransition.previousSnapshot,
|
|
277
|
+
snapshot: inspectedTransition.snapshot,
|
|
278
|
+
event: inspectedTransition.event,
|
|
279
|
+
sourceActorId: inspectedTransition.sourceActorId,
|
|
280
|
+
actions: inspectedTransition.actions,
|
|
281
|
+
transitions: inspectedTransition.transitions,
|
|
282
|
+
sent: inspectedTransition.sent
|
|
283
|
+
});
|
|
284
|
+
emitLocal("transition", inspectedTransition);
|
|
285
|
+
emitLocal("snapshot", entry);
|
|
286
|
+
const status = snapshot?.status;
|
|
287
|
+
if (status === "done" || status === "stopped" || status === "error") {
|
|
288
|
+
actors.delete(entry.actorId);
|
|
289
|
+
pendingTransitions.delete(entry.actorId);
|
|
290
|
+
if (initSent) send({
|
|
291
|
+
type: "@statelyai.system.actorStopped",
|
|
292
|
+
actorId: entry.actorId
|
|
293
|
+
});
|
|
294
|
+
const stopped = { actorId: entry.actorId };
|
|
295
|
+
emitLocal("stop", stopped);
|
|
296
|
+
emitLocal("stopped", stopped);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function inspectActor(actor) {
|
|
300
|
+
const root = actor;
|
|
301
|
+
const rootActorId = root.sessionId;
|
|
302
|
+
const existing = inspectedRoots.get(rootActorId);
|
|
303
|
+
if (existing) return existing.subscription;
|
|
304
|
+
const subscription = root.system.inspect((inspectionEvent) => {
|
|
305
|
+
if (destroyed) return;
|
|
306
|
+
switch (inspectionEvent.type) {
|
|
307
|
+
case "@xstate.actor":
|
|
308
|
+
handleActor(inspectionEvent.actorRef, rootActorId, {
|
|
309
|
+
parentRef: inspectionEvent.parentRef,
|
|
310
|
+
id: inspectionEvent.id,
|
|
311
|
+
source: inspectionEvent.src,
|
|
312
|
+
snapshot: inspectionEvent.snapshot
|
|
313
|
+
});
|
|
314
|
+
break;
|
|
315
|
+
case "@xstate.event":
|
|
316
|
+
pendingTransitions.set(inspectionEvent.actorRef.sessionId, createPendingTransition(inspectionEvent.actorRef, inspectionEvent.event, inspectionEvent.sourceRef));
|
|
317
|
+
break;
|
|
318
|
+
case "@xstate.action":
|
|
319
|
+
getPendingTransition(inspectionEvent.actorRef).actions.push(normalizeAction(inspectionEvent.action));
|
|
320
|
+
break;
|
|
321
|
+
case "@xstate.microstep":
|
|
322
|
+
getPendingTransition(inspectionEvent.actorRef, inspectionEvent.event).transitions.push(...(inspectionEvent._transitions ?? []).map(normalizeTakenTransition));
|
|
323
|
+
break;
|
|
324
|
+
case "@xstate.snapshot": {
|
|
325
|
+
const pending = getPendingTransition(inspectionEvent.actorRef, inspectionEvent.event);
|
|
326
|
+
handleTransition(inspectionEvent.actorRef, inspectionEvent.snapshot, inspectionEvent.event, rootActorId, pending);
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
case "@xstate.transition":
|
|
330
|
+
if (!inspectionEvent.actions || !inspectionEvent.microsteps || !inspectionEvent.sent) break;
|
|
331
|
+
handleTransition(inspectionEvent.actorRef, inspectionEvent.snapshot, inspectionEvent.event, rootActorId, {
|
|
332
|
+
previousSnapshot: actors.get(inspectionEvent.actorRef.sessionId)?.snapshot ?? null,
|
|
333
|
+
event: inspectionEvent.event,
|
|
334
|
+
sourceActorId: inspectionEvent.sourceRef?.sessionId ?? null,
|
|
335
|
+
actions: inspectionEvent.actions.map(normalizeAction),
|
|
336
|
+
transitions: inspectionEvent.microsteps.map(normalizeTakenTransition),
|
|
337
|
+
sent: inspectionEvent.sent.map(normalizeSentEvent)
|
|
338
|
+
});
|
|
339
|
+
break;
|
|
340
|
+
default: break;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
inspectedRoots.set(rootActorId, {
|
|
344
|
+
actor: root,
|
|
345
|
+
subscription
|
|
346
|
+
});
|
|
347
|
+
backfillActorTree(root, rootActorId);
|
|
348
|
+
if (initSent) sendInit();
|
|
349
|
+
return { unsubscribe() {
|
|
350
|
+
subscription.unsubscribe();
|
|
351
|
+
inspectedRoots.delete(rootActorId);
|
|
352
|
+
} };
|
|
353
|
+
}
|
|
354
|
+
function manualRegister(id, opts) {
|
|
355
|
+
if (actors.has(id)) return;
|
|
356
|
+
const entry = {
|
|
357
|
+
actorId: id,
|
|
358
|
+
parentActorId: opts?.parent ?? null,
|
|
359
|
+
rootId: sessionId,
|
|
360
|
+
id,
|
|
361
|
+
systemId: opts?.systemId,
|
|
362
|
+
snapshot: opts?.snapshot ?? null,
|
|
363
|
+
machineConfig: opts?.machine ?? null
|
|
364
|
+
};
|
|
365
|
+
actors.set(id, entry);
|
|
366
|
+
if (initSent) send({
|
|
367
|
+
type: "@statelyai.system.actorRegistered",
|
|
368
|
+
actorId: id,
|
|
369
|
+
parentActorId: entry.parentActorId,
|
|
370
|
+
id,
|
|
371
|
+
machine: entry.machineConfig,
|
|
372
|
+
snapshot: entry.snapshot ?? void 0
|
|
373
|
+
});
|
|
374
|
+
emitRegisterOnce(entry);
|
|
375
|
+
}
|
|
376
|
+
function manualSnapshot(actorId, snapshot, event, sourceActorId) {
|
|
377
|
+
if (!actors.has(actorId)) manualRegister(actorId);
|
|
378
|
+
const entry = actors.get(actorId);
|
|
379
|
+
const previousSnapshot = entry.snapshot;
|
|
380
|
+
const transition = {
|
|
381
|
+
actorId,
|
|
382
|
+
sourceActorId: sourceActorId ?? null,
|
|
383
|
+
previousSnapshot,
|
|
384
|
+
snapshot,
|
|
385
|
+
event: event ?? null,
|
|
386
|
+
actions: [],
|
|
387
|
+
transitions: [],
|
|
388
|
+
sent: []
|
|
389
|
+
};
|
|
390
|
+
entry.snapshot = snapshot;
|
|
391
|
+
if (initSent) send({
|
|
392
|
+
type: "@statelyai.system.actorSnapshot",
|
|
393
|
+
actorId,
|
|
394
|
+
previousSnapshot,
|
|
395
|
+
snapshot,
|
|
396
|
+
event: event ?? null,
|
|
397
|
+
sourceActorId: sourceActorId ?? null,
|
|
398
|
+
actions: [],
|
|
399
|
+
transitions: [],
|
|
400
|
+
sent: []
|
|
401
|
+
});
|
|
402
|
+
emitLocal("transition", transition);
|
|
403
|
+
emitLocal("snapshot", entry);
|
|
404
|
+
}
|
|
405
|
+
function manualEvent(actorId, event, eventOpts) {
|
|
406
|
+
const eventObj = typeof event === "string" ? { type: event } : { ...event };
|
|
407
|
+
manualSnapshot(actorId, actors.get(actorId)?.snapshot ?? null, eventObj, eventOpts?.source ?? null);
|
|
408
|
+
}
|
|
409
|
+
function manualStop(actorId) {
|
|
410
|
+
if (!actors.has(actorId)) return;
|
|
411
|
+
actors.delete(actorId);
|
|
412
|
+
if (initSent) send({
|
|
413
|
+
type: "@statelyai.system.actorStopped",
|
|
414
|
+
actorId
|
|
415
|
+
});
|
|
416
|
+
const stopped = { actorId };
|
|
417
|
+
emitLocal("stop", stopped);
|
|
418
|
+
emitLocal("stopped", stopped);
|
|
419
|
+
}
|
|
420
|
+
initialized = true;
|
|
421
|
+
if (pendingTransportReady) {
|
|
422
|
+
pendingTransportReady = false;
|
|
423
|
+
handleTransportReady();
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
actors,
|
|
427
|
+
get sessionId() {
|
|
428
|
+
return sessionId;
|
|
429
|
+
},
|
|
430
|
+
inspect: inspectActor,
|
|
431
|
+
on(event, handler) {
|
|
432
|
+
if (!localListeners[event]) localListeners[event] = /* @__PURE__ */ new Set();
|
|
433
|
+
localListeners[event].add(handler);
|
|
434
|
+
return () => {
|
|
435
|
+
localListeners[event].delete(handler);
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
off(event, handler) {
|
|
439
|
+
localListeners[event]?.delete(handler);
|
|
440
|
+
},
|
|
441
|
+
export(format, callOptions) {
|
|
442
|
+
return exportManager.start(format, callOptions, "Inspector is destroyed", () => destroyed);
|
|
443
|
+
},
|
|
444
|
+
actor: manualRegister,
|
|
445
|
+
snapshot: manualSnapshot,
|
|
446
|
+
event: manualEvent,
|
|
447
|
+
stop: manualStop,
|
|
448
|
+
destroy() {
|
|
449
|
+
if (destroyed) return;
|
|
450
|
+
destroyed = true;
|
|
451
|
+
try {
|
|
452
|
+
for (const { subscription } of inspectedRoots.values()) subscription.unsubscribe();
|
|
453
|
+
} catch {}
|
|
454
|
+
if (ownsTransport) transport.destroy();
|
|
455
|
+
exportManager.clear("Inspector destroyed");
|
|
456
|
+
events.clear();
|
|
457
|
+
actors.clear();
|
|
458
|
+
inspectedRoots.clear();
|
|
459
|
+
pendingTransitions.clear();
|
|
460
|
+
pendingMessages.length = 0;
|
|
461
|
+
for (const set of Object.values(localListeners)) set?.clear();
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/** @deprecated Use {@link createInspector}. */
|
|
466
|
+
const createStatelyInspector = createInspector;
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
export { createStatelyInspector as n, createInspector as t };
|
package/dist/inspect.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap } from "./protocol.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
export { AdoptedActor, CreateInspectorOptions, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, Inspector, InspectorEvents, ManualActorOptions, Transport, createStatelyInspector };
|
|
1
|
+
import { EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InspectionAction, InspectionSentEvent, InspectionTakenTransition } from "./protocol.mjs";
|
|
2
|
+
import { a as InspectorEvents, c as createStatelyInspector, f as Transport, i as Inspector, n as CreateInspectorOptions, o as ManualActorOptions, r as InspectedTransition, s as createInspector, t as AdoptedActor } from "./inspect-BMHheAvx.mjs";
|
|
3
|
+
export { AdoptedActor, CreateInspectorOptions, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InspectedTransition, InspectionAction, InspectionSentEvent, InspectionTakenTransition, Inspector, InspectorEvents, ManualActorOptions, Transport, createInspector, createStatelyInspector };
|