@valerypopoff/rivet2-core 2.31.0 → 2.33.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.
@@ -31,16 +31,22 @@ export function resolveNodePrefabInstance(project, node) {
31
31
  title: `Missing library node (${prefabId})`,
32
32
  };
33
33
  }
34
+ const visualData = {
35
+ ...structuredClone(sourceNode.visualData),
36
+ x: node.visualData.x,
37
+ y: node.visualData.y,
38
+ width: node.visualData.width ?? sourceNode.visualData.width,
39
+ zIndex: node.visualData.zIndex,
40
+ };
41
+ // Channel positions belong to each instance's wiring, not the library source.
42
+ if (Array.isArray(node.visualData.dataBusChannelOrder))
43
+ visualData.dataBusChannelOrder = [...node.visualData.dataBusChannelOrder];
44
+ else
45
+ delete visualData.dataBusChannelOrder;
34
46
  return {
35
47
  ...structuredClone(sourceNode),
36
48
  id: node.id,
37
- visualData: {
38
- ...structuredClone(sourceNode.visualData),
39
- x: node.visualData.x,
40
- y: node.visualData.y,
41
- width: node.visualData.width ?? sourceNode.visualData.width,
42
- zIndex: node.visualData.zIndex,
43
- },
49
+ visualData,
44
50
  };
45
51
  }
46
52
  /**
@@ -1,2 +1,3 @@
1
1
  /** Lightweight entry point for file preparation without model/provider runtime initialization. */
2
2
  export { deserializeProject, deserializeGraph, deserializeDatasets, serializeProject, serializeGraph, serializeDatasets, } from './utils/serialization/serialization.js';
3
+ export { bindSharedReplayProjectId, serializeSharedReplayProject } from './utils/serialization/serialization_v4.js';
@@ -1,4 +1,5 @@
1
1
  import { mapValues } from 'lodash-es';
2
+ import stableStringify from 'safe-stable-stringify';
2
3
  import { normalizeSerializedLLMTemperatureData } from '../../model/chat-v2/llmChatV2NodeMigration.js';
3
4
  import { doubleCheckProject, isValidProjectStaticData } from './serializationUtils.js';
4
5
  import { entries } from '../typeSafety.js';
@@ -17,6 +18,27 @@ export function graphV4Deserializer(data) {
17
18
  return fromSerializedGraph(serializedGraph);
18
19
  }
19
20
  export function projectV4Serializer(project, attachedData) {
21
+ return wrapInYamlEnvelope(4, prepareSerializedProject(project, attachedData));
22
+ }
23
+ const replayProjectHeader = '{"version":4,"data":{"metadata":{"id":';
24
+ /** A v4 project with its ID at a known location, for rebinding a verified replay without re-encoding the graph. */
25
+ export function serializeSharedReplayProject(project, attachedData) {
26
+ const { metadata: { id, ...metadata }, ...data } = prepareSerializedProject(project, attachedData);
27
+ const metadataJson = stableStringify(metadata);
28
+ const dataJson = stableStringify(data);
29
+ // Numeric metadata keys are allowed and JSON.stringify would move them
30
+ // ahead of id. Write the fixed envelope once and keep the rest canonical.
31
+ const metadataTail = metadataJson === '{}' ? '}' : ',' + metadataJson.slice(1);
32
+ return replayProjectHeader + JSON.stringify(id) + metadataTail + ',' + dataJson.slice(1) + '}';
33
+ }
34
+ export function bindSharedReplayProjectId(snapshot, sourceId, recordingId) {
35
+ const sourceHeader = replayProjectHeader + JSON.stringify(sourceId);
36
+ const afterId = snapshot[sourceHeader.length];
37
+ if (!snapshot.startsWith(sourceHeader) || (afterId !== ',' && afterId !== '}'))
38
+ throw new Error('Shared replay project has an invalid source identity.');
39
+ return replayProjectHeader + JSON.stringify(recordingId) + snapshot.slice(sourceHeader.length);
40
+ }
41
+ function prepareSerializedProject(project, attachedData) {
20
42
  if (!isValidProjectStaticData(project.data)) {
21
43
  throw new Error('Project data must be a record of static-data strings');
22
44
  }
@@ -33,7 +55,7 @@ export function projectV4Serializer(project, attachedData) {
33
55
  path: undefined,
34
56
  },
35
57
  };
36
- return wrapInYamlEnvelope(4, toSerializedProject(filteredProject, attachedData));
58
+ return toSerializedProject(filteredProject, attachedData);
37
59
  }
38
60
  export function graphV4Serializer(graph) {
39
61
  return wrapInYamlEnvelope(4, toSerializedGraph(graph));
@@ -148,6 +170,7 @@ function toSerializedNode(node, allNodes, allConnections) {
148
170
  return {
149
171
  description: node.description?.trim() ? node.description : undefined,
150
172
  visualData: packVisualDataV4(node),
173
+ dataBusChannelOrder: node.visualData.dataBusChannelOrder,
151
174
  isSplitRun: node.isSplitRun ? true : undefined,
152
175
  splitRunMax: node.isSplitRun ? node.splitRunMax : undefined,
153
176
  splitRunConcurrency: node.isSplitRun ? node.splitRunConcurrency : undefined,
@@ -185,6 +208,9 @@ function fromSerializedNode(serializedNode, serializedNodeInfo) {
185
208
  width,
186
209
  zIndex,
187
210
  color,
211
+ ...(Array.isArray(serializedNode.dataBusChannelOrder)
212
+ ? { dataBusChannelOrder: serializedNode.dataBusChannelOrder }
213
+ : {}),
188
214
  },
189
215
  data: serializedNode.data ?? {},
190
216
  variants: serializedNode.variants ?? [],
@@ -27,6 +27,8 @@ export interface NodeBase {
27
27
  /** The y-coordinate of the node's position. */
28
28
  y: number;
29
29
  width?: number;
30
+ /** Presentation order of Data Bus channels; port identities and execution are unchanged. */
31
+ dataBusChannelOrder?: number[];
30
32
  /** The accent color of the node in the UI. */
31
33
  color?: {
32
34
  border: string;
@@ -1,2 +1,3 @@
1
1
  /** Lightweight entry point for file preparation without model/provider runtime initialization. */
2
2
  export { deserializeProject, deserializeGraph, deserializeDatasets, serializeProject, serializeGraph, serializeDatasets, type CombinedDataset, } from './utils/serialization/serialization.js';
3
+ export { bindSharedReplayProjectId, serializeSharedReplayProject } from './utils/serialization/serialization_v4.js';
@@ -4,6 +4,9 @@ import type { CombinedDataset } from './serialization.js';
4
4
  export declare function projectV4Deserializer(data: unknown): [Project, AttachedData];
5
5
  export declare function graphV4Deserializer(data: unknown): NodeGraph;
6
6
  export declare function projectV4Serializer(project: Project, attachedData?: AttachedData): unknown;
7
+ /** A v4 project with its ID at a known location, for rebinding a verified replay without re-encoding the graph. */
8
+ export declare function serializeSharedReplayProject(project: Project, attachedData: AttachedData): string;
9
+ export declare function bindSharedReplayProjectId(snapshot: string, sourceId: string, recordingId: string): string;
7
10
  export declare function graphV4Serializer(graph: NodeGraph): unknown;
8
11
  export declare function datasetV4Serializer(datasets: CombinedDataset[]): string;
9
12
  export declare function datasetV4Deserializer(serializedDatasets: string): CombinedDataset[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.31.0",
3
+ "version": "2.33.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",