@typeonce/effect-machine-devtools 0.23.0 → 0.24.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.
Files changed (50) hide show
  1. package/README.md +10 -4
  2. package/dist/DevServer.d.ts +2 -1
  3. package/dist/DevServer.d.ts.map +1 -1
  4. package/dist/DevServer.js.map +1 -1
  5. package/dist/DevToolsProtocol.d.ts +731 -17
  6. package/dist/DevToolsProtocol.d.ts.map +1 -1
  7. package/dist/DevToolsProtocol.js +191 -1
  8. package/dist/DevToolsProtocol.js.map +1 -1
  9. package/dist/MachineDocument.d.ts +78 -2
  10. package/dist/MachineDocument.d.ts.map +1 -1
  11. package/dist/MachineDocument.js +33 -1
  12. package/dist/MachineDocument.js.map +1 -1
  13. package/dist/MachineRegistry.d.ts +36 -6
  14. package/dist/MachineRegistry.d.ts.map +1 -1
  15. package/dist/ProjectInspector.d.ts +2 -0
  16. package/dist/ProjectInspector.d.ts.map +1 -1
  17. package/dist/ProjectInspector.js.map +1 -1
  18. package/dist/client/assets/index-B49Tjawc.js +14 -0
  19. package/dist/client/assets/index-BKH0cOG2.css +1 -0
  20. package/dist/client/index.html +2 -2
  21. package/dist/internal/devServer.d.ts +2 -1
  22. package/dist/internal/devServer.d.ts.map +1 -1
  23. package/dist/internal/devServer.js +68 -7
  24. package/dist/internal/devServer.js.map +1 -1
  25. package/dist/internal/evaluationWorker.d.ts.map +1 -1
  26. package/dist/internal/evaluationWorker.js +279 -4
  27. package/dist/internal/evaluationWorker.js.map +1 -1
  28. package/dist/internal/machineDocument.d.ts.map +1 -1
  29. package/dist/internal/machineDocument.js +63 -2
  30. package/dist/internal/machineDocument.js.map +1 -1
  31. package/dist/internal/projectInspector.d.ts.map +1 -1
  32. package/dist/internal/projectInspector.js +26 -10
  33. package/dist/internal/projectInspector.js.map +1 -1
  34. package/package.json +2 -2
  35. package/src/DevServer.ts +6 -2
  36. package/src/DevToolsProtocol.ts +286 -1
  37. package/src/MachineDocument.ts +54 -1
  38. package/src/ProjectInspector.ts +5 -0
  39. package/src/internal/browser/input-form.ts +669 -0
  40. package/src/internal/browser/planner-example.ts +143 -0
  41. package/src/internal/browser/simulation-client.ts +20 -0
  42. package/src/internal/browser/styles.css +323 -3
  43. package/src/internal/browser/visualizer-app.ts +395 -34
  44. package/src/internal/browser/visualizer.ts +1 -1
  45. package/src/internal/devServer.ts +91 -8
  46. package/src/internal/evaluationWorker.ts +390 -8
  47. package/src/internal/machineDocument.ts +75 -2
  48. package/src/internal/projectInspector.ts +58 -15
  49. package/dist/client/assets/index-BGOhE3Ng.css +0 -1
  50. package/dist/client/assets/index-DiqGhsGR.js +0 -14
@@ -12,7 +12,7 @@ import * as MachineDocument from "./MachineDocument.js"
12
12
  * @category models
13
13
  * @since 0.23.0
14
14
  */
15
- export const protocolVersion = 1 as const
15
+ export const protocolVersion = 2 as const
16
16
 
17
17
  /**
18
18
  * @category schemas
@@ -144,3 +144,288 @@ export const RegistrySnapshot = Schema.Struct({
144
144
  * @since 0.23.0
145
145
  */
146
146
  export type RegistrySnapshot = Schema.Schema.Type<typeof RegistrySnapshot>
147
+
148
+ /**
149
+ * JSON-safe representation of a persisted machine snapshot.
150
+ *
151
+ * @category schemas
152
+ * @since 0.24.0
153
+ */
154
+ export const EncodedSnapshot = Schema.Struct({
155
+ _tag: Schema.Literal("MachineSnapshot"),
156
+ active: Schema.Array(Schema.Struct({
157
+ path: Schema.String,
158
+ value: Schema.optionalKey(Schema.Json)
159
+ })),
160
+ completed: Schema.optionalKey(Schema.Array(Schema.Struct({
161
+ path: Schema.String,
162
+ output: Schema.optionalKey(Schema.Json)
163
+ }))),
164
+ history: Schema.optionalKey(Schema.Record(
165
+ Schema.String,
166
+ Schema.Struct({
167
+ mode: Schema.Literals(["shallow", "deep"]),
168
+ active: Schema.Array(Schema.String),
169
+ values: Schema.Record(Schema.String, Schema.Json)
170
+ })
171
+ ))
172
+ })
173
+
174
+ /**
175
+ * @category models
176
+ * @since 0.24.0
177
+ */
178
+ export type EncodedSnapshot = Schema.Schema.Type<typeof EncodedSnapshot>
179
+
180
+ const SimulationRequestFields = {
181
+ protocolVersion: Schema.Literal(protocolVersion),
182
+ key: Schema.String,
183
+ revision: Schema.Natural,
184
+ source: MachineDocument.Source
185
+ }
186
+
187
+ /**
188
+ * Starts an isolated planner session. Omitting `input` calls a machine that
189
+ * declares no input; otherwise the JSON value is decoded by its input schema.
190
+ *
191
+ * @category schemas
192
+ * @since 0.24.0
193
+ */
194
+ export const StartSimulation = Schema.Struct({
195
+ ...SimulationRequestFields,
196
+ _tag: Schema.tag("StartSimulation"),
197
+ input: Schema.optionalKey(Schema.Json)
198
+ })
199
+
200
+ /**
201
+ * @category models
202
+ * @since 0.24.0
203
+ */
204
+ export type StartSimulation = Schema.Schema.Type<typeof StartSimulation>
205
+
206
+ /**
207
+ * Plans one JSON event from an encoded session snapshot.
208
+ *
209
+ * @category schemas
210
+ * @since 0.24.0
211
+ */
212
+ export const SendSimulationEvent = Schema.Struct({
213
+ ...SimulationRequestFields,
214
+ _tag: Schema.tag("SendSimulationEvent"),
215
+ step: Schema.Natural,
216
+ snapshot: EncodedSnapshot,
217
+ event: Schema.Json
218
+ })
219
+
220
+ /**
221
+ * @category models
222
+ * @since 0.24.0
223
+ */
224
+ export type SendSimulationEvent = Schema.Schema.Type<typeof SendSimulationEvent>
225
+
226
+ /**
227
+ * Request accepted by the isolated machine planner.
228
+ *
229
+ * @category schemas
230
+ * @since 0.24.0
231
+ */
232
+ export const SimulationRequest = Schema.Union([StartSimulation, SendSimulationEvent])
233
+
234
+ /**
235
+ * @category models
236
+ * @since 0.24.0
237
+ */
238
+ export type SimulationRequest = Schema.Schema.Type<typeof SimulationRequest>
239
+
240
+ /**
241
+ * A compact view of one logical machine snapshot.
242
+ *
243
+ * @category schemas
244
+ * @since 0.24.0
245
+ */
246
+ export const SimulationSnapshot = Schema.Struct({
247
+ activePaths: Schema.Array(Schema.String),
248
+ candidateEvents: Schema.Array(Schema.String)
249
+ })
250
+
251
+ /**
252
+ * @category models
253
+ * @since 0.24.0
254
+ */
255
+ export type SimulationSnapshot = Schema.Schema.Type<typeof SimulationSnapshot>
256
+
257
+ /**
258
+ * Transition selected by the planner after hierarchy and conflict resolution.
259
+ *
260
+ * @category schemas
261
+ * @since 0.24.0
262
+ */
263
+ export const PlannedTransition = Schema.Struct({
264
+ source: Schema.String,
265
+ trigger: MachineDocument.Trigger,
266
+ reenter: Schema.Boolean,
267
+ branchIndex: Schema.Natural,
268
+ branchKey: Schema.NullOr(Schema.String),
269
+ target: Schema.NullOr(Schema.String),
270
+ resolvedTarget: Schema.NullOr(Schema.String),
271
+ updates: Schema.Array(Schema.String)
272
+ })
273
+
274
+ /**
275
+ * @category models
276
+ * @since 0.24.0
277
+ */
278
+ export type PlannedTransition = Schema.Schema.Type<typeof PlannedTransition>
279
+
280
+ /**
281
+ * Closed command produced by planning. Commands are displayed but never
282
+ * committed by the visualizer.
283
+ *
284
+ * @category schemas
285
+ * @since 0.24.0
286
+ */
287
+ export const PlannedCommand = Schema.Union([
288
+ Schema.Struct({
289
+ _tag: Schema.tag("SendTo"),
290
+ target: Schema.String,
291
+ event: Schema.Json
292
+ }),
293
+ Schema.Struct({
294
+ _tag: Schema.tag("Stop"),
295
+ target: Schema.String
296
+ })
297
+ ])
298
+
299
+ /**
300
+ * @category models
301
+ * @since 0.24.0
302
+ */
303
+ export type PlannedCommand = Schema.Schema.Type<typeof PlannedCommand>
304
+
305
+ /**
306
+ * One statechart microstep retained in a planned macrostep.
307
+ *
308
+ * @category schemas
309
+ * @since 0.24.0
310
+ */
311
+ export const SimulationMicrostep = Schema.Struct({
312
+ index: Schema.Natural,
313
+ event: Schema.Json,
314
+ transitions: Schema.Array(PlannedTransition),
315
+ raisedEvents: Schema.Array(Schema.Json),
316
+ emittedEvents: Schema.Array(Schema.Json),
317
+ commands: Schema.Array(PlannedCommand),
318
+ exitPaths: Schema.Array(Schema.String),
319
+ entryPaths: Schema.Array(Schema.String),
320
+ activePaths: Schema.Array(Schema.String),
321
+ changed: Schema.Boolean
322
+ })
323
+
324
+ /**
325
+ * @category models
326
+ * @since 0.24.0
327
+ */
328
+ export type SimulationMicrostep = Schema.Schema.Type<typeof SimulationMicrostep>
329
+
330
+ /**
331
+ * Structured trace for an initial plan or one received event.
332
+ *
333
+ * @category schemas
334
+ * @since 0.24.0
335
+ */
336
+ export const SimulationFrame = Schema.Struct({
337
+ step: Schema.Natural,
338
+ trigger: Schema.Union([
339
+ Schema.Struct({ _tag: Schema.tag("Initial"), input: Schema.optionalKey(Schema.Json) }),
340
+ Schema.Struct({ _tag: Schema.tag("Event"), event: Schema.Json })
341
+ ]),
342
+ before: SimulationSnapshot,
343
+ after: SimulationSnapshot,
344
+ microsteps: Schema.Array(SimulationMicrostep),
345
+ commands: Schema.Array(PlannedCommand),
346
+ emittedEvents: Schema.Array(Schema.Json),
347
+ done: Schema.Boolean,
348
+ output: Schema.optionalKey(Schema.Json)
349
+ })
350
+
351
+ /**
352
+ * @category models
353
+ * @since 0.24.0
354
+ */
355
+ export type SimulationFrame = Schema.Schema.Type<typeof SimulationFrame>
356
+
357
+ /**
358
+ * Successful planner response containing the next portable session state.
359
+ *
360
+ * @category schemas
361
+ * @since 0.24.0
362
+ */
363
+ export const SimulationReady = Schema.Struct({
364
+ protocolVersion: Schema.Literal(protocolVersion),
365
+ _tag: Schema.tag("SimulationReady"),
366
+ key: Schema.String,
367
+ revision: Schema.Natural,
368
+ step: Schema.Natural,
369
+ snapshot: EncodedSnapshot,
370
+ current: SimulationSnapshot,
371
+ frame: SimulationFrame
372
+ })
373
+
374
+ /**
375
+ * @category models
376
+ * @since 0.24.0
377
+ */
378
+ export type SimulationReady = Schema.Schema.Type<typeof SimulationReady>
379
+
380
+ /**
381
+ * One authoritative Effect Schema issue associated with a machine or event
382
+ * input path.
383
+ *
384
+ * @category schemas
385
+ * @since 0.24.0
386
+ */
387
+ export const InputIssue = Schema.Struct({
388
+ path: Schema.Array(Schema.Union([Schema.String, Schema.Number])),
389
+ message: Schema.String
390
+ })
391
+
392
+ /**
393
+ * @category models
394
+ * @since 0.24.0
395
+ */
396
+ export type InputIssue = Schema.Schema.Type<typeof InputIssue>
397
+
398
+ /**
399
+ * Recoverable failure produced while loading, decoding, or planning a session.
400
+ *
401
+ * @category schemas
402
+ * @since 0.24.0
403
+ */
404
+ export const SimulationFailed = Schema.Struct({
405
+ protocolVersion: Schema.Literal(protocolVersion),
406
+ _tag: Schema.tag("SimulationFailed"),
407
+ key: Schema.String,
408
+ revision: Schema.Natural,
409
+ diagnostics: Schema.Array(Diagnostic),
410
+ inputIssues: Schema.Array(InputIssue)
411
+ })
412
+
413
+ /**
414
+ * @category models
415
+ * @since 0.24.0
416
+ */
417
+ export type SimulationFailed = Schema.Schema.Type<typeof SimulationFailed>
418
+
419
+ /**
420
+ * Result returned by the isolated machine planner.
421
+ *
422
+ * @category schemas
423
+ * @since 0.24.0
424
+ */
425
+ export const SimulationResult = Schema.Union([SimulationReady, SimulationFailed])
426
+
427
+ /**
428
+ * @category models
429
+ * @since 0.24.0
430
+ */
431
+ export type SimulationResult = Schema.Schema.Type<typeof SimulationResult>
@@ -13,7 +13,7 @@ import * as internal from "./internal/machineDocument.js"
13
13
  * @category models
14
14
  * @since 0.23.0
15
15
  */
16
- export const schemaVersion = 1 as const
16
+ export const schemaVersion = 2 as const
17
17
 
18
18
  /**
19
19
  * Source module and export that produced a machine.
@@ -216,6 +216,58 @@ export const Snapshot = Schema.Struct({
216
216
  */
217
217
  export type Snapshot = Schema.Schema.Type<typeof Snapshot>
218
218
 
219
+ /**
220
+ * Canonical JSON Schema used to render one machine input form.
221
+ *
222
+ * @category schemas
223
+ * @since 0.24.0
224
+ */
225
+ export const InputSchema = Schema.Struct({
226
+ dialect: Schema.Literal("draft-2020-12"),
227
+ schema: Schema.Json,
228
+ definitions: Schema.Record(Schema.String, Schema.Json)
229
+ })
230
+
231
+ /**
232
+ * @category models
233
+ * @since 0.24.0
234
+ */
235
+ export type InputSchema = Schema.Schema.Type<typeof InputSchema>
236
+
237
+ /**
238
+ * Public event input paired with the schema for its payload.
239
+ *
240
+ * @category schemas
241
+ * @since 0.24.0
242
+ */
243
+ export const EventInput = Schema.Struct({
244
+ event: Schema.String,
245
+ schema: InputSchema
246
+ })
247
+
248
+ /**
249
+ * @category models
250
+ * @since 0.24.0
251
+ */
252
+ export type EventInput = Schema.Schema.Type<typeof EventInput>
253
+
254
+ /**
255
+ * Machine and public event inputs available to devtools forms.
256
+ *
257
+ * @category schemas
258
+ * @since 0.24.0
259
+ */
260
+ export const Inputs = Schema.Struct({
261
+ machine: Schema.NullOr(InputSchema),
262
+ events: Schema.Array(EventInput)
263
+ })
264
+
265
+ /**
266
+ * @category models
267
+ * @since 0.24.0
268
+ */
269
+ export type Inputs = Schema.Schema.Type<typeof Inputs>
270
+
219
271
  /**
220
272
  * Complete, versioned, JSON-safe machine inspection document.
221
273
  *
@@ -232,6 +284,7 @@ export const MachineDocument = Schema.Struct({
232
284
  states: Schema.Array(State),
233
285
  transitions: Schema.Array(Transition),
234
286
  activities: Schema.Array(Activity),
287
+ inputs: Inputs,
235
288
  snapshot: Schema.NullOr(Snapshot)
236
289
  })
237
290
 
@@ -92,6 +92,11 @@ export class ProjectInspector extends Context.Service<ProjectInspector, {
92
92
  readonly inspect: (
93
93
  options: InspectOptions
94
94
  ) => Effect.Effect<ReadonlyArray<DevToolsProtocol.MachineResult>, DiscoveryError | EvaluationError>
95
+ /** @internal */
96
+ readonly simulate: (
97
+ request: DevToolsProtocol.SimulationRequest,
98
+ options: Pick<InspectOptions, "root">
99
+ ) => Effect.Effect<DevToolsProtocol.SimulationResult, EvaluationError>
95
100
  }>()("@typeonce/effect-machine-devtools/ProjectInspector") {}
96
101
 
97
102
  /**