@valerypopoff/rivet2-core 2.1.2 → 2.1.3

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 (52) hide show
  1. package/dist/cjs/bundle.cjs +904 -434
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/processSettings.js +5 -0
  4. package/dist/esm/exports.js +2 -0
  5. package/dist/esm/model/GraphProcessor.js +24 -45
  6. package/dist/esm/model/GraphRunLifecycle.js +67 -0
  7. package/dist/esm/model/MarkdownSanitizationPolicy.js +38 -0
  8. package/dist/esm/model/UiGraph.js +57 -0
  9. package/dist/esm/model/UiGraphRendererStyles.js +82 -0
  10. package/dist/esm/model/UiGraphRuntimeModel.js +71 -0
  11. package/dist/esm/model/chat-v2/aiSdkBridge.js +1 -1
  12. package/dist/esm/model/chat-v2/chatV2EditorCache.js +2 -2
  13. package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -48
  14. package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +98 -0
  15. package/dist/esm/model/chat-v2/chatV2RequestPlan.js +64 -0
  16. package/dist/esm/model/chat-v2/chatV2RuntimeOptions.js +11 -39
  17. package/dist/esm/model/chat-v2/index.js +2 -0
  18. package/dist/esm/model/chat-v2/llmChatV2NodeData.js +1 -0
  19. package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +31 -11
  20. package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +21 -9
  21. package/dist/esm/model/chat-v2/providerOptions.js +9 -35
  22. package/dist/esm/model/nodes/LLMChatV2Node.js +3 -3
  23. package/dist/esm/plugins/autoevals/AutoEvalsNode.js +3 -1
  24. package/dist/esm/plugins/gentrace/gentraceSdk.js +8 -0
  25. package/dist/esm/plugins/gentrace/plugin.js +5 -4
  26. package/dist/esm/plugins/google/google.js +9 -7
  27. package/dist/esm/utils/pQueueCompat.js +1 -1
  28. package/dist/esm/utils/serialization/serializationUtils.js +35 -0
  29. package/dist/esm/utils/serialization/serialization_v4.js +5 -4
  30. package/dist/esm/webAppRuntime.js +2 -0
  31. package/dist/types/api/createProcessor.d.ts +1 -1
  32. package/dist/types/api/processSettings.d.ts +3 -4
  33. package/dist/types/exports.d.ts +2 -0
  34. package/dist/types/model/GraphRunLifecycle.d.ts +22 -0
  35. package/dist/types/model/MarkdownSanitizationPolicy.d.ts +9 -0
  36. package/dist/types/model/ProcessContext.d.ts +2 -2
  37. package/dist/types/model/Settings.d.ts +1 -0
  38. package/dist/types/model/UiGraph.d.ts +12 -0
  39. package/dist/types/model/UiGraphRendererStyles.d.ts +1 -1
  40. package/dist/types/model/UiGraphRuntimeModel.d.ts +52 -0
  41. package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +46 -0
  42. package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +42 -0
  43. package/dist/types/model/chat-v2/chatV2Types.d.ts +1 -0
  44. package/dist/types/model/chat-v2/index.d.ts +2 -0
  45. package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +1 -0
  46. package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +2 -0
  47. package/dist/types/model/chat-v2/providerOptions.d.ts +2 -2
  48. package/dist/types/plugins/gentrace/gentraceSdk.d.ts +5 -0
  49. package/dist/types/plugins/gentrace/plugin.d.ts +1 -1
  50. package/dist/types/utils/pQueueCompat.d.ts +1 -1
  51. package/dist/types/webAppRuntime.d.ts +4 -0
  52. package/package.json +15 -9
@@ -1,7 +1,12 @@
1
1
  import { DEFAULT_CHAT_NODE_TIMEOUT } from '../utils/defaults.js';
2
+ function definedRuntimeSettings(settings) {
3
+ return Object.fromEntries(Object.entries(settings).filter(([, value]) => value !== undefined && value !== ''));
4
+ }
2
5
  export function resolveProcessSettings(settings = {}, fallbacks = {}) {
3
6
  const openAiApiKey = settings.openAiApiKey || settings.openAiKey || fallbacks.openAiApiKey || fallbacks.openAiKey || '';
4
7
  return {
8
+ ...fallbacks,
9
+ ...definedRuntimeSettings(settings),
5
10
  openAiApiKey,
6
11
  openAiKey: openAiApiKey,
7
12
  anthropicApiKey: settings.anthropicApiKey || fallbacks.anthropicApiKey || '',
@@ -7,7 +7,9 @@ export * from './model/NodeGraph.js';
7
7
  export * from './model/NodePrefabResolver.js';
8
8
  export { getGraphBoundary } from './model/GraphBoundaryCache.js';
9
9
  export * from './model/UiGraph.js';
10
+ export * from './model/UiGraphRuntimeModel.js';
10
11
  export * from './model/UiGraphRendererStyles.js';
12
+ export * from './model/MarkdownSanitizationPolicy.js';
11
13
  export * from './model/NodeImpl.js';
12
14
  export * from './model/NodeDefinition.js';
13
15
  export * from './model/Nodes.js';
@@ -18,6 +18,7 @@ import { getInputNodesTo, getMissingRequiredInputs, getOutputNodesFrom, getStart
18
18
  import { wireSubprocessorEvents, wireSubprocessorLifecycle } from './SubprocessorBridge.js';
19
19
  import { createGraphAbortError, createGraphAbortErrorFromSignal, createGraphAbortReason, getAbortSignalReason, getGraphAbortReasonFromError, getGraphAbortReasonFromSignal, isAbortLikeError, isRaceLoserGraphAbortReason, isSuccessfulNonRaceGraphAbortReason, RACE_LOSER_EXCLUSION_REASON, SUCCESSFUL_GRAPH_ABORT_EXCLUSION_REASON, } from './GraphAbortReasons.js';
20
20
  import { emitDetached } from '../utils/emitDetached.js';
21
+ import { GraphRunLifecycle } from './GraphRunLifecycle.js';
21
22
  import { createExcludedNodeOutputs, getControlFlowExclusionDecision, getMissingRequiredInputExclusion, } from './NodeExclusionPolicy.js';
22
23
  // eslint-disable-next-line import/no-cycle -- There has to be a cycle because CodeRunner needs to import the entirety of Rivet
23
24
  import { IsomorphicCodeRunner } from '../integrations/CodeRunner.js';
@@ -112,11 +113,10 @@ export class GraphProcessor {
112
113
  #nodeInstances;
113
114
  #connections;
114
115
  #emitter = new Emittery();
115
- #running = false;
116
+ #lifecycle = new GraphRunLifecycle();
116
117
  #isSubProcessor = false;
117
118
  #externalFunctions = {};
118
119
  slowMode = false;
119
- #isPaused = false;
120
120
  #parent;
121
121
  #registry;
122
122
  #concurrency;
@@ -161,9 +161,6 @@ export class GraphProcessor {
161
161
  #contextValues = undefined;
162
162
  #globals = undefined;
163
163
  #attachedNodeData = undefined;
164
- #aborted = false;
165
- #abortSuccessfully = false;
166
- #abortError = undefined;
167
164
  #successfulAbortTerminalProcessIds = undefined;
168
165
  #totalCost = 0;
169
166
  #ignoreNodes = undefined;
@@ -179,10 +176,9 @@ export class GraphProcessor {
179
176
  #graphInputNodeValues = {};
180
177
  /** User input nodes that are pending user input. */
181
178
  #pendingUserInputs = undefined;
182
- #finishEmitted = false;
183
179
  #unsubscribeTokenizerError;
184
180
  get isRunning() {
185
- return this.#running;
181
+ return this.#lifecycle.isRunning;
186
182
  }
187
183
  #startNodeTiming() {
188
184
  return this.#captureNodeTimings ? getMonotonicTimeMs() : undefined;
@@ -400,11 +396,9 @@ export class GraphProcessor {
400
396
  this.#externalFunctions[name] = fn;
401
397
  }
402
398
  async abort(successful = false, error) {
403
- if (!this.#running || this.#aborted) {
399
+ if (!this.#lifecycle.requestAbort(successful, error)) {
404
400
  return Promise.resolve();
405
401
  }
406
- this.#abortSuccessfully = successful;
407
- this.#abortError = error;
408
402
  const abortReason = createGraphAbortReason(successful, error);
409
403
  this.#abortController.abort(abortReason);
410
404
  this.#abortActiveNodeControllers(abortReason);
@@ -415,14 +409,12 @@ export class GraphProcessor {
415
409
  await this.#processingQueue.onIdle();
416
410
  }
417
411
  pause() {
418
- if (this.#isPaused === false) {
419
- this.#isPaused = true;
412
+ if (this.#lifecycle.pause()) {
420
413
  emitDetached(this.#emitter, 'pause', void 0);
421
414
  }
422
415
  }
423
416
  resume() {
424
- if (this.#isPaused) {
425
- this.#isPaused = false;
417
+ if (this.#lifecycle.resume()) {
426
418
  emitDetached(this.#emitter, 'resume', void 0);
427
419
  }
428
420
  }
@@ -430,16 +422,16 @@ export class GraphProcessor {
430
422
  this.slowMode = slowMode;
431
423
  }
432
424
  async #waitUntilUnpaused() {
433
- if (!this.#isPaused) {
425
+ if (!this.#lifecycle.isPaused) {
434
426
  return;
435
427
  }
436
428
  if (this.#abortController.signal.aborted) {
437
- throw this.#getAbortError();
429
+ throw this.#lifecycle.getAbortError();
438
430
  }
439
431
  await new Promise((resolve, reject) => {
440
432
  const abortListener = () => {
441
433
  cleanup();
442
- reject(this.#getAbortError());
434
+ reject(this.#lifecycle.getAbortError());
443
435
  };
444
436
  const unsubscribeResume = this.#emitter.on('resume', () => {
445
437
  cleanup();
@@ -452,12 +444,6 @@ export class GraphProcessor {
452
444
  this.#abortController.signal.addEventListener('abort', abortListener, { once: true });
453
445
  });
454
446
  }
455
- #getAbortError() {
456
- if (typeof this.#abortError === 'string') {
457
- return new Error(this.#abortError);
458
- }
459
- return this.#abortError ?? new Error('Processing aborted');
460
- }
461
447
  async *events() {
462
448
  for await (const [event, data] of this.#emitter.anyEvent()) {
463
449
  yield {
@@ -521,7 +507,7 @@ export class GraphProcessor {
521
507
  erroredNodes: this.#erroredNodes,
522
508
  graphInputs: this.#graphInputs,
523
509
  graphOutputs: this.#graphOutputs,
524
- isAborted: () => this.#aborted,
510
+ isAborted: () => this.#lifecycle.isAborted,
525
511
  nodeResults: this.#nodeResults,
526
512
  project: this.#project,
527
513
  recorder,
@@ -536,7 +522,8 @@ export class GraphProcessor {
536
522
  this.#graphOutputs = graphOutputs;
537
523
  },
538
524
  setRunning: (running) => {
539
- this.#running = running;
525
+ if (!running)
526
+ this.#lifecycle.complete();
540
527
  },
541
528
  visitedNodes: this.#visitedNodes,
542
529
  waitUntilUnpaused: () => this.#waitUntilUnpaused(),
@@ -544,8 +531,7 @@ export class GraphProcessor {
544
531
  return this.#graphOutputs;
545
532
  }
546
533
  #initProcessState() {
547
- this.#running = true;
548
- this.#finishEmitted = false;
534
+ this.#lifecycle.begin();
549
535
  if (!this.#hasPreloadedData) {
550
536
  this.#nodeResults = new Map();
551
537
  this.#visitedNodes = new Set();
@@ -569,12 +555,6 @@ export class GraphProcessor {
569
555
  this.#nodeProcessContextBase = undefined;
570
556
  this.#runToRelevantNodeIds = undefined;
571
557
  this.#abortController = this.#newAbortController();
572
- this.#abortController.signal.addEventListener('abort', () => {
573
- this.#aborted = true;
574
- });
575
- this.#aborted = false;
576
- this.#abortError = undefined;
577
- this.#abortSuccessfully = false;
578
558
  this.#successfulAbortTerminalProcessIds = new Set();
579
559
  this.#nodeAbortControllers = new Map();
580
560
  this.#loadedProjects =
@@ -595,7 +575,7 @@ export class GraphProcessor {
595
575
  inputs = {},
596
576
  /** Contextual data available to all graphs and subgraphs. Kind of like react context, avoids drilling down data into subgraphs. Be careful when using it. */
597
577
  contextValues = {}) {
598
- if (this.#running) {
578
+ if (this.#lifecycle.isRunning) {
599
579
  throw new Error('Cannot process graph while already processing');
600
580
  }
601
581
  try {
@@ -620,16 +600,15 @@ export class GraphProcessor {
620
600
  return await this.#profileRuntimeAsync('finalizeGraphRun', () => this.#finalizeGraphRun());
621
601
  }
622
602
  finally {
623
- this.#running = false;
603
+ this.#lifecycle.complete();
624
604
  this.#cleanupTokenizerErrorListener();
625
605
  await this.#profileRuntimeAsync('emitFinish', () => this.#emitFinishIfNeeded());
626
606
  }
627
607
  }
628
608
  async #emitFinishIfNeeded() {
629
- if (this.#isSubProcessor || this.#finishEmitted) {
609
+ if (!this.#lifecycle.claimRootFinish(this.#isSubProcessor)) {
630
610
  return;
631
611
  }
632
- this.#finishEmitted = true;
633
612
  await this.#emitter.emit('finish', undefined);
634
613
  }
635
614
  #initializeGraphRun(context, inputs, contextValues) {
@@ -853,8 +832,8 @@ export class GraphProcessor {
853
832
  });
854
833
  }
855
834
  #createGraphError(erroredNodes) {
856
- if (this.#abortError) {
857
- return this.#getAbortError();
835
+ if (this.#lifecycle.abortError) {
836
+ return this.#lifecycle.getAbortError();
858
837
  }
859
838
  const message = `Graph ${this.#graph.metadata.name} (${this.#graph.metadata.id}) failed to process due to errors in nodes:\n${erroredNodes
860
839
  .map(([nodeId]) => `- ${this.#nodesById[nodeId].title} (${nodeId})`)
@@ -867,7 +846,7 @@ export class GraphProcessor {
867
846
  }
868
847
  async #throwIfGraphErrored() {
869
848
  const erroredNodes = this.#getUnhandledErroredNodes();
870
- if (!erroredNodes.length || this.#abortSuccessfully) {
849
+ if (!erroredNodes.length || this.#lifecycle.abortSuccessful) {
871
850
  return;
872
851
  }
873
852
  const error = this.#createGraphError(erroredNodes);
@@ -880,7 +859,7 @@ export class GraphProcessor {
880
859
  async #finalizeGraphRun() {
881
860
  ensureGraphCostOutput(this.#graphOutputs, this.#totalCost);
882
861
  const outputValues = this.#graphOutputs;
883
- this.#running = false;
862
+ this.#lifecycle.complete();
884
863
  await this.#emitter.emit('graphFinish', this.#withExecution({ graph: this.#graph, outputs: outputValues }));
885
864
  if (!this.#isSubProcessor) {
886
865
  await this.#emitter.emit('done', { results: outputValues });
@@ -1227,7 +1206,7 @@ export class GraphProcessor {
1227
1206
  setNodeResults: (nodeId, outputs) => this.#nodeResults.set(nodeId, outputs),
1228
1207
  markNodeVisited: (nodeId) => this.#visitedNodes.add(nodeId),
1229
1208
  nodeErrored: (n, err, pid, durationMs, splitRunDurationMs) => this.#nodeErrored(n, err, pid, durationMs, splitRunDurationMs),
1230
- isAborted: () => this.#aborted,
1209
+ isAborted: () => this.#lifecycle.isAborted,
1231
1210
  getAbortError: () => createGraphAbortErrorFromSignal(this.#abortController.signal),
1232
1211
  emit: (event, data) => {
1233
1212
  if (event === 'partialOutput') {
@@ -1316,8 +1295,8 @@ export class GraphProcessor {
1316
1295
  this.#successfulAbortTerminalProcessIds.add(processId);
1317
1296
  return SUCCESSFUL_GRAPH_ABORT_EXCLUSION_REASON;
1318
1297
  }
1319
- if (this.#abortSuccessfully && isAbortLikeError(error)) {
1320
- const exclusionReason = this.#abortError === RACE_LOSER_EXCLUSION_REASON
1298
+ if (this.#lifecycle.abortSuccessful && isAbortLikeError(error)) {
1299
+ const exclusionReason = this.#lifecycle.abortError === RACE_LOSER_EXCLUSION_REASON
1321
1300
  ? RACE_LOSER_EXCLUSION_REASON
1322
1301
  : SUCCESSFUL_GRAPH_ABORT_EXCLUSION_REASON;
1323
1302
  if (exclusionReason === SUCCESSFUL_GRAPH_ABORT_EXCLUSION_REASON) {
@@ -1577,7 +1556,7 @@ export class GraphProcessor {
1577
1556
  const wireEventsProfileStart = this.#startRuntimeProfile();
1578
1557
  try {
1579
1558
  wireSubprocessorEvents(processor, this.#emitter, {
1580
- isPaused: () => this.#isPaused,
1559
+ isPaused: () => this.#lifecycle.isPaused,
1581
1560
  pause: () => {
1582
1561
  void this.pause();
1583
1562
  },
@@ -0,0 +1,67 @@
1
+ /** Owns run-level state only. Scheduling and event emission remain in GraphProcessor. */
2
+ export class GraphRunLifecycle {
3
+ #phase = 'idle';
4
+ #paused = false;
5
+ #abort;
6
+ #finishClaimed = false;
7
+ get phase() {
8
+ return this.#phase;
9
+ }
10
+ get isRunning() {
11
+ return this.#phase === 'running' || this.#phase === 'aborting';
12
+ }
13
+ get isPaused() {
14
+ return this.#paused;
15
+ }
16
+ get isAborted() {
17
+ return this.#abort != null;
18
+ }
19
+ get abortSuccessful() {
20
+ return this.#abort?.successful ?? false;
21
+ }
22
+ get abortError() {
23
+ return this.#abort?.error;
24
+ }
25
+ begin() {
26
+ if (this.isRunning) {
27
+ throw new Error('Cannot process graph while already processing');
28
+ }
29
+ this.#phase = 'running';
30
+ this.#abort = undefined;
31
+ this.#finishClaimed = false;
32
+ }
33
+ complete() {
34
+ if (this.#phase !== 'idle')
35
+ this.#phase = 'finished';
36
+ }
37
+ requestAbort(successful, error) {
38
+ if (!this.isRunning || this.#abort)
39
+ return undefined;
40
+ this.#phase = 'aborting';
41
+ this.#abort = { successful, error };
42
+ return this.#abort;
43
+ }
44
+ pause() {
45
+ if (this.#paused)
46
+ return false;
47
+ this.#paused = true;
48
+ return true;
49
+ }
50
+ resume() {
51
+ if (!this.#paused)
52
+ return false;
53
+ this.#paused = false;
54
+ return true;
55
+ }
56
+ claimRootFinish(isSubProcessor) {
57
+ if (isSubProcessor || this.#finishClaimed)
58
+ return false;
59
+ this.#finishClaimed = true;
60
+ return true;
61
+ }
62
+ getAbortError() {
63
+ if (typeof this.#abort?.error === 'string')
64
+ return new Error(this.#abort.error);
65
+ return this.#abort?.error ?? new Error('Processing aborted');
66
+ }
67
+ }
@@ -0,0 +1,38 @@
1
+ export const RIVET_MARKDOWN_ALLOWED_TAGS = [
2
+ 'a',
3
+ 'blockquote',
4
+ 'br',
5
+ 'code',
6
+ 'del',
7
+ 'em',
8
+ 'h1',
9
+ 'h2',
10
+ 'h3',
11
+ 'h4',
12
+ 'h5',
13
+ 'h6',
14
+ 'hr',
15
+ 'li',
16
+ 'ol',
17
+ 'p',
18
+ 'pre',
19
+ 'strong',
20
+ 'sub',
21
+ 'sup',
22
+ 'table',
23
+ 'tbody',
24
+ 'td',
25
+ 'th',
26
+ 'thead',
27
+ 'tr',
28
+ 'ul',
29
+ ];
30
+ export const RIVET_MARKDOWN_ALLOWED_ATTRIBUTES = ['class', 'href', 'title'];
31
+ // http(s), mailto, hashes, and ordinary relative links. Protocol-relative and
32
+ // active/unknown schemes are intentionally excluded.
33
+ export const RIVET_MARKDOWN_ALLOWED_URI_REGEXP_SOURCE = '^(?:https?:|mailto:|#|\\?(?:[^/]|$)|/(?!/)|\\.{1,2}/|[a-z0-9._~-]+(?:[/?#]|$))';
34
+ export const RIVET_MARKDOWN_SANITIZER_POLICY = Object.freeze({
35
+ allowedAttributes: RIVET_MARKDOWN_ALLOWED_ATTRIBUTES,
36
+ allowedTags: RIVET_MARKDOWN_ALLOWED_TAGS,
37
+ allowedUriRegExpSource: RIVET_MARKDOWN_ALLOWED_URI_REGEXP_SOURCE,
38
+ });
@@ -1,4 +1,51 @@
1
1
  import { newId } from '../utils/newId.js';
2
+ export function hasValidUiGraphComponentIds(uiGraph) {
3
+ const componentIds = new Set();
4
+ for (const component of uiGraph.components) {
5
+ const componentId = typeof component.id === 'string' ? component.id : '';
6
+ if (!componentId.trim() || componentIds.has(componentId)) {
7
+ return false;
8
+ }
9
+ componentIds.add(componentId);
10
+ }
11
+ return true;
12
+ }
13
+ /**
14
+ * Returns an immutable repair for legacy or externally assembled UI graphs.
15
+ * Repaired IDs are deterministic so separately rendered HTML and action calls agree
16
+ * without mutating a host-owned project snapshot.
17
+ */
18
+ export function normalizeUiGraphComponentIds(uiGraph) {
19
+ if (hasValidUiGraphComponentIds(uiGraph)) {
20
+ return uiGraph;
21
+ }
22
+ const reservedIds = new Set(uiGraph.components
23
+ .map((component) => (typeof component.id === 'string' ? component.id : ''))
24
+ .filter((componentId) => Boolean(componentId.trim())));
25
+ const usedIds = new Set();
26
+ const graphId = typeof uiGraph.id === 'string' && uiGraph.id.trim() ? uiGraph.id : 'ui-graph';
27
+ const components = uiGraph.components.map((component, index) => {
28
+ const componentId = typeof component.id === 'string' ? component.id : '';
29
+ if (componentId.trim() && !usedIds.has(componentId)) {
30
+ usedIds.add(componentId);
31
+ return component;
32
+ }
33
+ const repairedId = getRepairedUiGraphComponentId(graphId, index, reservedIds, usedIds);
34
+ usedIds.add(repairedId);
35
+ return { ...component, id: repairedId };
36
+ });
37
+ return { ...uiGraph, components };
38
+ }
39
+ function getRepairedUiGraphComponentId(graphId, componentIndex, reservedIds, usedIds) {
40
+ const baseId = `${graphId}-component-${componentIndex + 1}`;
41
+ let repairedId = baseId;
42
+ let suffix = 2;
43
+ while (reservedIds.has(repairedId) || usedIds.has(repairedId)) {
44
+ repairedId = `${baseId}-${suffix}`;
45
+ suffix += 1;
46
+ }
47
+ return repairedId;
48
+ }
2
49
  export function createDefaultUiGraph(options = {}) {
3
50
  const promptStateKey = 'input';
4
51
  const resultStateKey = 'result';
@@ -66,6 +113,16 @@ export function resolveUiGraphActionInputs(action, state) {
66
113
  }
67
114
  return inputs;
68
115
  }
116
+ /**
117
+ * Selects the UI state that a button action is explicitly allowed to send.
118
+ * Outputs and unrelated form fields stay local to the rendered web app.
119
+ */
120
+ export function getUiGraphActionState(action, state) {
121
+ return Object.fromEntries([...new Set(getUiGraphActionInputBindings(action).map((binding) => binding.stateKey))]
122
+ .filter(Boolean)
123
+ .filter((stateKey) => Object.prototype.hasOwnProperty.call(state, stateKey))
124
+ .map((stateKey) => [stateKey, state[stateKey]]));
125
+ }
69
126
  export function resolveUiGraphActionOutputStateValue(action, outputs) {
70
127
  if (!action.outputKey) {
71
128
  return outputs;
@@ -101,11 +101,93 @@ export const RIVET_WEB_APP_RENDERER_CSS = `
101
101
  .rivet-web-app-output {
102
102
  display: grid;
103
103
  gap: 8px;
104
+ position: relative;
104
105
  }
105
106
 
106
107
  .rivet-web-app-output-title {
107
108
  color: var(--rivet-web-app-output-title);
108
109
  font-weight: 700;
110
+ padding-right: 32px;
111
+ }
112
+
113
+ .rivet-web-app-output-has-download .rivet-web-app-output-title {
114
+ padding-right: 64px;
115
+ }
116
+
117
+ .rivet-web-app-output-action-button {
118
+ position: absolute;
119
+ top: 11px;
120
+ width: 24px;
121
+ height: 24px;
122
+ border: 0;
123
+ border-radius: 5px;
124
+ background: transparent;
125
+ color: color-mix(in srgb, var(--rivet-web-app-foreground) 68%, transparent);
126
+ cursor: pointer;
127
+ padding: 0;
128
+ }
129
+
130
+ .rivet-web-app-output-copy-button {
131
+ right: 11px;
132
+ }
133
+
134
+ .rivet-web-app-output-download-button {
135
+ right: 39px;
136
+ }
137
+
138
+ .rivet-web-app-output-copy-button::before,
139
+ .rivet-web-app-output-copy-button::after {
140
+ content: "";
141
+ position: absolute;
142
+ width: 10px;
143
+ height: 12px;
144
+ border: 1.5px solid currentColor;
145
+ border-radius: 2px;
146
+ }
147
+
148
+ .rivet-web-app-output-copy-button::before {
149
+ top: 5px;
150
+ left: 8px;
151
+ }
152
+
153
+ .rivet-web-app-output-copy-button::after {
154
+ top: 8px;
155
+ left: 5px;
156
+ background: var(--rivet-web-app-card-background);
157
+ }
158
+
159
+ .rivet-web-app-output-download-button::before,
160
+ .rivet-web-app-output-download-button::after {
161
+ content: "";
162
+ position: absolute;
163
+ }
164
+
165
+ .rivet-web-app-output-download-button::before {
166
+ top: 5px;
167
+ left: 8px;
168
+ width: 8px;
169
+ height: 8px;
170
+ border-right: 1.5px solid currentColor;
171
+ border-bottom: 1.5px solid currentColor;
172
+ transform: rotate(45deg);
173
+ }
174
+
175
+ .rivet-web-app-output-download-button::after {
176
+ top: 16px;
177
+ left: 6px;
178
+ width: 12px;
179
+ height: 4px;
180
+ border-right: 1.5px solid currentColor;
181
+ border-bottom: 1.5px solid currentColor;
182
+ border-left: 1.5px solid currentColor;
183
+ border-radius: 0 0 2px 2px;
184
+ }
185
+
186
+ .rivet-web-app-output-action-button:hover,
187
+ .rivet-web-app-output-action-button:focus-visible {
188
+ color: var(--primary, #ff9e2c);
189
+ outline: none;
190
+ background: color-mix(in srgb, var(--rivet-web-app-foreground) 8%, transparent);
109
191
  }
110
192
 
111
193
  .rivet-web-app-output pre {
@@ -0,0 +1,71 @@
1
+ export function getUiGraphComponentRenderModel(component, state) {
2
+ switch (component.type) {
3
+ case 'text':
4
+ return { component, text: component.text, type: 'text' };
5
+ case 'markdown':
6
+ return { component, markdown: component.markdown, type: 'markdown' };
7
+ case 'input':
8
+ case 'textarea':
9
+ return {
10
+ component,
11
+ label: getUiGraphComponentLabel(component),
12
+ type: component.type,
13
+ value: `${state[component.stateKey] ?? component.defaultValue ?? ''}`,
14
+ };
15
+ case 'button':
16
+ return { component, label: component.label, type: 'button' };
17
+ case 'output':
18
+ return {
19
+ component,
20
+ label: getUiGraphComponentLabel(component),
21
+ output: getUiGraphOutputRenderModel(state, component.stateKey, component.renderAs ?? 'text'),
22
+ type: 'output',
23
+ };
24
+ }
25
+ }
26
+ export function getUiGraphComponentLabel(component) {
27
+ return component.label || component.stateKey;
28
+ }
29
+ export function getUiGraphOutputRenderModel(state, stateKey, renderAs) {
30
+ const value = state[stateKey];
31
+ const hasValue = hasUiGraphStateValue(state, stateKey);
32
+ const renderedValue = renderUiGraphOutputValue(value, renderAs);
33
+ return {
34
+ hasValue,
35
+ ...(hasValue && renderAs === 'json' ? { jsonDownloadValue: stringifyUiGraphValue(value) } : {}),
36
+ renderedValue,
37
+ renderAs,
38
+ };
39
+ }
40
+ export function hasUiGraphStateValue(state, key) {
41
+ return Object.prototype.hasOwnProperty.call(state, key) && state[key] !== undefined;
42
+ }
43
+ export function renderUiGraphOutputValue(value, renderAs) {
44
+ if (renderAs === 'json') {
45
+ return stringifyUiGraphValue(value) ?? '';
46
+ }
47
+ return typeof value === 'string' ? value : value == null ? '' : stringifyUiGraphValue(value) ?? '';
48
+ }
49
+ export function stringifyUiGraphValue(value) {
50
+ try {
51
+ return JSON.stringify(value, null, 2);
52
+ }
53
+ catch {
54
+ return '[Unserializable value]';
55
+ }
56
+ }
57
+ export function getUiGraphJsonOutputFilename(appName, date = new Date()) {
58
+ const safeName = appName
59
+ .trim()
60
+ .replace(/[<>:"/\\|?*\u0000-\u001F]/g, '-')
61
+ .replace(/\s+/g, ' ')
62
+ .slice(0, 80);
63
+ return `${safeName || 'Rivet web app'} ${formatUiGraphDownloadDateTime(date)}.json`;
64
+ }
65
+ export function formatUiGraphDownloadDateTime(date) {
66
+ const pad = (value) => `${value}`.padStart(2, '0');
67
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}-${pad(date.getMinutes())}-${pad(date.getSeconds())}`;
68
+ }
69
+ export function applyUiGraphStatePatch(state, statePatch) {
70
+ return statePatch ? { ...state, ...statePatch } : state;
71
+ }
@@ -123,7 +123,7 @@ function buildTextArgs(options) {
123
123
  const args = {
124
124
  model: options.model,
125
125
  messages: options.messages,
126
- maxRetries: 0,
126
+ maxRetries: options.maxRetries ?? 0,
127
127
  };
128
128
  if (options.tools !== undefined)
129
129
  args.tools = options.tools;
@@ -61,8 +61,8 @@ function fingerprintNodeDataForCache(data) {
61
61
  const isCustomProvider = data.provider === 'custom';
62
62
  return {
63
63
  ...data,
64
- baseURL: isCustomProvider ? '' : data.baseURL,
65
- useBaseURLInput: isCustomProvider ? false : data.useBaseURLInput,
64
+ baseURL: '',
65
+ useBaseURLInput: false,
66
66
  customProviderBaseURL: isCustomProvider ? data.customProviderBaseURL : '',
67
67
  useCustomProviderBaseURLInput: isCustomProvider ? data.useCustomProviderBaseURLInput : false,
68
68
  extraProviderOptions: data.useExtraProviderOptionsInput ? '' : fingerprintSecret(data.extraProviderOptions) ?? '',