@statelyai/sdk 0.33.0 → 0.34.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 (40) hide show
  1. package/README.md +15 -4
  2. package/dist/assetStorage.d.mts +1 -1
  3. package/dist/auth.d.mts +1 -1
  4. package/dist/bin.mjs +1 -0
  5. package/dist/{dist-wbhkeGh6.mjs → dist-NJFkDQjK.mjs} +170 -77
  6. package/dist/{editorHostSession-DfmHzpls.mjs → editorHostSession-Bj5YcijC.mjs} +2 -2
  7. package/dist/{editorHostSession-C6yxOmSO.d.mts → editorHostSession-DwD_9cER.d.mts} +2 -2
  8. package/dist/editorHostSession.d.mts +1 -1
  9. package/dist/editorHostSession.mjs +3 -3
  10. package/dist/embed.d.mts +4 -4
  11. package/dist/embed.mjs +5 -4
  12. package/dist/{graph-CR_g-mOq.d.mts → graph-Ciocekxl.d.mts} +1 -1
  13. package/dist/graph.d.mts +1 -1
  14. package/dist/{index-DlOZxzrW.d.mts → index-DZivqh0u.d.mts} +21 -4
  15. package/dist/index.d.mts +8 -8
  16. package/dist/index.mjs +9 -9
  17. package/dist/{inspect-C-eEfU3T.mjs → inspect-0dMcaOz_.mjs} +43 -6
  18. package/dist/{inspect-CunxIl8H.d.mts → inspect-D-L0qj9L.d.mts} +17 -9
  19. package/dist/inspect.d.mts +3 -3
  20. package/dist/inspect.mjs +3 -2
  21. package/dist/node-relay.mjs +1 -1
  22. package/dist/patchTypes.d.mts +1 -1
  23. package/dist/{protocol-CQL9Ubt9.d.mts → protocol-AeHm956D.d.mts} +46 -76
  24. package/dist/protocol-BsBGRISR.mjs +116 -0
  25. package/dist/protocol.d.mts +2 -2
  26. package/dist/protocol.mjs +2 -86
  27. package/dist/relay.d.mts +1 -1
  28. package/dist/relay.mjs +23 -3
  29. package/dist/{studio-rSI54Ese.mjs → studio-BZP6DaIO.mjs} +50 -15
  30. package/dist/{studio-DV5IIGhV.d.mts → studio-CKdEPGKY.d.mts} +56 -17
  31. package/dist/studio.d.mts +1 -1
  32. package/dist/studio.mjs +1 -1
  33. package/dist/sync.d.mts +2 -2
  34. package/dist/sync.mjs +5 -10
  35. package/dist/{version-BblbkW8-.mjs → version-DxDSBJta.mjs} +17 -5
  36. package/package.json +3 -3
  37. /package/dist/{auth-Dg7prjeL.d.mts → auth-CVFc85uF.d.mts} +0 -0
  38. /package/dist/{editor-sync-types-CPpzTSnT.d.mts → editor-sync-types-D7YYz6fb.d.mts} +0 -0
  39. /package/dist/{editorHostProtocol-Bko7wge8.mjs → editorHostProtocol-B2_t3Le7.mjs} +0 -0
  40. /package/dist/{statelyPragma-D46lczJR.mjs → statelyPragma-YtVaBuIe.mjs} +0 -0
package/README.md CHANGED
@@ -223,6 +223,11 @@ Resource operations always require a credential.
223
223
  Stream live actor-system state to the hosted Stately inspector. Zero-config
224
224
  inspection needs no API key or local relay.
225
225
 
226
+ `selectedSessionId` takes the exact session id: `actor.sessionId` for runtime
227
+ actors (or your `resolveSessionId` result), and `${producerId}:${id}` for manual
228
+ actors. For example, with `producerId: 'demo'`, select `inspector.actor('root')`
229
+ using `selectedSessionId: 'demo:root'`. Do not add the viewer's room namespace.
230
+
226
231
  ```ts
227
232
  import { createActor } from "xstate";
228
233
  import { createInspector } from "@statelyai/sdk";
@@ -234,6 +239,13 @@ const actor = createActor(machine, { inspect });
234
239
  actor.start();
235
240
  ```
236
241
 
242
+ The inspector also accepts read-only `documents`, panel configuration, initial
243
+ `viewMode`, and typed display `settings`. Use `selectActor(sessionId)`,
244
+ `setTheme(theme)`, `setViewMode(mode)`, and `setSettings(settings)` to control the
245
+ viewer without restarting inspection. `on('loaded', ...)` reports a usable
246
+ viewer separately from relay `ready`; `on('capabilityDenied', ...)` reports
247
+ blocked viewer actions. See [inspector controls](../../docs/sdk/inspector.md#viewer-configuration-and-controls).
248
+
237
249
  If you already have the actor reference, `inspector.attach(actor)` subscribes to
238
250
  its system and backfills actors that are already running.
239
251
 
@@ -243,7 +255,8 @@ JSON-safe machine structure:
243
255
 
244
256
  ```ts
245
257
  const inspector = createInspector({
246
- extractMachine: (actor) => (actor.logic === machine ? machineSource : actor.logic?.config),
258
+ extractMachine: (actor) =>
259
+ actor.logic === machine ? machineSource : actor.logic?.config,
247
260
  });
248
261
  ```
249
262
 
@@ -276,9 +289,7 @@ const inspector = createInspector({
276
289
  roomId: persistedInspectionRoomId,
277
290
  producerId: persistedInspectionProducerId,
278
291
  resolveSessionId: (actor, defaultSessionId, parentSessionId) =>
279
- parentSessionId
280
- ? `${parentSessionId}/${actor.id}`
281
- : persistedInspectionId,
292
+ parentSessionId ? `${parentSessionId}/${actor.id}` : persistedInspectionId,
282
293
  });
283
294
  ```
284
295
 
@@ -1,4 +1,4 @@
1
- import { Ht as UploadResult } from "./protocol-CQL9Ubt9.mjs";
1
+ import { Gt as UploadResult } from "./protocol-AeHm956D.mjs";
2
2
 
3
3
  //#region src/assetStorage.d.ts
4
4
  interface AssetUploadContext {
package/dist/auth.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-Dg7prjeL.mjs";
1
+ import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-CVFc85uF.mjs";
2
2
  export { StatelyAuthMode, StatelyCredential, createAuthorizationHeader, getCredentialToken };
package/dist/bin.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import "./protocol-BsBGRISR.mjs";
2
3
  import { createNodeInspectionRelay } from "./node-relay.mjs";
3
4
 
4
5
  //#region src/bin.ts
@@ -3337,6 +3337,16 @@ function getEmittedNodeId(graph, node) {
3337
3337
  function getResolvedNodeId(graph, node) {
3338
3338
  return getEmittedNodeId(graph, node) ?? getDefaultPathId(graph, node);
3339
3339
  }
3340
+ function isCodeExpression(value) {
3341
+ return Boolean(value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code" && typeof value.expr === "string");
3342
+ }
3343
+ function containsCodeExpression(value, seen = /* @__PURE__ */ new WeakSet()) {
3344
+ if (!value || typeof value !== "object") return false;
3345
+ if (isCodeExpression(value)) return true;
3346
+ if (seen.has(value)) return false;
3347
+ seen.add(value);
3348
+ return Object.values(value).some((child) => containsCodeExpression(child, seen));
3349
+ }
3340
3350
  /**
3341
3351
  * Serializes JavaScript values as JS source code (not JSON).
3342
3352
  * - Unquoted keys for valid identifiers
@@ -3347,16 +3357,19 @@ function getResolvedNodeId(graph, node) {
3347
3357
  */
3348
3358
  const VALID_IDENT = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
3349
3359
  var RawCode = class {
3350
- constructor(code) {
3360
+ constructor(code, sourceValue, sourceSlice) {
3351
3361
  this.code = code;
3362
+ this.sourceValue = sourceValue;
3363
+ this.sourceSlice = sourceSlice;
3352
3364
  }
3353
3365
  };
3354
- function raw(code) {
3355
- return new RawCode(code);
3366
+ function raw(code, sourceValue, sourceSlice) {
3367
+ return new RawCode(code, sourceValue, sourceSlice);
3356
3368
  }
3369
+ const SERIALIZED_SOURCE_ID = "__stately_source_id__";
3357
3370
  function serializeJS(value, indent = 0, step = 2) {
3358
- if (value instanceof RawCode) return value.code;
3359
- if (isInlineExpressionDirective(value)) return value.expr;
3371
+ if (value instanceof RawCode) return markSourceValue(value.sourceValue, value.code, value.sourceSlice);
3372
+ if (isCodeExpression(value)) return markSourceValue(value, value.expr);
3360
3373
  if (value === void 0) return "undefined";
3361
3374
  if (value === null) return "null";
3362
3375
  if (typeof value === "string") return `'${escapeString(value)}'`;
@@ -3365,6 +3378,14 @@ function serializeJS(value, indent = 0, step = 2) {
3365
3378
  if (typeof value === "object") return serializeObject(value, indent, step);
3366
3379
  return String(value);
3367
3380
  }
3381
+ function markSourceValue(value, code, slice = {
3382
+ from: 0,
3383
+ to: code.length
3384
+ }) {
3385
+ if (!value) return code;
3386
+ const id = value[SERIALIZED_SOURCE_ID];
3387
+ return id === void 0 ? code : `${code.slice(0, slice.from)}/*__stately_source_${id}_start__*/${code.slice(slice.from, slice.to)}/*__stately_source_${id}_end__*/${code.slice(slice.to)}`;
3388
+ }
3368
3389
  function escapeString(s) {
3369
3390
  return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
3370
3391
  }
@@ -3385,17 +3406,17 @@ function serializeObject(obj, indent, step) {
3385
3406
  return `{\n${entries.map(([key, val]) => {
3386
3407
  const k = VALID_IDENT.test(key) ? key : `'${escapeString(key)}'`;
3387
3408
  const serialized = serializeJS(val, inner, step);
3388
- if (isRawExpression(val) && serialized.includes("\n")) return `${pad}${k}: ${indentRawCode(serialized, inner)}`;
3409
+ if (isRawExpression(val) && serialized.includes("\n")) return `${pad}${k}: ${preservesAuthoredWhitespace(val) ? serialized : indentRawCode(serialized, inner)}`;
3389
3410
  return `${pad}${k}: ${serialized}`;
3390
3411
  }).join(",\n")},\n${closePad}}`;
3391
3412
  }
3392
- function isRawExpression(value) {
3393
- return value instanceof RawCode || isInlineExpressionDirective(value);
3413
+ function preservesAuthoredWhitespace(value) {
3414
+ if (isCodeExpression(value)) return true;
3415
+ const sourceValue = value instanceof RawCode ? value.sourceValue : value;
3416
+ return Boolean(sourceValue && typeof sourceValue === "object" && SERIALIZED_SOURCE_ID in sourceValue);
3394
3417
  }
3395
- function isInlineExpressionDirective(value) {
3396
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
3397
- const directive = value;
3398
- return directive["@type"] === "code" && typeof directive.expr === "string";
3418
+ function isRawExpression(value) {
3419
+ return value instanceof RawCode || isCodeExpression(value);
3399
3420
  }
3400
3421
  function indentRawCode(code, indent) {
3401
3422
  const lines = code.split("\n");
@@ -3571,7 +3592,7 @@ function deepSimplify(config) {
3571
3592
  return config;
3572
3593
  }
3573
3594
  function buildMeta(meta, color) {
3574
- if (isCodeExpression$4(meta)) return meta;
3595
+ if (isCodeExpression(meta)) return meta;
3575
3596
  const result = {};
3576
3597
  if (meta) {
3577
3598
  for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null) result[k] = v;
@@ -3579,18 +3600,16 @@ function buildMeta(meta, color) {
3579
3600
  if (color) result["@statelyai.color"] = color;
3580
3601
  return Object.keys(result).length > 0 ? result : void 0;
3581
3602
  }
3582
- function isCodeExpression$4(value) {
3583
- return Boolean(value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code" && typeof value.expr === "string");
3584
- }
3585
3603
  /** Format event param — supports { type: string } (new) and plain string (legacy) */
3586
3604
  function formatEventParam(event) {
3605
+ if (isCodeExpression(event)) return serializeJS(event);
3587
3606
  if (event && typeof event === "object" && "type" in event) return formatInlineObject(event);
3588
3607
  if (typeof event === "string") return `{ type: '${event}' }`;
3589
3608
  return "undefined";
3590
3609
  }
3591
3610
  function formatStringParam(value) {
3592
3611
  if (typeof value === "string") return `'${value}'`;
3593
- return isCodeExpression$4(value) ? serializeJS(value) : "undefined";
3612
+ return isCodeExpression(value) ? serializeJS(value) : "undefined";
3594
3613
  }
3595
3614
  function formatInlineObject(value) {
3596
3615
  return `{ ${Object.entries(value).filter(([, item]) => item !== void 0).map(([key, item]) => `${formatObjectKey(key)}: ${serializeJS(item)}`).join(", ")} }`;
@@ -3598,8 +3617,21 @@ function formatInlineObject(value) {
3598
3617
  function formatObjectKey(key) {
3599
3618
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
3600
3619
  }
3601
- const eventParamSchema = union([string(), object({ type: string() }).catchall(unknown())]);
3602
- const delayParamSchema = union([number(), string()]);
3620
+ const codeExpressionParamSchema = object({
3621
+ "@type": literal("code"),
3622
+ expr: string()
3623
+ }).passthrough();
3624
+ const eventParamSchema = union([
3625
+ string(),
3626
+ object({ type: string() }).catchall(unknown()),
3627
+ codeExpressionParamSchema
3628
+ ]);
3629
+ const stringOrCodeParamSchema = union([string(), codeExpressionParamSchema]);
3630
+ const delayParamSchema = union([
3631
+ number(),
3632
+ string(),
3633
+ codeExpressionParamSchema
3634
+ ]);
3603
3635
  const builtInActionParamSchemas = {
3604
3636
  "xstate.enqueue": object({
3605
3637
  code: string().optional(),
@@ -3607,24 +3639,25 @@ const builtInActionParamSchemas = {
3607
3639
  }),
3608
3640
  "xstate.raise": object({
3609
3641
  event: eventParamSchema.optional(),
3610
- id: string().optional(),
3642
+ id: stringOrCodeParamSchema.optional(),
3611
3643
  delay: delayParamSchema.optional()
3612
3644
  }),
3613
3645
  "xstate.sendTo": object({
3614
- to: string().optional(),
3646
+ to: stringOrCodeParamSchema.optional(),
3615
3647
  event: eventParamSchema.optional(),
3616
- id: string().optional(),
3648
+ id: stringOrCodeParamSchema.optional(),
3617
3649
  delay: delayParamSchema.optional()
3618
3650
  }),
3619
- "xstate.cancel": object({ sendId: string().optional() }),
3651
+ "xstate.cancel": object({ sendId: stringOrCodeParamSchema.optional() }),
3620
3652
  "xstate.emit": object({ event: eventParamSchema.optional() }),
3621
3653
  "xstate.spawnChild": object({
3622
- src: string().optional(),
3623
- id: string().optional(),
3624
- systemId: string().optional()
3654
+ src: stringOrCodeParamSchema.optional(),
3655
+ id: stringOrCodeParamSchema.optional(),
3656
+ systemId: stringOrCodeParamSchema.optional(),
3657
+ input: unknown().optional()
3625
3658
  }),
3626
- "xstate.stopChild": object({ actorRef: string().optional() }),
3627
- "xstate.log": object({ label: string().optional() }),
3659
+ "xstate.stopChild": object({ actorRef: stringOrCodeParamSchema.optional() }),
3660
+ "xstate.log": object({ label: unknown().optional() }),
3628
3661
  "xstate.assign": object({ assignment: record(string(), unknown()).optional() }).catchall(unknown()),
3629
3662
  "xstate.choose": object({ branches: array(object({
3630
3663
  guard: unknown().optional(),
@@ -3651,8 +3684,8 @@ const XSTATE_BUILT_IN_ACTIONS = {
3651
3684
  emit(params) {
3652
3685
  const eventStr = formatEventParam(params?.event);
3653
3686
  const opts = [];
3654
- if (params?.id) opts.push(`id: '${params.id}'`);
3655
- if (params?.delay != null) opts.push(`delay: ${JSON.stringify(params.delay)}`);
3687
+ if (params?.id) opts.push(`id: ${formatStringParam(params.id)}`);
3688
+ if (params?.delay != null) opts.push(`delay: ${serializeJS(params.delay)}`);
3656
3689
  return `raise(${eventStr}${opts.length > 0 ? `, { ${opts.join(", ")} }` : ""})`;
3657
3690
  }
3658
3691
  },
@@ -3666,8 +3699,8 @@ const XSTATE_BUILT_IN_ACTIONS = {
3666
3699
  const to = formatStringParam(params?.to);
3667
3700
  const eventStr = formatEventParam(params?.event);
3668
3701
  const opts = [];
3669
- if (params?.id) opts.push(`id: '${params.id}'`);
3670
- if (params?.delay != null) opts.push(`delay: ${JSON.stringify(params.delay)}`);
3702
+ if (params?.id) opts.push(`id: ${formatStringParam(params.id)}`);
3703
+ if (params?.delay != null) opts.push(`delay: ${serializeJS(params.delay)}`);
3671
3704
  return `sendTo(${to}, ${eventStr}${opts.length > 0 ? `, { ${opts.join(", ")} }` : ""})`;
3672
3705
  }
3673
3706
  },
@@ -3700,8 +3733,9 @@ const XSTATE_BUILT_IN_ACTIONS = {
3700
3733
  emit(params) {
3701
3734
  const src = formatStringParam(params?.src);
3702
3735
  const opts = [];
3703
- if (params?.id) opts.push(`id: '${params.id}'`);
3704
- if (params?.systemId) opts.push(`systemId: '${params.systemId}'`);
3736
+ if (params?.id) opts.push(`id: ${formatStringParam(params.id)}`);
3737
+ if (params?.systemId) opts.push(`systemId: ${formatStringParam(params.systemId)}`);
3738
+ if (params?.input !== void 0) opts.push(`input: ${serializeJS(params.input)}`);
3705
3739
  return `spawnChild(${src}${opts.length > 0 ? `, { ${opts.join(", ")} }` : ""})`;
3706
3740
  }
3707
3741
  },
@@ -3722,7 +3756,7 @@ const XSTATE_BUILT_IN_ACTIONS = {
3722
3756
  importKind: "named",
3723
3757
  paramsSchema: builtInActionParamSchemas["xstate.log"],
3724
3758
  emit(params) {
3725
- return `log(${(params?.label ? `'${params.label}'` : void 0) ?? ""})`;
3759
+ return `log(${(params?.label !== void 0 ? serializeJS(params.label) : void 0) ?? ""})`;
3726
3760
  }
3727
3761
  },
3728
3762
  "xstate.choose": {
@@ -3742,7 +3776,7 @@ const XSTATE_BUILT_IN_ACTIONS = {
3742
3776
  importKind: "named",
3743
3777
  paramsSchema: builtInActionParamSchemas["xstate.assign"],
3744
3778
  emit(params) {
3745
- if (isCodeExpression$4(params?.assignment)) return `assign(${serializeJS(params.assignment)})`;
3779
+ if (isCodeExpression(params?.assignment)) return `assign(${serializeJS(params.assignment)})`;
3746
3780
  const assignments = params?.assignment && typeof params.assignment === "object" && !Array.isArray(params.assignment) ? params.assignment : params;
3747
3781
  const entries = Object.entries(assignments ?? {}).filter(([k, v]) => k && v !== void 0);
3748
3782
  if (entries.length === 0) return "assign({})";
@@ -3842,7 +3876,7 @@ function serializeActionItem(action, keepChooseStructured = false) {
3842
3876
  };
3843
3877
  }
3844
3878
  function formatAssignValue(value) {
3845
- if (typeof value !== "string") return JSON.stringify(value);
3879
+ if (typeof value !== "string") return serializeJS(value);
3846
3880
  const templateExpression = value.match(/^\{\{([\s\S]*)\}\}$/);
3847
3881
  if (templateExpression) return templateExpression[1].trim();
3848
3882
  return JSON.stringify(value);
@@ -5114,7 +5148,7 @@ function transitionContextIdentity(fn) {
5114
5148
  }
5115
5149
  function omitIdentityTransitionContext(transition, identity) {
5116
5150
  const context = transition.context;
5117
- if (!identity || !context || typeof context !== "object" || context["@type"] !== "code" || context.expr !== identity) return transition;
5151
+ if (!identity || !isCodeExpression(context) || context.expr !== identity) return transition;
5118
5152
  const { context: _context, ...rest } = transition;
5119
5153
  return rest;
5120
5154
  }
@@ -5128,8 +5162,7 @@ function normalizeFunctionTransition(fn, bindings, depth) {
5128
5162
  if (branch.contextUpdates && result && typeof result === "object" && !Array.isArray(result)) {
5129
5163
  const record = result;
5130
5164
  const context = record.context;
5131
- const contextRecord = context && typeof context === "object" && !Array.isArray(context) ? context : null;
5132
- if (contextRecord?.["@type"] === "code" && contextRecord.expr === "nextContext") result = {
5165
+ if (isCodeExpression(context) && context.expr === "nextContext") result = {
5133
5166
  ...record,
5134
5167
  context: branch.contextUpdates
5135
5168
  };
@@ -5264,6 +5297,68 @@ function inlineAction(fn) {
5264
5297
  }
5265
5298
  };
5266
5299
  }
5300
+ function builtInActionFromCall(call, bindings, context, depth) {
5301
+ if (!ts.isIdentifier(call.expression)) return null;
5302
+ const imported = context.imports?.get(call.expression.text);
5303
+ if (!imported || imported.package !== "xstate" && imported.package !== "xstate-v5") return null;
5304
+ const name = imported.import;
5305
+ const value = (index) => {
5306
+ const argument = call.arguments[index];
5307
+ return argument ? expressionToValue(argument, bindings, {
5308
+ ...context,
5309
+ effectArgumentValue: true
5310
+ }, depth + 1) : void 0;
5311
+ };
5312
+ const options = (index) => {
5313
+ const resolved = value(index);
5314
+ return resolved && typeof resolved === "object" && !Array.isArray(resolved) ? resolved : {};
5315
+ };
5316
+ switch (name) {
5317
+ case "assign": return {
5318
+ type: "xstate.assign",
5319
+ params: { assignment: value(0) }
5320
+ };
5321
+ case "raise": return {
5322
+ type: "xstate.raise",
5323
+ params: {
5324
+ event: value(0),
5325
+ ...options(1)
5326
+ }
5327
+ };
5328
+ case "sendTo": return {
5329
+ type: "xstate.sendTo",
5330
+ params: {
5331
+ to: value(0),
5332
+ event: value(1),
5333
+ ...options(2)
5334
+ }
5335
+ };
5336
+ case "emit": return {
5337
+ type: "xstate.emit",
5338
+ params: { event: value(0) }
5339
+ };
5340
+ case "cancel": return {
5341
+ type: "xstate.cancel",
5342
+ params: { sendId: value(0) }
5343
+ };
5344
+ case "spawnChild": return {
5345
+ type: "xstate.spawnChild",
5346
+ params: {
5347
+ src: value(0),
5348
+ ...options(1)
5349
+ }
5350
+ };
5351
+ case "stopChild": return {
5352
+ type: "xstate.stopChild",
5353
+ params: { actorRef: value(0) }
5354
+ };
5355
+ case "log": return {
5356
+ type: "xstate.log",
5357
+ params: { label: value(0) }
5358
+ };
5359
+ default: return null;
5360
+ }
5361
+ }
5267
5362
  function inlineCodeExpression(expr, imports) {
5268
5363
  return {
5269
5364
  "@type": "code",
@@ -5492,6 +5587,8 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
5492
5587
  if (context.actionValue) {
5493
5588
  const choose = chooseActionFromEnqueueActions(node, bindings);
5494
5589
  if (choose) return choose;
5590
+ const builtIn = builtInActionFromCall(node, bindings, context, depth);
5591
+ if (builtIn) return builtIn;
5495
5592
  return inlineAction(node);
5496
5593
  }
5497
5594
  const callee = node.expression.getText();
@@ -6242,12 +6339,12 @@ function toV6TransitionValue(value) {
6242
6339
  const transition = value;
6243
6340
  if (transition.matches !== void 0) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
6244
6341
  if (transition.guard) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
6245
- if (transition.description || transition.input !== void 0 && !containsInlineExpression(transition.input)) return mapV6MachineConfig(transition);
6342
+ if (transition.description || transition.input !== void 0 && !containsCodeExpression(transition.input)) return mapV6MachineConfig(transition);
6246
6343
  const target = transition.target;
6247
6344
  const context = transition.context;
6248
6345
  const actionsValue = transition.actions;
6249
6346
  const actions = Array.isArray(actionsValue) ? actionsValue : actionsValue === void 0 ? [] : [actionsValue];
6250
- if (actions.length === 0 && !containsInlineExpression(transition) && !containsTemplateExpression(transition)) return mapV6MachineConfig(transition);
6347
+ if (actions.length === 0 && !containsCodeExpression(transition) && !containsTemplateExpression(transition)) return mapV6MachineConfig(transition);
6251
6348
  if (actions.length === 0 && typeof target === "string" && context === void 0 && transition.input === void 0 && !transition.reenter && !transition.meta) return { target };
6252
6349
  if (actions.length === 0 && target === void 0 && context === void 0 && transition.input === void 0) return mapV6MachineConfig(transition);
6253
6350
  return buildV6ActionFunction(actions, {
@@ -6551,16 +6648,7 @@ function unwrapDirectEnqExpression(action) {
6551
6648
  return match?.[1] ? raw(match[1]) : action;
6552
6649
  }
6553
6650
  function inlineExpr(value) {
6554
- if (!value || typeof value !== "object" || Array.isArray(value)) return;
6555
- const directive = value;
6556
- return directive["@type"] === "code" && typeof directive.expr === "string" ? directive.expr : void 0;
6557
- }
6558
- function containsInlineExpression(value) {
6559
- if (!value || typeof value !== "object") return false;
6560
- if (Array.isArray(value)) return value.some(containsInlineExpression);
6561
- const record = value;
6562
- if (record["@type"] === "code" && typeof record.expr === "string") return true;
6563
- return Object.values(record).some(containsInlineExpression);
6651
+ return isCodeExpression(value) ? value.expr : void 0;
6564
6652
  }
6565
6653
  function actionToV6Effect(action) {
6566
6654
  const expr = inlineExpr(action);
@@ -6899,18 +6987,25 @@ function hasSchemaProperties(schema) {
6899
6987
  }
6900
6988
  return true;
6901
6989
  }
6990
+ function rawWithSourceSlice(prefix, source, suffix, sourceValue) {
6991
+ return raw(`${prefix}${source}${suffix}`, sourceValue, {
6992
+ from: prefix.length,
6993
+ to: prefix.length + source.length
6994
+ });
6995
+ }
6902
6996
  function buildActionsBlock(actions, options) {
6903
6997
  const block = {};
6904
6998
  for (const implementation of actions) if (implementation.code?.body) {
6905
6999
  if (options.xstateVersion === 6) assertV6NamedActionBody(implementation.name, implementation.code.body);
6906
7000
  const inlineExpression = getInlineExpression$1(implementation.code.body);
6907
7001
  if (inlineExpression) {
6908
- block[implementation.name] = raw(inlineExpression);
7002
+ block[implementation.name] = raw(inlineExpression, implementation.code);
6909
7003
  continue;
6910
7004
  }
6911
7005
  const params = hasSchemaProperties(implementation.paramsSchema) ? options.xstateVersion === 6 ? options.includeTypeSyntax ? `params: ${jsonSchemaToTSType(implementation.paramsSchema)}` : "params" : options.includeTypeSyntax ? `, params: ${jsonSchemaToTSType(implementation.paramsSchema)}` : ", params" : "";
6912
7006
  const firstParam = options.xstateVersion === 6 ? params : `{ context, event }${params}`;
6913
- block[implementation.name] = raw(`function (${firstParam}) {\n ${dedent(implementation.code.body)}\n}`);
7007
+ const body = dedent(implementation.code.body);
7008
+ block[implementation.name] = rawWithSourceSlice(`function (${firstParam}) {\n `, body, "\n}", implementation.code);
6914
7009
  } else block[implementation.name] = raw(options.xstateVersion === 6 ? `function () {\n // TODO: implement ${implementation.name}\n}` : `function ({ context, event }) {\n // TODO: implement ${implementation.name}\n}`);
6915
7010
  return block;
6916
7011
  }
@@ -6919,11 +7014,12 @@ function buildGuardsBlock(guards, options) {
6919
7014
  for (const guard of guards) if (guard.code?.body) {
6920
7015
  const inlineExpression = getInlineExpression$1(guard.code.body);
6921
7016
  if (inlineExpression) {
6922
- block[guard.name] = raw(inlineExpression);
7017
+ block[guard.name] = raw(inlineExpression, guard.code);
6923
7018
  continue;
6924
7019
  }
6925
7020
  const params = hasSchemaProperties(guard.paramsSchema) ? options.includeTypeSyntax ? `, params: ${jsonSchemaToTSType(guard.paramsSchema)}` : ", params" : "";
6926
- block[guard.name] = raw(`function ({ context, event }${params ? params : ""}) {\n ${dedent(guard.code.body)}\n}`);
7021
+ const body = dedent(guard.code.body);
7022
+ block[guard.name] = rawWithSourceSlice(`function ({ context, event }${params ? params : ""}) {\n `, body, "\n}", guard.code);
6927
7023
  } else block[guard.name] = raw(`function ({ context, event }) {\n // TODO: implement ${guard.name}\n return false;\n}`);
6928
7024
  return block;
6929
7025
  }
@@ -6933,16 +7029,18 @@ function buildActorsBlock(actors, options) {
6933
7029
  for (const actor of actors) if (actor.code?.body) {
6934
7030
  const inlineExpression = getActorLogicExpression(actor.code.body);
6935
7031
  if (inlineExpression) {
6936
- block[actor.name] = raw(inlineExpression);
7032
+ block[actor.name] = raw(inlineExpression, actor.code);
6937
7033
  continue;
6938
7034
  }
6939
7035
  const functionExpression = stripExportDefault(actor.code.body);
6940
7036
  if (isCompleteFunctionExpression(functionExpression)) {
6941
- block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: ${functionExpression} })` : `${actorFactory}(${functionExpression})`);
7037
+ block[actor.name] = rawWithSourceSlice(options.xstateVersion === 6 ? `${actorFactory}({ run: ` : `${actorFactory}(`, functionExpression, options.xstateVersion === 6 ? " })" : ")", actor.code);
6942
7038
  continue;
6943
7039
  }
6944
7040
  const inputType = options.includeTypeSyntax && hasSchemaProperties(actor.inputSchema) ? `: ${jsonSchemaToTSType(actor.inputSchema)}` : "";
6945
- block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: async ({ input }${inputType ? `: { input${inputType} }` : ""}) => {\n ${dedent(actor.code.body)}\n} })` : `${actorFactory}(async ({ input }${inputType ? `: { input${inputType} }` : ""}) => {\n ${dedent(actor.code.body)}\n})`);
7041
+ const body = dedent(actor.code.body);
7042
+ const prefix = `${actorFactory}(${options.xstateVersion === 6 ? "{ run: " : ""}async ({ input }${inputType ? `: { input${inputType} }` : ""}) => {\n `;
7043
+ block[actor.name] = rawWithSourceSlice(prefix, body, options.xstateVersion === 6 ? "\n} })" : "\n})", actor.code);
6946
7044
  } else block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: async ({ input }) => {\n // TODO: implement ${actor.name}\n} })` : `${actorFactory}(async ({ input }) => {\n // TODO: implement ${actor.name}\n})`);
6947
7045
  return block;
6948
7046
  }
@@ -6957,15 +7055,16 @@ function buildDelaysBlock(delays) {
6957
7055
  for (const delay of delays) if (delay.code?.body) {
6958
7056
  const inlineExpression = getInlineExpression$1(delay.code.body);
6959
7057
  if (inlineExpression) {
6960
- block[delay.name] = raw(inlineExpression);
7058
+ block[delay.name] = raw(inlineExpression, delay.code);
6961
7059
  continue;
6962
7060
  }
6963
7061
  const constantExpression = getConstantImplementationExpression(delay.code.body);
6964
7062
  if (constantExpression) {
6965
- block[delay.name] = raw(constantExpression);
7063
+ block[delay.name] = raw(constantExpression, delay.code);
6966
7064
  continue;
6967
7065
  }
6968
- block[delay.name] = raw(`function ({ context, event }) {\n ${dedent(delay.code.body)}\n}`);
7066
+ const body = dedent(delay.code.body);
7067
+ block[delay.name] = rawWithSourceSlice("function ({ context, event }) {\n ", body, "\n}", delay.code);
6969
7068
  } else block[delay.name] = raw(`function () {\n // TODO: implement ${delay.name}\n return 1000;\n}`);
6970
7069
  return block;
6971
7070
  }
@@ -7151,7 +7250,7 @@ function transformState(state, ctx, sourceKey) {
7151
7250
  }
7152
7251
  /** Rewrites embedded code expressions of a plain data value for v4. */
7153
7252
  function transformCodeValues(value) {
7154
- if (isCodeExpression$3(value)) return raw(toV4Code(value.expr));
7253
+ if (isCodeExpression(value)) return raw(toV4Code(value.expr));
7155
7254
  if (Array.isArray(value)) return value.map(transformCodeValues);
7156
7255
  if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, transformCodeValues(item)]));
7157
7256
  return value;
@@ -7181,7 +7280,7 @@ function targetsSelfOrDescendant(target, sourceKey) {
7181
7280
  /** Renders a v6 `matches` guard as readable text for the TODO marker. */
7182
7281
  function describeMatches(matches) {
7183
7282
  if (typeof matches === "string") return matches;
7184
- if (isCodeExpression$3(matches)) return matches.expr;
7283
+ if (isCodeExpression(matches)) return matches.expr;
7185
7284
  try {
7186
7285
  return serializeJS(matches, 0).replace(/\s+/g, " ");
7187
7286
  } catch {
@@ -7191,7 +7290,7 @@ function describeMatches(matches) {
7191
7290
  function transformTransitionValue(value, sourceKey) {
7192
7291
  if (Array.isArray(value)) return value.map((item) => transformTransitionValue(item, sourceKey));
7193
7292
  if (!value || typeof value !== "object") return value;
7194
- if (isCodeExpression$3(value)) return raw(toV4Code(value.expr));
7293
+ if (isCodeExpression(value)) return raw(toV4Code(value.expr));
7195
7294
  const transition = value;
7196
7295
  const result = {};
7197
7296
  let reenter;
@@ -7244,7 +7343,7 @@ function toV4ParameterizedObject(value) {
7244
7343
  };
7245
7344
  }
7246
7345
  function transformGuard(guard) {
7247
- if (isCodeExpression$3(guard)) return raw(toV4Code(guard.expr));
7346
+ if (isCodeExpression(guard)) return raw(toV4Code(guard.expr));
7248
7347
  if (guard && typeof guard === "object" && !Array.isArray(guard)) return toV4ParameterizedObject(guard);
7249
7348
  return guard;
7250
7349
  }
@@ -7254,7 +7353,7 @@ function transformActions(value) {
7254
7353
  return wasArray ? mapped : mapped[0];
7255
7354
  }
7256
7355
  function transformAction(action) {
7257
- if (isCodeExpression$3(action)) return raw(toV4Code(action.expr));
7356
+ if (isCodeExpression(action)) return raw(toV4Code(action.expr));
7258
7357
  if (action && typeof action === "object" && !Array.isArray(action)) return toV4ParameterizedObject(action);
7259
7358
  return action;
7260
7359
  }
@@ -7267,7 +7366,7 @@ function transformInvoke(value, ctx, sourceKey) {
7267
7366
  if (item === void 0) continue;
7268
7367
  switch (key) {
7269
7368
  case "src":
7270
- if (isCodeExpression$3(item)) {
7369
+ if (isCodeExpression(item)) {
7271
7370
  const name = typeof invoke.id === "string" && invoke.id ? invoke.id : `service${Object.keys(ctx.services).length + 1}`;
7272
7371
  ctx.services[name] = raw(toV4Code(item.expr));
7273
7372
  result.src = name;
@@ -7649,9 +7748,6 @@ function getCodeExpressionImports(graph) {
7649
7748
  visit(graph);
7650
7749
  return [...imports.values()];
7651
7750
  }
7652
- function isCodeExpression$3(value) {
7653
- return !!value && typeof value === "object" && value["@type"] === "code" && typeof value.expr === "string";
7654
- }
7655
7751
  function getXStateFSMCompatibilityIssues(graph) {
7656
7752
  const root = graph.nodes.find((node) => node.parentId == null);
7657
7753
  if (!root) return ["missing root state"];
@@ -7671,7 +7767,7 @@ function getXStateFSMCompatibilityIssues(graph) {
7671
7767
  if (!edge.data.eventType) issues.add("eventless transitions");
7672
7768
  if (!stateIds.has(edge.targetId) && edge.data.transitionType !== "targetless") issues.add("transitions outside the flat state set");
7673
7769
  if (edge.data.guard || edge.data.actions?.length || edge.data.matches || edge.data.input !== void 0 || edge.data.transitionType === "reenter") issues.add("guards, actions, matching, transition input, or reentry");
7674
- if (isCodeExpression$2(edge.data.context)) issues.add("dynamic transition context");
7770
+ if (isCodeExpression(edge.data.context)) issues.add("dynamic transition context");
7675
7771
  }
7676
7772
  if ([...eventCounts.values()].some((count) => count > 1)) issues.add("multiple transitions for one event");
7677
7773
  return [...issues];
@@ -7713,7 +7809,7 @@ function buildState(graph, state, stateById) {
7713
7809
  }
7714
7810
  function buildTransition$1(edge, stateById) {
7715
7811
  const target = edge.data.transitionType === "targetless" ? void 0 : stateById.get(edge.targetId)?.data.key;
7716
- const context = isCodeExpression$2(edge.data.context) ? void 0 : edge.data.context;
7812
+ const context = isCodeExpression(edge.data.context) ? void 0 : edge.data.context;
7717
7813
  if (context !== void 0) return {
7718
7814
  target,
7719
7815
  context
@@ -7751,9 +7847,6 @@ function eventPayloadType(schema) {
7751
7847
  required
7752
7848
  });
7753
7849
  }
7754
- function isCodeExpression$2(value) {
7755
- return !!value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code";
7756
- }
7757
7850
  const colorSchema = _enum([
7758
7851
  "green",
7759
7852
  "red",
@@ -8038,4 +8131,4 @@ const simulateMachineStepInputSchema = machineInputSchema.extend({
8038
8131
  });
8039
8132
 
8040
8133
  //#endregion
8041
- export { toXStateV6MachineConfig as S, graphToXStateV4TS as _, alignCompareGraphIds as a, raw as b, diffGraphsSemantically as c, getDelayKeyFromEventType as d, getXStateFSMCompatibilityIssues as f, graphToXStateTS as g, graphToXStateFSM as h, XSTATE_V6_FN_TRANSITION_META as i, eventsSchemaToTSType as l, graphToMachineConfig as m, RawCode as n, contextSchemaToTSType as o, graphChangeToPatchesResult as p, XSTATE_V6_BRANCH_DESCRIPTION_META as r, detectXStateSourceProfile as s, INLINE_EXPRESSION_DIRECTIVE_FIELDS as t, extractXStateMachineConfigEntries as u, jsonSchemaToTSType as v, serializeJS as x, normalizeMachineProfile as y };
8134
+ export { toXStateV6MachineConfig as C, serializeJS as S, graphToXStateV4TS as _, alignCompareGraphIds as a, normalizeMachineProfile as b, diffGraphsSemantically as c, getDelayKeyFromEventType as d, getXStateFSMCompatibilityIssues as f, graphToXStateTS as g, graphToXStateFSM as h, XSTATE_V6_FN_TRANSITION_META as i, eventsSchemaToTSType as l, graphToMachineConfig as m, RawCode as n, contextSchemaToTSType as o, graphChangeToPatchesResult as p, XSTATE_V6_BRANCH_DESCRIPTION_META as r, detectXStateSourceProfile as s, INLINE_EXPRESSION_DIRECTIVE_FIELDS as t, extractXStateMachineConfigEntries as u, isCodeExpression as v, raw as x, jsonSchemaToTSType as y };
@@ -1,6 +1,6 @@
1
1
  import { c as object, f as unknown, i as custom, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./openapi-BTDjYWXd.mjs";
2
- import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
- import { p as graphChangeToPatchesResult } from "./dist-wbhkeGh6.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-B2_t3Le7.mjs";
3
+ import { p as graphChangeToPatchesResult } from "./dist-NJFkDQjK.mjs";
4
4
  import * as ts$1 from "typescript";
5
5
 
6
6
  //#region ../api-contract/dist/editor-sync.mjs
@@ -1,5 +1,5 @@
1
- import { $t as EmbedPanelConfig, X as ProjectEmbedMachine, st as ProjectWorkspaceConfig } from "./protocol-CQL9Ubt9.mjs";
2
- import { a as EditorSyncParseRequest, d as EditorSyncTextReplacement, f as MachineSourceLocations, i as EditorSyncApplyResponse, n as EditorSyncAccess, o as EditorSyncParseResponse, r as EditorSyncApplyRequest, s as EditorSyncSourceDocument, t as EditorCapabilities } from "./editor-sync-types-CPpzTSnT.mjs";
1
+ import { Q as ProjectEmbedMachine, an as EmbedPanelConfig, lt as ProjectWorkspaceConfig } from "./protocol-AeHm956D.mjs";
2
+ import { a as EditorSyncParseRequest, d as EditorSyncTextReplacement, f as MachineSourceLocations, i as EditorSyncApplyResponse, n as EditorSyncAccess, o as EditorSyncParseResponse, r as EditorSyncApplyRequest, s as EditorSyncSourceDocument, t as EditorCapabilities } from "./editor-sync-types-D7YYz6fb.mjs";
3
3
 
4
4
  //#region src/editorHostProtocol.d.ts
5
5
  declare const EDITOR_PROTOCOL_VERSION = 1;
@@ -1,2 +1,2 @@
1
- import { _ as EditorHostOutboundMessage, a as EditorHostWorkspaceSessionOptions, c as EditorSyncError, d as fetchEditorSyncAccess, f as EDITOR_PROTOCOL_VERSION, g as EditorHostInitOptions, h as EditorHostInboundMessage, i as EditorHostWorkspaceSession, l as RemoteEditorSyncBackendOptions, m as EditorHostExportFormat, n as EditorHostSessionOptions, o as EditorSourceHost, p as EditorHostDiagnostic, r as EditorHostWorkspaceMachine, s as EditorSyncBackend, t as EditorHostSession, u as createRemoteEditorSyncBackend, v as EditorHostValidationIssue } from "./editorHostSession-C6yxOmSO.mjs";
1
+ import { _ as EditorHostOutboundMessage, a as EditorHostWorkspaceSessionOptions, c as EditorSyncError, d as fetchEditorSyncAccess, f as EDITOR_PROTOCOL_VERSION, g as EditorHostInitOptions, h as EditorHostInboundMessage, i as EditorHostWorkspaceSession, l as RemoteEditorSyncBackendOptions, m as EditorHostExportFormat, n as EditorHostSessionOptions, o as EditorSourceHost, p as EditorHostDiagnostic, r as EditorHostWorkspaceMachine, s as EditorSyncBackend, t as EditorHostSession, u as createRemoteEditorSyncBackend, v as EditorHostValidationIssue } from "./editorHostSession-DwD_9cER.mjs";
2
2
  export { EDITOR_PROTOCOL_VERSION, EditorHostDiagnostic, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorHostWorkspaceMachine, EditorHostWorkspaceSession, EditorHostWorkspaceSessionOptions, EditorSourceHost, EditorSyncBackend, EditorSyncError, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
@@ -1,6 +1,6 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
- import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
- import { a as fetchEditorSyncAccess, i as createRemoteEditorSyncBackend, n as EditorHostWorkspaceSession, r as EditorSyncError, t as EditorHostSession } from "./editorHostSession-DfmHzpls.mjs";
4
- import "./dist-wbhkeGh6.mjs";
2
+ import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-B2_t3Le7.mjs";
3
+ import { a as fetchEditorSyncAccess, i as createRemoteEditorSyncBackend, n as EditorHostWorkspaceSession, r as EditorSyncError, t as EditorHostSession } from "./editorHostSession-Bj5YcijC.mjs";
4
+ import "./dist-NJFkDQjK.mjs";
5
5
 
6
6
  export { EDITOR_PROTOCOL_VERSION, EditorHostSession, EditorHostWorkspaceSession, EditorSyncError, createRemoteEditorSyncBackend, fetchEditorSyncAccess };