@valerypopoff/rivet2-core 2.12.0 → 2.15.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.
Files changed (69) hide show
  1. package/dist/cjs/bundle.cjs +3188 -592
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +5 -0
  4. package/dist/esm/api/processSettings.js +1 -0
  5. package/dist/esm/exports.js +5 -0
  6. package/dist/esm/model/GraphInputStream.js +70 -0
  7. package/dist/esm/model/GraphProcessor.js +264 -29
  8. package/dist/esm/model/MarkdownSanitizationPolicy.js +2 -0
  9. package/dist/esm/model/NodeExecutionPlanner.js +4 -4
  10. package/dist/esm/model/NodeImpl.js +1 -1
  11. package/dist/esm/model/Nodes.js +9 -0
  12. package/dist/esm/model/ProcessContextBuilder.js +2 -1
  13. package/dist/esm/model/StreamingOutputWatch.js +5 -0
  14. package/dist/esm/model/StreamingWatchTopology.js +228 -0
  15. package/dist/esm/model/classifier/credentials.js +81 -0
  16. package/dist/esm/model/classifier/migration.js +97 -0
  17. package/dist/esm/model/classifier/providers.js +347 -0
  18. package/dist/esm/model/classifier/questionHelpers.js +125 -0
  19. package/dist/esm/model/classifier/types.js +1 -0
  20. package/dist/esm/model/nodeBodyMarkdown.js +37 -0
  21. package/dist/esm/model/nodes/AssembleMessageNode.js +2 -2
  22. package/dist/esm/model/nodes/AssemblePromptNode.js +46 -17
  23. package/dist/esm/model/nodes/ClassifierEvaluateNode.js +392 -0
  24. package/dist/esm/model/nodes/ClassifierQuestionNode.js +569 -0
  25. package/dist/esm/model/nodes/CodeNewNode.js +33 -9
  26. package/dist/esm/model/nodes/GraphInputNode.js +15 -19
  27. package/dist/esm/model/nodes/LLMChatV2Node.js +3 -12
  28. package/dist/esm/model/nodes/LLMProfileNode.js +6 -12
  29. package/dist/esm/model/nodes/MatchCaseNode.js +78 -3
  30. package/dist/esm/model/nodes/MatchCaseNodeBase.js +24 -2
  31. package/dist/esm/model/nodes/ObjectNode.js +48 -41
  32. package/dist/esm/model/nodes/PassthroughNode.js +1 -1
  33. package/dist/esm/model/nodes/ProjectNameNode.js +37 -0
  34. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +1 -0
  35. package/dist/esm/model/nodes/SubGraphNode.js +1 -0
  36. package/dist/esm/model/nodes/codeOutputInference.js +292 -0
  37. package/dist/esm/model/nodes/variadicPortIndex.js +1 -1
  38. package/dist/esm/utils/serialization/serialization.js +4 -0
  39. package/dist/types/exports.d.ts +6 -0
  40. package/dist/types/model/EditorDefinition.d.ts +24 -0
  41. package/dist/types/model/GraphInputStream.d.ts +23 -0
  42. package/dist/types/model/GraphProcessor.d.ts +3 -0
  43. package/dist/types/model/MarkdownSanitizationPolicy.d.ts +1 -1
  44. package/dist/types/model/NodeExecutionPlanner.d.ts +1 -1
  45. package/dist/types/model/NodeImpl.d.ts +3 -1
  46. package/dist/types/model/Nodes.d.ts +7 -4
  47. package/dist/types/model/ProcessContext.d.ts +3 -0
  48. package/dist/types/model/ProcessContextBuilder.d.ts +2 -1
  49. package/dist/types/model/Settings.d.ts +4 -0
  50. package/dist/types/model/StreamingOutputWatch.d.ts +2 -0
  51. package/dist/types/model/StreamingWatchTopology.d.ts +26 -0
  52. package/dist/types/model/classifier/credentials.d.ts +24 -0
  53. package/dist/types/model/classifier/migration.d.ts +18 -0
  54. package/dist/types/model/classifier/providers.d.ts +78 -0
  55. package/dist/types/model/classifier/questionHelpers.d.ts +31 -0
  56. package/dist/types/model/classifier/types.d.ts +58 -0
  57. package/dist/types/model/nodeBodyMarkdown.d.ts +19 -0
  58. package/dist/types/model/nodes/AssemblePromptNode.d.ts +4 -3
  59. package/dist/types/model/nodes/ClassifierEvaluateNode.d.ts +47 -0
  60. package/dist/types/model/nodes/ClassifierQuestionNode.d.ts +60 -0
  61. package/dist/types/model/nodes/CodeNewNode.d.ts +6 -0
  62. package/dist/types/model/nodes/GraphInputNode.d.ts +2 -0
  63. package/dist/types/model/nodes/MatchCaseNode.d.ts +9 -2
  64. package/dist/types/model/nodes/MatchCaseNodeBase.d.ts +13 -1
  65. package/dist/types/model/nodes/ObjectNode.d.ts +5 -0
  66. package/dist/types/model/nodes/ProjectNameNode.d.ts +12 -0
  67. package/dist/types/model/nodes/codeOutputInference.d.ts +31 -0
  68. package/dist/types/model/nodes/variadicPortIndex.d.ts +1 -0
  69. package/package.json +1 -1
@@ -57,6 +57,11 @@ export class StreamingOutputWatch {
57
57
  this.#run = run;
58
58
  this.#onFailure = onFailure;
59
59
  }
60
+ /** Updates superseded before the receiving graph could start. */
61
+ accountCoalescedUpdates(count) {
62
+ this.#receivedUpdates += count;
63
+ this.#coalescedUpdates += count;
64
+ }
60
65
  get hasPending() {
61
66
  // Stop prevents new delivery, but accepted and failing invocations still
62
67
  // belong to the root lifecycle until they settle. Hiding those active runs
@@ -0,0 +1,228 @@
1
+ import { canRenderDataBusNode, getDataBusInputChannelIndex, getDataBusOutputChannelIndex } from './DataBusTopology.js';
2
+ import { resolveNodePrefabInstance } from './NodePrefabResolver.js';
3
+ import { createGraphOutputSelection } from './GraphOutputSelection.js';
4
+ /** An executing caller may forward outputs after its condition has passed. */
5
+ export function canForwardGraphCallerOutputPartials(node) {
6
+ return ((node.type === 'subGraph' || node.type === 'referencedGraphAlias') &&
7
+ !node.disabled &&
8
+ !node.isSplitRun &&
9
+ !node.data.useErrorOutput);
10
+ }
11
+ /** Early input delivery must not bypass the caller's ordinary readiness/condition gate. */
12
+ export function canStreamThroughGraphCaller(node) {
13
+ return canForwardGraphCallerOutputPartials(node) && !node.isConditional;
14
+ }
15
+ export function canStreamThroughGraphInput(node) {
16
+ return (node.type === 'graphInput' &&
17
+ !node.disabled &&
18
+ !node.isConditional &&
19
+ !node.isSplitRun &&
20
+ !node.data.useDefaultValueInput);
21
+ }
22
+ /** A named output may forward only when one direct producer determines its terminal value. */
23
+ export function canForwardGraphOutputPartials(graphOutput, sourceNode, graphOutputIsFrozen) {
24
+ return (graphOutput.type === 'graphOutput' &&
25
+ !graphOutput.disabled &&
26
+ !graphOutput.isConditional &&
27
+ !graphOutput.isSplitRun &&
28
+ !sourceNode.isSplitRun &&
29
+ !graphOutputIsFrozen);
30
+ }
31
+ /** Trace Watch demand through named boundaries without making ordinary nodes repeatable. */
32
+ export function getProjectStreamingOutputWatchConnections({ project, graph, referencedProjects, registry, frozenNodeOutputs = {}, isNodeFrozen, fullGraphCallers, }) {
33
+ // Unsaved active graph edits must take precedence over the stored project graph.
34
+ const currentProject = {
35
+ ...project,
36
+ graphs: { ...project.graphs, ...(graph.metadata?.id ? { [graph.metadata.id]: graph } : {}) },
37
+ };
38
+ const projects = { ...referencedProjects, [project.metadata.id]: currentProject };
39
+ const contexts = new Map();
40
+ const isFrozen = (owner, candidate, node) => isNodeFrozen?.(owner, candidate, node) ??
41
+ (owner === currentProject &&
42
+ !!(candidate.metadata?.id && frozenNodeOutputs[candidate.metadata.id]?.[node.id]?.length));
43
+ for (const owner of Object.values(projects)) {
44
+ for (const candidate of Object.values(owner.graphs)) {
45
+ const nodes = Object.fromEntries(candidate.nodes.map((node) => [node.id, resolveNodePrefabInstance(owner, node)]));
46
+ const connectionsByNode = new Map();
47
+ for (const edge of candidate.connections) {
48
+ for (const id of new Set([edge.inputNodeId, edge.outputNodeId])) {
49
+ const edges = connectionsByNode.get(id) ?? [];
50
+ edges.push(edge);
51
+ connectionsByNode.set(id, edges);
52
+ }
53
+ }
54
+ const ports = new Map();
55
+ const getPorts = (nodeId) => {
56
+ const cached = ports.get(nodeId);
57
+ if (cached)
58
+ return cached;
59
+ const node = nodes[nodeId];
60
+ let definitions = { inputs: new Set(), outputs: new Set() };
61
+ try {
62
+ if (!node)
63
+ return definitions;
64
+ const impl = registry.createDynamicImpl(node);
65
+ const connections = connectionsByNode.get(node.id) ?? [];
66
+ definitions = {
67
+ inputs: new Set(impl.getInputDefinitionsIncludingBuiltIn(connections, nodes, owner, projects).map((port) => port.id)),
68
+ outputs: new Set(impl.getOutputDefinitions(connections, nodes, owner, projects).map((port) => port.id)),
69
+ };
70
+ }
71
+ catch {
72
+ // Missing plugins or incomplete definitions cannot establish a stream route.
73
+ }
74
+ ports.set(nodeId, definitions);
75
+ return definitions;
76
+ };
77
+ // Resolve definitions only on visited routes, including failed plugin lookups.
78
+ const incomingByNode = new Map();
79
+ const incoming = (nodeId) => {
80
+ let edges = incomingByNode.get(nodeId);
81
+ if (!edges) {
82
+ edges = (connectionsByNode.get(nodeId) ?? []).filter((edge) => edge.inputNodeId === nodeId &&
83
+ getPorts(nodeId).inputs.has(edge.inputId) &&
84
+ getPorts(edge.outputNodeId).outputs.has(edge.outputId));
85
+ incomingByNode.set(nodeId, edges);
86
+ }
87
+ return edges;
88
+ };
89
+ contexts.set(candidate, { project: owner, nodes, incoming, marked: new Set() });
90
+ }
91
+ }
92
+ // Index callers by the actual target graph, not graph/node IDs (which are local).
93
+ const callers = new Map();
94
+ for (const [parent, context] of contexts) {
95
+ for (const node of Object.values(context.nodes)) {
96
+ if (node.disabled || isFrozen(context.project, parent, node) || !canStreamThroughGraphCaller(node))
97
+ continue;
98
+ const caller = node;
99
+ const owner = caller.type === 'subGraph' ? context.project : projects[caller.data.projectId];
100
+ const child = owner?.graphs[caller.data.graphId];
101
+ if (!child)
102
+ continue;
103
+ let selected;
104
+ if (caller.type === 'subGraph' &&
105
+ caller.data.skipUnusedOutputs &&
106
+ !caller.data.useAsGraphPartialOutput &&
107
+ !(parent === graph && fullGraphCallers?.has(caller.id))) {
108
+ const childContext = contexts.get(child);
109
+ const outputNames = new Set(Object.values(childContext.nodes)
110
+ .filter((node) => node.type === 'graphOutput')
111
+ .map((node) => node.data.id));
112
+ const outputs = parent.connections
113
+ .filter((edge) => edge.outputNodeId === caller.id)
114
+ .map((edge) => edge.outputId)
115
+ .filter((id) => outputNames.has(id));
116
+ try {
117
+ selected = createGraphOutputSelection({ ...child, nodes: Object.values(childContext.nodes) }, outputs, (node) => childContext.incoming(node.id).map((edge) => childContext.nodes[edge.outputNodeId])).nodeIds;
118
+ }
119
+ catch {
120
+ continue;
121
+ }
122
+ }
123
+ const entries = callers.get(child) ?? [];
124
+ entries.push({ graph: parent, node, selected });
125
+ callers.set(child, entries);
126
+ }
127
+ }
128
+ const watchInputs = [];
129
+ for (const [candidate, context] of contexts) {
130
+ for (const node of Object.values(context.nodes)) {
131
+ if (node.type !== 'watchStreamingOutput' || node.disabled || isFrozen(context.project, candidate, node))
132
+ continue;
133
+ const inputs = context.incoming(node.id).filter((edge) => edge.inputId === 'stream');
134
+ // Multiple providers are rejected by the Watch scheduler, not multiple streams.
135
+ if (inputs.length === 1)
136
+ watchInputs.push({ graph: candidate, edge: inputs[0] });
137
+ }
138
+ }
139
+ const visiting = new Map();
140
+ const trace = (candidate, edge) => {
141
+ const context = contexts.get(candidate);
142
+ if (context.marked.has(edge))
143
+ return true;
144
+ const graphVisiting = visiting.get(candidate) ?? new Set();
145
+ if (graphVisiting.has(edge))
146
+ return false;
147
+ graphVisiting.add(edge);
148
+ visiting.set(candidate, graphVisiting);
149
+ try {
150
+ const source = context.nodes[edge.outputNodeId];
151
+ if (!source || source.disabled || source.isSplitRun || isFrozen(context.project, candidate, source))
152
+ return false;
153
+ if (canRenderDataBusNode(source)) {
154
+ const channel = getDataBusOutputChannelIndex(edge.outputId);
155
+ if (channel == null)
156
+ return false;
157
+ const providers = context
158
+ .incoming(source.id)
159
+ .filter((input) => getDataBusInputChannelIndex(input.inputId) === channel);
160
+ if (providers.length !== 1 || !trace(candidate, providers[0]))
161
+ return false;
162
+ context.marked.add(edge);
163
+ return true;
164
+ }
165
+ if (source.type === 'graphInput' && edge.outputId === 'data') {
166
+ if (!canStreamThroughGraphInput(source))
167
+ return false;
168
+ const inputName = source.data.id;
169
+ let foundSource = false;
170
+ for (const parent of callers.get(candidate) ?? []) {
171
+ if (parent.selected && !parent.selected.has(edge.inputNodeId))
172
+ continue;
173
+ const inputs = contexts
174
+ .get(parent.graph)
175
+ .incoming(parent.node.id)
176
+ .filter((input) => input.inputId === inputName);
177
+ // Ambiguous authored inputs stay final-only even though ordinary
178
+ // execution retains its established first-provider projection.
179
+ if (inputs.length === 1 && trace(parent.graph, inputs[0]))
180
+ foundSource = true;
181
+ }
182
+ if (!foundSource)
183
+ return false;
184
+ context.marked.add(edge);
185
+ return true;
186
+ }
187
+ if (source.type !== 'subGraph' && source.type !== 'referencedGraphAlias') {
188
+ context.marked.add(edge);
189
+ return true;
190
+ }
191
+ if (!canForwardGraphCallerOutputPartials(source))
192
+ return false;
193
+ const caller = source;
194
+ const childProject = caller.type === 'subGraph' ? context.project : projects[caller.data.projectId];
195
+ const child = childProject?.graphs[caller.data.graphId];
196
+ const childContext = child && contexts.get(child);
197
+ if (!child || !childContext)
198
+ return false;
199
+ const outputs = Object.values(childContext.nodes).filter((node) => node.type === 'graphOutput' && !node.disabled && node.data.id === edge.outputId);
200
+ // Duplicate names have first-final-winner semantics, so cannot relay partials.
201
+ if (outputs.length !== 1)
202
+ return false;
203
+ const output = outputs[0];
204
+ const outputIsFrozen = isFrozen(childProject, child, output);
205
+ const providers = childContext.incoming(output.id).filter((input) => input.inputId === 'value');
206
+ // As in GraphProcessor's effective connection projection, the first
207
+ // valid provider owns a single-input Graph Output in a malformed graph.
208
+ // Never mark a shadowed provider that cannot determine the final value.
209
+ const provider = providers[0];
210
+ const providerNode = provider && childContext.nodes[provider.outputNodeId];
211
+ if (!provider ||
212
+ !providerNode ||
213
+ !canForwardGraphOutputPartials(output, providerNode, outputIsFrozen) ||
214
+ !trace(child, provider))
215
+ return false;
216
+ context.marked.add(edge);
217
+ return true;
218
+ }
219
+ finally {
220
+ graphVisiting.delete(edge);
221
+ if (graphVisiting.size === 0)
222
+ visiting.delete(candidate);
223
+ }
224
+ };
225
+ for (const { graph: candidate, edge } of watchInputs)
226
+ trace(candidate, edge);
227
+ return contexts.get(graph)?.marked ?? new Set();
228
+ }
@@ -0,0 +1,81 @@
1
+ import { coerceTypeOptional } from '../../utils/coerceType.js';
2
+ export const JEV_DEFAULT_CREDENTIAL_NAMES = {
3
+ programmaticName: 'typesafeApiKey',
4
+ environmentVariableName: 'TYPESAFE_API_KEY',
5
+ };
6
+ const programmaticNamePattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
7
+ const environmentVariableNamePattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
8
+ export function isValidClassifierProgrammaticCredentialName(name) {
9
+ return programmaticNamePattern.test(name);
10
+ }
11
+ export function isValidClassifierEnvironmentCredentialName(name) {
12
+ return environmentVariableNamePattern.test(name);
13
+ }
14
+ export function normalizeClassifierCredentialNames(value, defaults = JEV_DEFAULT_CREDENTIAL_NAMES) {
15
+ if (value != null && (typeof value !== 'object' || Array.isArray(value))) {
16
+ throw new Error('Classifier API key names must be an object.');
17
+ }
18
+ const raw = value;
19
+ if (raw?.programmaticName != null && typeof raw.programmaticName !== 'string') {
20
+ throw new Error('Classifier programmatic API key name must be a string.');
21
+ }
22
+ if (raw?.environmentVariableName != null && typeof raw.environmentVariableName !== 'string') {
23
+ throw new Error('Classifier API key environment variable must be a string.');
24
+ }
25
+ const programmaticName = raw?.programmaticName?.trim() || defaults.programmaticName;
26
+ const environmentVariableName = raw?.environmentVariableName?.trim() || defaults.environmentVariableName;
27
+ if (!isValidClassifierProgrammaticCredentialName(programmaticName)) {
28
+ throw new Error('Classifier programmatic API key name must be a JavaScript-style identifier without a leading digit.');
29
+ }
30
+ if (!isValidClassifierEnvironmentCredentialName(environmentVariableName)) {
31
+ throw new Error('Classifier API key environment variable must contain letters, digits, and _ without a leading digit.');
32
+ }
33
+ return { programmaticName, environmentVariableName };
34
+ }
35
+ export function getClassifierCredentialNamesForDisplay(value, defaults = JEV_DEFAULT_CREDENTIAL_NAMES) {
36
+ try {
37
+ return normalizeClassifierCredentialNames(value, defaults);
38
+ }
39
+ catch {
40
+ return { ...defaults };
41
+ }
42
+ }
43
+ export function isDefaultClassifierCredentialNames(names, defaults = JEV_DEFAULT_CREDENTIAL_NAMES) {
44
+ return names.programmaticName === defaults.programmaticName && names.environmentVariableName === defaults.environmentVariableName;
45
+ }
46
+ export function resolveClassifierApiKey({ apiKeyNames, apiKeySource, context, defaults, inputs, providerId, }) {
47
+ if (apiKeySource === 'input') {
48
+ const value = coerceTypeOptional(inputs['apiKey'], 'string')?.trim();
49
+ if (!value)
50
+ throw new Error('API Key input is required when API key source is Input port.');
51
+ return value;
52
+ }
53
+ const names = normalizeClassifierCredentialNames(apiKeyNames, defaults);
54
+ const namedValue = resolveNamedClassifierApiKey(context, names);
55
+ if (namedValue)
56
+ return namedValue;
57
+ if (isDefaultClassifierCredentialNames(names, defaults)) {
58
+ const firstPartyValue = getNonEmptyString(context.settings.classifierProviders?.[providerId]?.apiKey);
59
+ if (firstPartyValue)
60
+ return firstPartyValue;
61
+ // Compatibility only: old applications stored the key under the removed plugin.
62
+ if (providerId === 'jev') {
63
+ const legacyValue = getNonEmptyString(context.settings.pluginSettings?.typesafe?.typesafeApiKey);
64
+ if (legacyValue)
65
+ return legacyValue;
66
+ }
67
+ }
68
+ throw new Error(`${providerId === 'jev' ? 'Jev' : 'Classifier'} API key is not set. Pass ${names.programmaticName}, configure ${names.environmentVariableName}, or set the configured key in Settings > Classifier.`);
69
+ }
70
+ function resolveNamedClassifierApiKey(context, names) {
71
+ const programmaticValue = getNonEmptyString(context.settings?.[names.programmaticName]);
72
+ if (programmaticValue)
73
+ return programmaticValue;
74
+ const environmentValue = getNonEmptyString(context.settings?.pluginEnv?.[names.environmentVariableName]);
75
+ if (environmentValue)
76
+ return environmentValue;
77
+ return getNonEmptyString(globalThis.process?.env?.[names.environmentVariableName]);
78
+ }
79
+ function getNonEmptyString(value) {
80
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
81
+ }
@@ -0,0 +1,97 @@
1
+ const legacyTypesafePluginId = 'typesafe';
2
+ function isLegacyTypesafePlugin(spec) {
3
+ return spec.type === 'built-in' && spec.id === legacyTypesafePluginId;
4
+ }
5
+ /**
6
+ * Converts the former TypeSafe plugin node family into the first-party
7
+ * classifier contract. It is intentionally idempotent because project data
8
+ * reaches Core through imports, hosted snapshots, recordings, and copies.
9
+ */
10
+ export function normalizeClassifierProject(project) {
11
+ for (const graph of Object.values(project.graphs))
12
+ normalizeClassifierGraph(graph);
13
+ for (const prefab of Object.values(project.nodePrefabs ?? {}))
14
+ normalizeClassifierNode(prefab.sourceNode);
15
+ if (project.plugins?.some(isLegacyTypesafePlugin)) {
16
+ project.plugins = project.plugins.filter((plugin) => !isLegacyTypesafePlugin(plugin));
17
+ }
18
+ }
19
+ /**
20
+ * Checks whether a project still needs the in-place legacy migration. Hosts
21
+ * which receive a caller-owned project object use this before cloning, so a
22
+ * compatibility repair never mutates the caller's snapshot.
23
+ */
24
+ export function hasLegacyClassifierProjectData(project) {
25
+ return (project.plugins?.some(isLegacyTypesafePlugin) === true ||
26
+ Object.values(project.graphs).some(hasLegacyClassifierGraphData) ||
27
+ Object.values(project.nodePrefabs ?? {}).some((prefab) => hasLegacyClassifierNodeData(prefab.sourceNode)));
28
+ }
29
+ export function normalizeClassifierGraph(graph) {
30
+ for (const node of graph.nodes)
31
+ normalizeClassifierNode(node);
32
+ }
33
+ export function hasLegacyClassifierGraphData(graph) {
34
+ return graph.nodes.some(hasLegacyClassifierNodeData);
35
+ }
36
+ export function normalizeClassifierNode(node) {
37
+ const legacyNode = node;
38
+ switch (legacyNode.type) {
39
+ case 'jevChoiceQuestion':
40
+ normalizeQuestionNode(legacyNode, 'choice', 'Jev Choice Question');
41
+ return;
42
+ case 'jevScoreQuestion':
43
+ normalizeQuestionNode(legacyNode, 'score', 'Jev Score Question');
44
+ return;
45
+ case 'jevNoulQuestion':
46
+ normalizeQuestionNode(legacyNode, 'noul', 'Jev Noul Question');
47
+ return;
48
+ case 'jevEvaluate':
49
+ normalizeEvaluateNode(legacyNode);
50
+ return;
51
+ case 'classifierEvaluate':
52
+ if (hasDeprecatedGlobalCredentialNames(legacyNode))
53
+ normalizeEvaluateNode(legacyNode);
54
+ return;
55
+ default:
56
+ return;
57
+ }
58
+ }
59
+ function hasLegacyClassifierNodeData(node) {
60
+ return (node.type === 'jevChoiceQuestion' ||
61
+ node.type === 'jevScoreQuestion' ||
62
+ node.type === 'jevNoulQuestion' ||
63
+ node.type === 'jevEvaluate' ||
64
+ (node.type === 'classifierEvaluate' && hasDeprecatedGlobalCredentialNames(node)));
65
+ }
66
+ function hasDeprecatedGlobalCredentialNames(node) {
67
+ return Object.prototype.hasOwnProperty.call(asRecord(node.data), 'apiKeyNames');
68
+ }
69
+ function normalizeQuestionNode(node, questionType, legacyTitle) {
70
+ node.type = 'classifierQuestion';
71
+ node.data = {
72
+ ...asRecord(node.data),
73
+ questionType,
74
+ };
75
+ if (node.title === legacyTitle)
76
+ node.title = 'Classifier Question';
77
+ }
78
+ function normalizeEvaluateNode(node) {
79
+ const legacyData = asRecord(node.data);
80
+ const legacyApiKeyNames = legacyData.apiKeyNames;
81
+ const existingNames = asRecord(legacyData.apiKeyNamesByProvider);
82
+ const apiKeyNamesByProvider = legacyApiKeyNames === undefined || Object.prototype.hasOwnProperty.call(existingNames, 'jev')
83
+ ? existingNames
84
+ : { ...existingNames, jev: legacyApiKeyNames };
85
+ const { apiKeyNames: _legacyApiKeyNames, ...dataWithoutLegacyNames } = legacyData;
86
+ node.type = 'classifierEvaluate';
87
+ node.data = {
88
+ ...dataWithoutLegacyNames,
89
+ provider: typeof legacyData.provider === 'string' && legacyData.provider ? legacyData.provider : 'jev',
90
+ ...(Object.keys(apiKeyNamesByProvider).length > 0 ? { apiKeyNamesByProvider } : {}),
91
+ };
92
+ if (node.title === 'Jev Evaluate')
93
+ node.title = 'Classifier Evaluate';
94
+ }
95
+ function asRecord(value) {
96
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
97
+ }