@valerypopoff/rivet2-core 2.32.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.
@@ -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));
@@ -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.32.0",
3
+ "version": "2.33.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",