@valerypopoff/rivet2-core 2.19.0 → 2.21.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.
@@ -35,6 +35,7 @@ export * from './model/AgentResponseTracePresentation.js';
35
35
  export * from './model/DebuggerTransportSentinel.js';
36
36
  export * from './model/ProjectReferenceLoader.js';
37
37
  export * from './model/SubgraphProjectTarget.js';
38
+ export * from './model/ProjectGraphCallSites.js';
38
39
  export * from './model/ProjectBundle.js';
39
40
  export * from './model/ProjectBundleRuntime.js';
40
41
  export * from './model/RivetUIContext.js';
@@ -1312,7 +1312,7 @@ export class GraphProcessor {
1312
1312
  if (candidate.type !== 'subGraph' || candidate.disabled)
1313
1313
  continue;
1314
1314
  const node = candidate;
1315
- if (node.data.targetScope === 'other-projects' && !node.data.targetProjectId) {
1315
+ if (node.data.targetScope && !node.data.targetProjectId) {
1316
1316
  throw new Error('Select a project and graph for this Subgraph before running it.');
1317
1317
  }
1318
1318
  let childOwner = owner;
@@ -1320,9 +1320,12 @@ export class GraphProcessor {
1320
1320
  const target = {
1321
1321
  projectId: node.data.targetProjectId,
1322
1322
  version: node.data.targetVersion ?? 'latest',
1323
+ callerProjectId: owner.metadata.id,
1323
1324
  };
1324
1325
  const key = getSubgraphProjectKey(target);
1325
1326
  let resolved = this.#shared.subgraphTargetCache.get(key);
1327
+ if (resolved)
1328
+ await this.#run.context.subgraphProjectLoader?.validateTarget?.(target);
1326
1329
  if (!resolved) {
1327
1330
  if (!this.#run.context.subgraphProjectLoader) {
1328
1331
  throw new Error('Subgraph calls to another project require a subgraphProjectLoader. Use a project bundle locally or run through Rivet Studio Server.');
@@ -37,7 +37,7 @@ function* projectSubgraphs(project) {
37
37
  if (data.targetVersion !== undefined && data.targetVersion !== 'latest' && data.targetVersion !== 'published')
38
38
  throw new ProjectBundleError('Invalid Subgraph project version.');
39
39
  }
40
- else if (data.targetScope === 'other-projects') {
40
+ else if (data.targetScope) {
41
41
  throw new ProjectBundleError(`Subgraph ${node.title || node.id} has no selected project.`);
42
42
  }
43
43
  yield { sourceGraphId, data };
@@ -73,6 +73,7 @@ export function validateProjectBundleProjects(manifest, projects) {
73
73
  const targets = new Map(manifest.targets.map((t) => [projectBundleTargetKey(t.projectId, t.version), t.artifact]));
74
74
  const references = new Map(manifest.references.map((r) => [r.projectId, r.artifact]));
75
75
  const plugins = new Map(manifest.plugins.map((plugin) => [plugin.id, plugin]));
76
+ const members = manifest.workspace ? new Set(manifest.workspace.members.map((m) => m.projectId)) : undefined;
76
77
  const vertices = new Map();
77
78
  const graphKey = (artifact, graph) => JSON.stringify([artifact, graph]);
78
79
  for (const artifact of manifest.artifacts) {
@@ -92,6 +93,8 @@ export function validateProjectBundleProjects(manifest, projects) {
92
93
  for (const { sourceGraphId, data } of projectSubgraphs(project)) {
93
94
  let targetId = artifact.id;
94
95
  if (data.targetProjectId) {
96
+ if (members?.has(data.targetProjectId) && !members.has(project.metadata.id))
97
+ throw new ProjectBundleError('A project outside this bundle cannot reference a bundle member through a Subgraph node.');
95
98
  const call = {
96
99
  projectId: data.targetProjectId,
97
100
  version: data.targetVersion ?? 'latest',
@@ -166,12 +169,12 @@ export function validateProjectBundleManifest(value) {
166
169
  const obj = object(value);
167
170
  if (obj.format !== 'rivet-project-bundle' ||
168
171
  obj.schemaVersion !== 1 ||
169
- (obj.requiredLoaderVersion !== 1 && obj.requiredLoaderVersion !== 2 && obj.requiredLoaderVersion !== 3))
172
+ ![1, 2, 3, 4].includes(obj.requiredLoaderVersion))
170
173
  fail('unsupported format or loader version; update @valerypopoff/rivet2-node');
171
174
  const versionPolicy = obj.versionPolicy === undefined ? undefined : version(obj.versionPolicy);
172
- if (versionPolicy && obj.requiredLoaderVersion !== 3)
175
+ if (versionPolicy && Number(obj.requiredLoaderVersion) < 3)
173
176
  fail('version selection requires loader version 3');
174
- if (obj.requiredLoaderVersion === 3 && !versionPolicy)
177
+ if (Number(obj.requiredLoaderVersion) >= 3 && !versionPolicy)
175
178
  fail('loader version 3 requires a version selection');
176
179
  const artifacts = array(obj.artifacts).map((v) => {
177
180
  const a = object(v);
@@ -197,6 +200,47 @@ export function validateProjectBundleManifest(value) {
197
200
  const rootArtifact = string(obj.rootArtifact);
198
201
  if (!byId.has(rootArtifact))
199
202
  fail('missing root artifact');
203
+ let workspace;
204
+ if (obj.workspace !== undefined) {
205
+ if (obj.requiredLoaderVersion !== 4)
206
+ fail('workspace membership requires loader version 4');
207
+ const w = object(obj.workspace);
208
+ const safePath = (value) => {
209
+ const path = string(value);
210
+ if (/[\\:\0<>"|?*\x01-\x1f]/.test(path) ||
211
+ path.split('/').some((p) => !p || p === '.' || p === '..' || /[. ]$/.test(p)))
212
+ fail('unsafe workspace path');
213
+ return path;
214
+ };
215
+ const folders = array(w.folders, 511).map(safePath);
216
+ const memberIds = new Set(), locations = new Set();
217
+ for (const folder of folders) {
218
+ if (locations.has(folder.toLowerCase()))
219
+ fail('duplicate workspace folder');
220
+ locations.add(folder.toLowerCase());
221
+ if (folder.includes('/') && !folders.includes(folder.slice(0, folder.lastIndexOf('/'))))
222
+ fail('missing workspace parent folder');
223
+ }
224
+ const members = array(w.members).map((value) => {
225
+ const m = object(value), projectId = string(m.projectId), relativePath = safePath(m.relativePath);
226
+ if (!relativePath.endsWith('.rivet-project') ||
227
+ memberIds.has(projectId) ||
228
+ locations.has(relativePath.toLowerCase()) ||
229
+ !artifacts.some((a) => a.projectId === projectId))
230
+ fail('invalid workspace member');
231
+ const parent = relativePath.includes('/') ? relativePath.slice(0, relativePath.lastIndexOf('/')) : '';
232
+ if (parent && !folders.includes(parent))
233
+ fail('missing workspace member folder');
234
+ memberIds.add(projectId);
235
+ locations.add(relativePath.toLowerCase());
236
+ return { projectId, relativePath };
237
+ });
238
+ if (!members.length || !memberIds.has(byId.get(rootArtifact).projectId))
239
+ fail('workspace has no initial member');
240
+ workspace = { name: string(w.name), folders, members };
241
+ }
242
+ if (obj.requiredLoaderVersion === 4 && !workspace)
243
+ fail('loader version 4 requires workspace membership');
200
244
  const targetKeys = new Set(), referenceIds = new Set();
201
245
  // A version-selected artifact has both latest and published bindings. The
202
246
  // project limit must not accidentally halve when those aliases are emitted.
@@ -237,6 +281,7 @@ export function validateProjectBundleManifest(value) {
237
281
  format: 'rivet-project-bundle',
238
282
  schemaVersion: 1,
239
283
  requiredLoaderVersion: obj.requiredLoaderVersion,
284
+ ...(workspace ? { workspace } : {}),
240
285
  ...(versionPolicy ? { versionPolicy } : {}),
241
286
  exportingRuntimeVersion: string(obj.exportingRuntimeVersion),
242
287
  rootArtifact,
@@ -0,0 +1,46 @@
1
+ import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
2
+ export function listProjectGraphCallSites(project) {
3
+ const calls = [];
4
+ for (const [sourceGraphId, graph] of Object.entries(project.graphs)) {
5
+ for (const authored of graph.nodes) {
6
+ const node = resolveNodePrefabInstance(project, authored);
7
+ if (node.disabled)
8
+ continue;
9
+ // Broken library links have no effective call to inspect. They must not
10
+ // suppress known callers elsewhere or make the reference check incomplete.
11
+ if (node.type === 'nodePrefabInstance')
12
+ continue;
13
+ let targetProjectId;
14
+ let targetGraphId;
15
+ let targetVersion;
16
+ if (node.type === 'subGraph') {
17
+ const data = node.data;
18
+ targetProjectId = data.targetProjectId;
19
+ targetGraphId = data.graphId;
20
+ targetVersion = data.targetVersion ?? 'latest';
21
+ if (targetVersion !== 'latest' && targetVersion !== 'published')
22
+ throw new Error('Invalid Subgraph version.');
23
+ }
24
+ else if (node.type === 'referencedGraphAlias') {
25
+ const data = node.data;
26
+ targetProjectId = data.projectId;
27
+ targetGraphId = data.graphId;
28
+ targetVersion = 'project-reference';
29
+ }
30
+ else
31
+ continue;
32
+ if (!targetProjectId || !targetGraphId)
33
+ continue;
34
+ calls.push({
35
+ sourceGraphId,
36
+ sourceGraphName: graph.metadata?.name ?? sourceGraphId,
37
+ nodeId: authored.id,
38
+ nodeTitle: node.title || (node.type === 'subGraph' ? 'Subgraph' : 'Referenced Graph Alias'),
39
+ targetProjectId,
40
+ targetGraphId,
41
+ targetVersion,
42
+ });
43
+ }
44
+ }
45
+ return calls;
46
+ }
@@ -181,7 +181,7 @@ function getErrorBodyFields(data) {
181
181
  const cooldownMs = data.retryOnNon200CooldownMs ?? DEFAULT_LLM_CHAT_V2_RETRY_ON_NON_200_COOLDOWN_MS;
182
182
  return [
183
183
  ...(data.errorOnNon200 !== false ? [{ label: 'Throw on non-2XX', value: 'Enabled' }] : []),
184
- ...(data.catchRequestFailed ? [{ label: 'Catch all failures', value: 'Enabled' }] : []),
184
+ ...(data.catchRequestFailed ? [{ label: 'Catch all exceptions', value: 'Enabled' }] : []),
185
185
  ...(data.retryOnNon200
186
186
  ? [
187
187
  { label: 'Retry on non-200', value: 'Enabled' },
@@ -510,31 +510,31 @@ function getOutputEditors() {
510
510
  return group('Outputs', [
511
511
  {
512
512
  type: 'toggle',
513
- label: 'Output reasoning',
513
+ label: 'Reasoning',
514
514
  dataKey: 'outputReasoning',
515
515
  helperMessage: 'Adds a Reasoning output when the provider/model exposes reasoning or thinking text through the Vercel AI SDK. Some providers only expose token counts or summaries.',
516
516
  },
517
517
  {
518
518
  type: 'toggle',
519
- label: 'Output usage details',
519
+ label: 'Usage details',
520
520
  dataKey: 'outputUsage',
521
521
  helperMessage: 'Adds a Usage output built from Vercel AI SDK usage metadata: prompt, completion, total, cached, reasoning tokens, and estimated cost when available.',
522
522
  },
523
523
  {
524
524
  type: 'toggle',
525
- label: 'Output LLM attempts',
525
+ label: 'LLM attempts',
526
526
  dataKey: 'outputLLMAttempts',
527
527
  helperMessage: 'Adds one chronological record for every profile configuration, provider request, and response-validation attempt. Records include provider, model, retry status, and provider error details when available.',
528
528
  },
529
529
  {
530
530
  type: 'toggle',
531
- label: 'Output request body',
531
+ label: 'Request body',
532
532
  dataKey: 'outputRequestBody',
533
533
  helperMessage: 'Adds an LLM request body output. It can contain prompts and non-secret provider options; it never includes authorization headers or API keys.',
534
534
  },
535
535
  {
536
536
  type: 'toggle',
537
- label: 'Output response body',
537
+ label: 'Response body',
538
538
  dataKey: 'outputResponseBody',
539
539
  helperMessage: 'Adds the complete LLM response body captured at the provider HTTP boundary. JSON responses are parsed for inspection; other responses remain text. Rivet does not redact or truncate captured content.',
540
540
  },
@@ -572,14 +572,14 @@ function getErrorBehaviorEditors() {
572
572
  return group('Error behavior', [
573
573
  {
574
574
  type: 'toggle',
575
- label: 'Fail on non-2XX status code',
575
+ label: 'Throw exception on non-2XX status code',
576
576
  dataKey: 'errorOnNon200',
577
577
  defaultValue: true,
578
578
  helperMessage: 'After retries and profile fallback, throw on a rejected HTTP request. When disabled, return Run failed and Run error; unavailable response outputs are excluded.',
579
579
  },
580
580
  {
581
581
  type: 'toggle',
582
- label: 'Catch all failures',
582
+ label: 'Catch all exceptions',
583
583
  dataKey: 'catchRequestFailed',
584
584
  helperMessage: 'Return any node execution failure through Run failed and Run error instead of stopping the graph. Explicit graph cancellation is never caught.',
585
585
  },
@@ -118,26 +118,26 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
118
118
  editors: [
119
119
  {
120
120
  type: 'toggle',
121
- label: 'Output usage details',
121
+ label: 'Usage details',
122
122
  dataKey: 'outputUsage',
123
123
  helperMessage: 'Adds estimated totalCost to Usage only for recognized requested/returned models. Unknown pricing is omitted. Provider-specific premiums are not included.',
124
124
  },
125
125
  {
126
126
  type: 'toggle',
127
- label: 'Output request body',
127
+ label: 'Request body',
128
128
  dataKey: 'outputRequestBody',
129
129
  helperMessage: 'Adds the exact classifier request JSON body sent to the provider. It excludes authorization headers and Rivet-managed API keys.',
130
130
  },
131
131
  {
132
132
  type: 'toggle',
133
- label: 'Output response body',
133
+ label: 'Response body',
134
134
  dataKey: 'outputResponseBody',
135
135
  helperMessage: 'Shows the provider response, including rejected or invalid responses. Non-JSON responses appear as raw text. Captured content may contain sensitive input.',
136
136
  },
137
- { type: 'toggle', label: 'Output classifier attempts', dataKey: 'outputClassifierAttempts' },
137
+ { type: 'toggle', label: 'Classifier attempts', dataKey: 'outputClassifierAttempts' },
138
138
  {
139
139
  type: 'toggle',
140
- label: 'Output classifier profile summary',
140
+ label: 'Classifier profile summary',
141
141
  dataKey: 'outputClassifierProfileSummary',
142
142
  hideIf: (data) => data.configurationMode !== 'profile',
143
143
  },
@@ -165,14 +165,14 @@ export class ClassifierEvaluateNodeImpl extends NodeImpl {
165
165
  editors: [
166
166
  {
167
167
  type: 'toggle',
168
- label: 'Fail on non-2XX status code',
168
+ label: 'Throw exception on non-2XX status code',
169
169
  dataKey: 'errorOnNon200',
170
170
  defaultValue: true,
171
- helperMessage: 'After retries, throw on a rejected HTTP request. When disabled, unavailable outputs are excluded. Run failed and Run error are available only when Catch all failures is enabled.',
171
+ helperMessage: 'After retries, throw on a rejected HTTP request. When disabled, unavailable outputs are excluded. Run failed and Run error are available only when Catch all exceptions is enabled.',
172
172
  },
173
173
  {
174
174
  type: 'toggle',
175
- label: 'Catch all failures',
175
+ label: 'Catch all exceptions',
176
176
  dataKey: 'catchRequestFailed',
177
177
  helperMessage: 'Return any node execution failure through Run failed and Run error instead of stopping the graph. Explicit graph cancellation is never caught.',
178
178
  },
@@ -564,7 +564,7 @@ export function getClassifierEvaluateBodySections(data) {
564
564
  id: 'error-behavior',
565
565
  fields: [
566
566
  ...(data.errorOnNon200 !== false ? [{ label: 'Throw on non-2XX', value: 'Enabled' }] : []),
567
- ...(data.catchRequestFailed ? [{ label: 'Catch all failures', value: 'Enabled' }] : []),
567
+ ...(data.catchRequestFailed ? [{ label: 'Catch all exceptions', value: 'Enabled' }] : []),
568
568
  ...(data.retryOnNon200
569
569
  ? [
570
570
  { label: 'Retry on non-200', value: 'Enabled' },
@@ -303,6 +303,7 @@ export class SubGraphNodeImpl extends NodeImpl {
303
303
  // upload before reporting the caller run complete, so closing its tab
304
304
  // immediately after completion cannot discard the called-project run.
305
305
  await context.onSubgraphProjectRun?.({
306
+ createdAt: new Date(startedAt).toISOString(),
306
307
  target: { projectId: this.data.targetProjectId, version: this.data.targetVersion ?? 'latest' },
307
308
  resolved: recordingTarget,
308
309
  graphId: this.data.graphId,
@@ -36,6 +36,7 @@ export * from './model/AgentResponseTracePresentation.js';
36
36
  export * from './model/DebuggerTransportSentinel.js';
37
37
  export * from './model/ProjectReferenceLoader.js';
38
38
  export * from './model/SubgraphProjectTarget.js';
39
+ export * from './model/ProjectGraphCallSites.js';
39
40
  export * from './model/ProjectBundle.js';
40
41
  export * from './model/ProjectBundleRuntime.js';
41
42
  export * from './model/RivetUIContext.js';
@@ -125,23 +125,28 @@ export type SerializedProcessEventMap = {
125
125
  }>;
126
126
  error: {
127
127
  error: Error | string;
128
+ execution?: GraphExecutionMetadata;
128
129
  } & ReplayEventTiming;
129
130
  done: {
130
131
  results: GraphOutputs;
132
+ execution?: GraphExecutionMetadata;
131
133
  } & ReplayEventTiming;
132
134
  abort: {
133
135
  successful: boolean;
134
136
  error?: string | Error;
137
+ execution?: GraphExecutionMetadata;
135
138
  } & ReplayEventTiming;
136
139
  finish: void;
137
140
  trace: string;
138
- /** Present only when RecordingPlayer re-emits a historical lifecycle transition. */
141
+ /** Replay marker is recording-only; live debuggers may identify the owning root. */
139
142
  pause: {
140
143
  isReplay?: true;
144
+ execution?: GraphExecutionMetadata;
141
145
  } | undefined;
142
- /** Present only when RecordingPlayer re-emits a historical lifecycle transition. */
146
+ /** Replay marker is recording-only; live debuggers may identify the owning root. */
143
147
  resume: {
144
148
  isReplay?: true;
149
+ execution?: GraphExecutionMetadata;
145
150
  } | undefined;
146
151
  globalSet: WithExecution<{
147
152
  id: string;
@@ -25,7 +25,16 @@ export type ProjectBundleArtifact = {
25
25
  export type ProjectBundleManifest = {
26
26
  format: 'rivet-project-bundle';
27
27
  schemaVersion: 1;
28
- requiredLoaderVersion: 1 | 2 | 3;
28
+ requiredLoaderVersion: 1 | 2 | 3 | 4;
29
+ /** Explicit container membership; other artifacts are portable dependency snapshots. */
30
+ workspace?: {
31
+ name: string;
32
+ folders: string[];
33
+ members: {
34
+ projectId: string;
35
+ relativePath: string;
36
+ }[];
37
+ };
29
38
  /** Explicit export-wide version selection; one artifact per project. */
30
39
  versionPolicy?: 'latest' | 'published';
31
40
  exportingRuntimeVersion: string;
@@ -0,0 +1,12 @@
1
+ import type { Project } from './Project.js';
2
+ /** Explicit cross-project calls; graph identity is always paired with its owner. */
3
+ export type ProjectGraphCallSite = {
4
+ sourceGraphId: string;
5
+ sourceGraphName: string;
6
+ nodeId: string;
7
+ nodeTitle: string;
8
+ targetProjectId: string;
9
+ targetGraphId: string;
10
+ targetVersion: 'latest' | 'published' | 'project-reference';
11
+ };
12
+ export declare function listProjectGraphCallSites(project: Project): ProjectGraphCallSite[];
@@ -7,6 +7,8 @@ export type SubgraphProjectVersion = 'latest' | 'published';
7
7
  export type SubgraphProjectTarget = {
8
8
  projectId: ProjectId;
9
9
  version: SubgraphProjectVersion;
10
+ /** Actual graph owner, supplied by the processor rather than persisted node configuration. */
11
+ callerProjectId?: ProjectId;
10
12
  };
11
13
  export type ResolvedSubgraphProject = {
12
14
  project: Project;
@@ -20,6 +22,8 @@ export type ResolvedSubgraphProject = {
20
22
  sourceProjectPath?: string;
21
23
  };
22
24
  export type SubgraphProjectRun = {
25
+ /** Logical run creation time, captured before execution; optional for older hosts. */
26
+ createdAt?: string;
23
27
  target: SubgraphProjectTarget;
24
28
  resolved: ResolvedSubgraphProject;
25
29
  graphId: GraphId;
@@ -32,6 +36,8 @@ export type SubgraphProjectRun = {
32
36
  };
33
37
  export type SubgraphProjectLoader = {
34
38
  loadTarget(target: SubgraphProjectTarget): Promise<ResolvedSubgraphProject>;
39
+ /** Recheck caller-dependent policy even when a target snapshot is already cached. */
40
+ validateTarget?(target: SubgraphProjectTarget): Promise<void>;
35
41
  };
36
42
  /** Internal definition key; not a project metadata ID or a persisted reference. */
37
43
  export declare function getSubgraphProjectKey(target: SubgraphProjectTarget): ProjectId;
@@ -16,7 +16,7 @@ export type SubGraphNode = ChartNode & {
16
16
  /** Saved project target resolved by a host or portable bundle loader. Absent means the current project. */
17
17
  targetProjectId?: ProjectId;
18
18
  /** Retains the hosted picker mode before an external project is selected. */
19
- targetScope?: 'other-projects';
19
+ targetScope?: 'other-projects' | 'same-bundle';
20
20
  targetVersion?: SubgraphProjectVersion;
21
21
  /** Last selected boundary keeps existing wires visible while a hosted preview reloads. */
22
22
  targetBoundary?: GraphBoundary;
@@ -20,6 +20,10 @@ export type SocketRecordingOptions = {
20
20
  */
21
21
  signal?: AbortSignal;
22
22
  };
23
+ /** Recording needs an event source, not ownership of a physical WebSocket. */
24
+ export type SocketRecordingChannel = Pick<EventTarget, 'addEventListener' | 'removeEventListener'> & {
25
+ readonly readyState: number;
26
+ };
23
27
  export declare class ExecutionRecorder {
24
28
  #private;
25
29
  recordingId: RecordingId | undefined;
@@ -27,7 +31,7 @@ export declare class ExecutionRecorder {
27
31
  on: Emittery<ExecutionRecorderEvents>['on'];
28
32
  off: Emittery<ExecutionRecorderEvents>['off'];
29
33
  once: Emittery<ExecutionRecorderEvents>['once'];
30
- recordSocket(channel: WebSocket, options?: SocketRecordingOptions): Promise<void>;
34
+ recordSocket(channel: SocketRecordingChannel, options?: SocketRecordingOptions): Promise<void>;
31
35
  record(processor: GraphProcessor): (terminal?: {
32
36
  type: 'done';
33
37
  results: ProcessEvents['done']['results'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-core",
3
- "version": "2.19.0",
3
+ "version": "2.21.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/bundle.cjs",
6
6
  "module": "dist/esm/index.js",