@bian-womp/spark-remote 0.2.67 → 0.2.69

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/lib/cjs/index.cjs CHANGED
@@ -445,6 +445,14 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
445
445
  });
446
446
  originalApi.setExtData(payload.extData || {});
447
447
  },
448
+ cancelNodeRuns: (nodeIds) => {
449
+ graphRuntime?.cancelNodeRuns(nodeIds);
450
+ },
451
+ commit: async () => { },
452
+ undo: async () => false,
453
+ redo: async () => false,
454
+ canUndo: async () => false,
455
+ canRedo: async () => false,
448
456
  describeRegistry: () => {
449
457
  // types (include enum options when available)
450
458
  const types = Array.from(registry.types.entries()).map(([id, d]) => {
@@ -655,10 +663,38 @@ async function createRuntimeAdapter(createRegistry, send, extensions) {
655
663
  launch: wrapMethod("launch", originalApi.launch),
656
664
  whenIdle: wrapMethod("whenIdle", originalApi.whenIdle),
657
665
  dispose: wrapMethod("dispose", originalApi.dispose),
666
+ commit: wrapMethod("commit", originalApi.commit),
667
+ cancelNodeRuns: wrapMethod("cancelNodeRuns", originalApi.cancelNodeRuns),
668
+ undo: wrapMethod("undo", originalApi.undo),
669
+ redo: wrapMethod("redo", originalApi.redo),
670
+ canUndo: wrapMethod("canUndo", originalApi.canUndo),
671
+ canRedo: wrapMethod("canRedo", originalApi.canRedo),
658
672
  };
659
673
  return extendedApi;
660
674
  }
661
675
 
676
+ const UNSET_MARKER = { __sparkUnset: true };
677
+ function isUnsetMarker(value) {
678
+ return (typeof value === "object" &&
679
+ value !== null &&
680
+ "__sparkUnset" in value &&
681
+ value.__sparkUnset === true);
682
+ }
683
+ function encodeInputsForTransport(inputs) {
684
+ const encoded = {};
685
+ for (const [key, value] of Object.entries(inputs)) {
686
+ encoded[key] = value === undefined ? UNSET_MARKER : value;
687
+ }
688
+ return encoded;
689
+ }
690
+ function decodeInputsFromTransport(inputs) {
691
+ const decoded = {};
692
+ for (const [key, value] of Object.entries(inputs)) {
693
+ decoded[key] = isUnsetMarker(value) ? undefined : value;
694
+ }
695
+ return decoded;
696
+ }
697
+
662
698
  class RemoteEngine {
663
699
  constructor(transport) {
664
700
  this.transport = transport;
@@ -696,12 +732,12 @@ class RemoteEngine {
696
732
  },
697
733
  });
698
734
  }
699
- // Batch inputs for a single network round-trip
700
735
  setInputs(nodeId, inputs, options) {
736
+ const encodedInputs = encodeInputsForTransport(inputs);
701
737
  this.transport.send({
702
738
  message: {
703
739
  type: "SetInputs",
704
- payload: { nodeId, inputs },
740
+ payload: { nodeId, inputs: encodedInputs },
705
741
  dry: options?.dry,
706
742
  },
707
743
  });
@@ -1029,6 +1065,16 @@ class RuntimeApiClient {
1029
1065
  message: { type: "RegistryApply", payload: { deltas } },
1030
1066
  });
1031
1067
  }
1068
+ async setInputs(nodeId, inputs, options) {
1069
+ const transport = await this.ensureConnected();
1070
+ await transport.request({
1071
+ message: {
1072
+ type: "SetInputs",
1073
+ payload: { nodeId, inputs },
1074
+ dry: options?.dry,
1075
+ },
1076
+ });
1077
+ }
1032
1078
  async snapshot() {
1033
1079
  const transport = await this.ensureConnected();
1034
1080
  const res = await transport.request({
@@ -1135,6 +1181,44 @@ class RuntimeApiClient {
1135
1181
  message: { type: "SetExtData", payload: data },
1136
1182
  });
1137
1183
  }
1184
+ async commit() {
1185
+ const transport = await this.ensureConnected();
1186
+ await transport.request({
1187
+ message: { type: "Commit" },
1188
+ });
1189
+ }
1190
+ async undo() {
1191
+ const transport = await this.ensureConnected();
1192
+ const res = await transport.request({
1193
+ message: { type: "Undo" },
1194
+ });
1195
+ const payload = res?.message || {};
1196
+ return payload.success ?? false;
1197
+ }
1198
+ async redo() {
1199
+ const transport = await this.ensureConnected();
1200
+ const res = await transport.request({
1201
+ message: { type: "Redo" },
1202
+ });
1203
+ const payload = res?.message || {};
1204
+ return payload.success ?? false;
1205
+ }
1206
+ async canUndo() {
1207
+ const transport = await this.ensureConnected();
1208
+ const res = await transport.request({
1209
+ message: { type: "CanUndo" },
1210
+ });
1211
+ const payload = res?.message || {};
1212
+ return payload.canUndo ?? false;
1213
+ }
1214
+ async canRedo() {
1215
+ const transport = await this.ensureConnected();
1216
+ const res = await transport.request({
1217
+ message: { type: "CanRedo" },
1218
+ });
1219
+ const payload = res?.message || {};
1220
+ return payload.canRedo ?? false;
1221
+ }
1138
1222
  /**
1139
1223
  * Dispose the client and close the transport connection.
1140
1224
  * Idempotent: safe to call multiple times.
@@ -1257,7 +1341,7 @@ class RuntimeApiServer {
1257
1341
  dry: !!dry,
1258
1342
  });
1259
1343
  const nodeId = msg.payload.nodeId;
1260
- const inputs = msg.payload.inputs;
1344
+ const inputs = decodeInputsFromTransport(msg.payload.inputs);
1261
1345
  this.runtimeApi.setInputs(nodeId, inputs, { dry });
1262
1346
  ack();
1263
1347
  break;
@@ -1390,6 +1474,36 @@ class RuntimeApiServer {
1390
1474
  ack();
1391
1475
  break;
1392
1476
  }
1477
+ case "Commit": {
1478
+ this.logCommand("Commit", env);
1479
+ await this.runtimeApi.commit();
1480
+ ack();
1481
+ break;
1482
+ }
1483
+ case "Undo": {
1484
+ this.logCommand("Undo", env);
1485
+ const success = await this.runtimeApi.undo();
1486
+ ack({ success });
1487
+ break;
1488
+ }
1489
+ case "Redo": {
1490
+ this.logCommand("Redo", env);
1491
+ const success = await this.runtimeApi.redo();
1492
+ ack({ success });
1493
+ break;
1494
+ }
1495
+ case "CanUndo": {
1496
+ this.logCommand("CanUndo", env);
1497
+ const canUndo = await this.runtimeApi.canUndo();
1498
+ ack({ canUndo });
1499
+ break;
1500
+ }
1501
+ case "CanRedo": {
1502
+ this.logCommand("CanRedo", env);
1503
+ const canRedo = await this.runtimeApi.canRedo();
1504
+ ack({ canRedo });
1505
+ break;
1506
+ }
1393
1507
  default: {
1394
1508
  this.logCommand("Unknown type", env);
1395
1509
  ack();