@valerypopoff/rivet2-core 2.0.10 → 2.1.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 (68) hide show
  1. package/dist/cjs/bundle.cjs +1762 -274
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +1 -0
  4. package/dist/esm/exports.js +4 -0
  5. package/dist/esm/model/GraphBoundaryCache.js +36 -4
  6. package/dist/esm/model/GraphBoundaryEffects.js +32 -0
  7. package/dist/esm/model/GraphPreprocessor.js +6 -4
  8. package/dist/esm/model/GraphProcessor.js +344 -118
  9. package/dist/esm/model/NodeGraph.js +1 -1
  10. package/dist/esm/model/NodePrefabResolver.js +57 -0
  11. package/dist/esm/model/Nodes.js +4 -1
  12. package/dist/esm/model/ProcessContextBuilder.js +3 -1
  13. package/dist/esm/model/UiGraph.js +113 -0
  14. package/dist/esm/model/UiGraphRendererStyles.js +208 -0
  15. package/dist/esm/model/chat/openAIChatRuntime.js +0 -1
  16. package/dist/esm/model/chat-v2/aiSdkBridge.js +100 -2
  17. package/dist/esm/model/chat-v2/chatV2Pipeline.js +35 -31
  18. package/dist/esm/model/chat-v2/chatV2Shared.js +1 -1
  19. package/dist/esm/model/chat-v2/providerOptions.js +5 -1
  20. package/dist/esm/model/nodes/CoalesceNode.js +1 -1
  21. package/dist/esm/model/nodes/CompareNode.js +15 -14
  22. package/dist/esm/model/nodes/GraphOutputNode.js +1 -0
  23. package/dist/esm/model/nodes/LLMChatV2Node.js +62 -17
  24. package/dist/esm/model/nodes/NodePrefabInstanceNode.js +39 -0
  25. package/dist/esm/model/nodes/PromptNode.js +2 -1
  26. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +49 -7
  27. package/dist/esm/model/nodes/SubGraphNode.js +42 -5
  28. package/dist/esm/utils/index.js +2 -0
  29. package/dist/esm/utils/jsonValueToDataValue.js +48 -0
  30. package/dist/esm/utils/projectComparison/connections.js +57 -0
  31. package/dist/esm/utils/projectComparison/graphs.js +60 -0
  32. package/dist/esm/utils/projectComparison/nodes.js +53 -0
  33. package/dist/esm/utils/projectComparison/summaries.js +60 -0
  34. package/dist/esm/utils/projectComparison/values.js +40 -0
  35. package/dist/esm/utils/projectComparison.js +73 -0
  36. package/dist/esm/utils/serialization/serializationHelpers.js +24 -3
  37. package/dist/esm/utils/serialization/serialization_v4.js +30 -0
  38. package/dist/types/api/createProcessor.d.ts +2 -1
  39. package/dist/types/exports.d.ts +5 -0
  40. package/dist/types/model/EditorDefinition.d.ts +1 -0
  41. package/dist/types/model/ExecutorProtocol.d.ts +13 -3
  42. package/dist/types/model/GraphBoundaryCache.d.ts +9 -3
  43. package/dist/types/model/GraphBoundaryEffects.d.ts +9 -0
  44. package/dist/types/model/GraphProcessor.d.ts +20 -0
  45. package/dist/types/model/NodeBase.d.ts +5 -0
  46. package/dist/types/model/NodeBodySpec.d.ts +1 -0
  47. package/dist/types/model/NodePrefabResolver.d.ts +13 -0
  48. package/dist/types/model/Nodes.d.ts +5 -4
  49. package/dist/types/model/ProcessContext.d.ts +5 -1
  50. package/dist/types/model/ProcessContextBuilder.d.ts +4 -2
  51. package/dist/types/model/Project.d.ts +9 -0
  52. package/dist/types/model/UiGraph.d.ts +84 -0
  53. package/dist/types/model/UiGraphRendererStyles.d.ts +2 -0
  54. package/dist/types/model/chat-v2/aiSdkBridge.d.ts +1 -0
  55. package/dist/types/model/chat-v2/chatV2Types.d.ts +23 -1
  56. package/dist/types/model/nodes/CompareNode.d.ts +4 -0
  57. package/dist/types/model/nodes/LLMChatV2Node.d.ts +2 -1
  58. package/dist/types/model/nodes/NodePrefabInstanceNode.d.ts +13 -0
  59. package/dist/types/model/nodes/SubGraphNode.d.ts +2 -0
  60. package/dist/types/utils/index.d.ts +2 -0
  61. package/dist/types/utils/jsonValueToDataValue.d.ts +2 -0
  62. package/dist/types/utils/projectComparison/connections.d.ts +5 -0
  63. package/dist/types/utils/projectComparison/graphs.d.ts +3 -0
  64. package/dist/types/utils/projectComparison/nodes.d.ts +5 -0
  65. package/dist/types/utils/projectComparison/summaries.d.ts +4 -0
  66. package/dist/types/utils/projectComparison/values.d.ts +5 -0
  67. package/dist/types/utils/projectComparison.d.ts +77 -0
  68. package/package.json +1 -1
@@ -1,11 +1,11 @@
1
1
  import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
2
- import { streamChatV2 } from './aiSdkBridge.js';
2
+ import { generateChatV2, streamChatV2 } from './aiSdkBridge.js';
3
3
  import { chatMessagesToModelMessages } from './messageConverter.js';
4
4
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
5
5
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
6
6
  import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
7
7
  import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
8
- class StreamChatV2RetryFailure extends Error {
8
+ class ChatV2RetryFailure extends Error {
9
9
  error;
10
10
  requestStatuses;
11
11
  requestErrors;
@@ -14,11 +14,11 @@ class StreamChatV2RetryFailure extends Error {
14
14
  this.error = error;
15
15
  this.requestStatuses = requestStatuses;
16
16
  this.requestErrors = requestErrors;
17
- this.name = 'StreamChatV2RetryFailure';
17
+ this.name = 'ChatV2RetryFailure';
18
18
  }
19
19
  }
20
- function isStreamChatV2RetryFailure(error) {
21
- return error instanceof StreamChatV2RetryFailure;
20
+ function isChatV2RetryFailure(error) {
21
+ return error instanceof ChatV2RetryFailure;
22
22
  }
23
23
  function getProviderFailureMessage(error) {
24
24
  if (error instanceof Error) {
@@ -41,7 +41,7 @@ function normalizeProviderFailureMessage(error, options) {
41
41
  function normalizeProviderFailureMessages(errors, options) {
42
42
  return errors.map((error) => normalizeProviderFailureMessage(error, options));
43
43
  }
44
- async function streamChatV2WithRetry(streamOptions, retryOptions) {
44
+ async function runChatV2WithRetry(chatOptions, retryOptions, transportMode) {
45
45
  const repeatTimes = retryOptions.retryOnNon200
46
46
  ? normalizeLLMChatV2RetryCount(retryOptions.retryOnNon200RepeatTimes)
47
47
  : 0;
@@ -50,7 +50,7 @@ async function streamChatV2WithRetry(streamOptions, retryOptions) {
50
50
  const requestErrors = [];
51
51
  for (let attempt = 0;; attempt++) {
52
52
  try {
53
- const result = await streamChatV2(streamOptions);
53
+ const result = transportMode === 'generate' ? await generateChatV2(chatOptions) : await streamChatV2(chatOptions);
54
54
  const statusCode = result.requestStatus ?? 200;
55
55
  if (retryOptions.retryOnNon200) {
56
56
  requestStatuses.push(statusCode);
@@ -73,7 +73,7 @@ async function streamChatV2WithRetry(streamOptions, retryOptions) {
73
73
  requestStatuses.push(statusCode);
74
74
  requestErrors.push(error);
75
75
  if (attempt >= repeatTimes) {
76
- throw new StreamChatV2RetryFailure(error, requestStatuses, requestErrors);
76
+ throw new ChatV2RetryFailure(error, requestStatuses, requestErrors);
77
77
  }
78
78
  await waitForLLMChatV2RetryCooldown(cooldownMs, retryOptions.context.signal);
79
79
  }
@@ -137,7 +137,9 @@ export async function runChatV2Pipeline(options) {
137
137
  : options.additionalTools == null
138
138
  ? functionTools
139
139
  : { ...functionTools, ...options.additionalTools };
140
- const streamed = await streamChatV2WithRetry({
140
+ const shouldStreamResponse = options.emitPartialOutputs !== false;
141
+ const transportMode = shouldStreamResponse ? 'stream' : 'generate';
142
+ const chatResponse = await runChatV2WithRetry({
141
143
  model: options.model,
142
144
  messages: modelMessages,
143
145
  tools,
@@ -155,7 +157,8 @@ export async function runChatV2Pipeline(options) {
155
157
  toolChoice: options.toolChoice,
156
158
  abortSignal: options.context.signal,
157
159
  executeStream: options.executeStream,
158
- onPartialOutput: options.emitPartialOutputs === false
160
+ executeGenerate: options.executeGenerate,
161
+ onPartialOutput: !shouldStreamResponse
159
162
  ? undefined
160
163
  : ({ text, functionCalls }) => {
161
164
  options.context.onPartialOutputs?.(createChatV2CommonOutputs({
@@ -178,8 +181,8 @@ export async function runChatV2Pipeline(options) {
178
181
  responseFormat: undefined,
179
182
  }));
180
183
  },
181
- }, options).catch((caughtError) => {
182
- const retryFailure = isStreamChatV2RetryFailure(caughtError) ? caughtError : undefined;
184
+ }, options, transportMode).catch((caughtError) => {
185
+ const retryFailure = isChatV2RetryFailure(caughtError) ? caughtError : undefined;
183
186
  const rawError = retryFailure?.error ?? caughtError;
184
187
  const normalizedError = normalizeChatV2ProviderError(rawError, {
185
188
  provider: options.provider,
@@ -193,23 +196,24 @@ export async function runChatV2Pipeline(options) {
193
196
  }
194
197
  throw normalizedError;
195
198
  });
196
- if ('commonOutputs' in streamed) {
197
- return streamed;
199
+ if ('commonOutputs' in chatResponse) {
200
+ return chatResponse;
198
201
  }
199
- const usage = normalizeChatV2Usage(streamed.result.usage, options);
200
- const requestStatuses = streamed.requestStatuses;
201
- const requestErrors = normalizeProviderFailureMessages(streamed.requestErrors, options);
202
- const responseError = streamed.responseError
203
- ? normalizeProviderFailureMessage(streamed.responseError, options)
202
+ const usage = normalizeChatV2Usage(chatResponse.result.usage, options);
203
+ const requestStatuses = chatResponse.requestStatuses;
204
+ const requestStatus = chatResponse.result.requestStatus ?? 200;
205
+ const requestErrors = normalizeProviderFailureMessages(chatResponse.requestErrors, options);
206
+ const responseError = chatResponse.responseError
207
+ ? normalizeProviderFailureMessage(chatResponse.responseError, options)
204
208
  : undefined;
205
209
  const commonOutputs = createChatV2CommonOutputs({
206
210
  requestMessages,
207
- response: streamed.result.responseText,
208
- structuredOutput: streamed.result.structuredOutput,
209
- functionCalls: streamed.result.functionCalls,
211
+ response: chatResponse.result.responseText,
212
+ structuredOutput: chatResponse.result.structuredOutput,
213
+ functionCalls: chatResponse.result.functionCalls,
210
214
  usage,
211
- reasoning: streamed.result.reasoning,
212
- requestStatus: streamed.result.requestStatus,
215
+ reasoning: chatResponse.result.reasoning,
216
+ requestStatus,
213
217
  responseError,
214
218
  requestStatuses,
215
219
  requestErrors,
@@ -229,13 +233,13 @@ export async function runChatV2Pipeline(options) {
229
233
  commonOutputs,
230
234
  requestMessages,
231
235
  allMessages: allMessagesOutput.value,
232
- response: streamed.result.responseText,
233
- functionCalls: streamed.result.functionCalls,
234
- reasoning: streamed.result.reasoning,
236
+ response: chatResponse.result.responseText,
237
+ functionCalls: chatResponse.result.functionCalls,
238
+ reasoning: chatResponse.result.reasoning,
235
239
  usage,
236
- rawUsage: streamed.result.usage,
237
- finishReason: streamed.result.finishReason,
238
- providerMetadata: streamed.result.providerMetadata,
239
- requestStatus: streamed.result.requestStatus ?? 200,
240
+ rawUsage: chatResponse.result.usage,
241
+ finishReason: chatResponse.result.finishReason,
242
+ providerMetadata: chatResponse.result.providerMetadata,
243
+ requestStatus,
240
244
  };
241
245
  }
@@ -147,7 +147,7 @@ export function getCommonChatV2Outputs(data, options = {}) {
147
147
  if (includeFunctionCalls) {
148
148
  outputs.push({
149
149
  id: functionCallsPortId,
150
- title: 'Function Calls',
150
+ title: 'Tool Calls',
151
151
  dataType: 'object[]',
152
152
  });
153
153
  }
@@ -196,7 +196,11 @@ export function createChatV2Model(provider, modelId, context, options = {}) {
196
196
  headers: options.headers,
197
197
  includeUsage: true,
198
198
  });
199
- return providerInstance.chatModel(modelId);
199
+ const model = providerInstance.chatModel(modelId);
200
+ // The installed OpenAI-compatible provider reads this from the model instance,
201
+ // but its factory options do not forward the flag.
202
+ model.supportsStructuredOutputs = true;
203
+ return model;
200
204
  }
201
205
  }
202
206
  }
@@ -22,7 +22,7 @@ export class CoalesceNodeImpl extends NodeImpl {
22
22
  visualData: {
23
23
  x: 0,
24
24
  y: 0,
25
- width: 150,
25
+ width: 190,
26
26
  },
27
27
  };
28
28
  return chartNode;
@@ -8,6 +8,20 @@ import { match } from 'ts-pattern';
8
8
  import { dedent } from 'ts-dedent';
9
9
  import { nodeDefinition } from '../NodeDefinition.js';
10
10
  import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
11
+ export const compareNodeComparisonFunctionOptions = [
12
+ { label: '==', value: '==' },
13
+ { label: '!=', value: '!=' },
14
+ { label: '<', value: '<' },
15
+ { label: '<=', value: '<=' },
16
+ { label: '>', value: '>' },
17
+ { label: '>=', value: '>=' },
18
+ { label: 'and', value: 'and' },
19
+ { label: 'or', value: 'or' },
20
+ { label: 'xor', value: 'xor' },
21
+ { label: 'nand', value: 'nand' },
22
+ { label: 'nor', value: 'nor' },
23
+ { label: 'xnor', value: 'xnor' },
24
+ ];
11
25
  export class CompareNodeImpl extends NodeImpl {
12
26
  static create() {
13
27
  const chartNode = {
@@ -62,20 +76,7 @@ export class CompareNodeImpl extends NodeImpl {
62
76
  type: 'dropdown',
63
77
  label: 'Comparison Function',
64
78
  dataKey: 'comparisonFunction',
65
- options: [
66
- { label: '==', value: '==' },
67
- { label: '!=', value: '!=' },
68
- { label: '<', value: '<' },
69
- { label: '<=', value: '<=' },
70
- { label: '>', value: '>' },
71
- { label: '>=', value: '>=' },
72
- { label: 'and', value: 'and' },
73
- { label: 'or', value: 'or' },
74
- { label: 'xor', value: 'xor' },
75
- { label: 'nand', value: 'nand' },
76
- { label: 'nor', value: 'nor' },
77
- { label: 'xnor', value: 'xnor' },
78
- ],
79
+ options: compareNodeComparisonFunctionOptions,
79
80
  useInputToggleDataKey: 'useComparisonFunctionInput',
80
81
  },
81
82
  ];
@@ -78,6 +78,7 @@ export class GraphOutputNodeImpl extends NodeImpl {
78
78
  type: 'string',
79
79
  label: 'ID',
80
80
  dataKey: 'id',
81
+ commitDebounceMs: 300,
81
82
  },
82
83
  {
83
84
  type: 'dataTypeSelector',
@@ -16,31 +16,62 @@ export { buildLLMChatV2EditorCacheKey, resolveLLMChatV2RuntimeProviderOptions };
16
16
  function usesBaseURLInput(data) {
17
17
  return data.provider === 'custom' ? data.useCustomProviderBaseURLInput : data.useBaseURLInput;
18
18
  }
19
- function getCustomProviderBaseURLBodyLine(data) {
19
+ function getCustomProviderBaseURLBodyValue(data) {
20
20
  if (data.provider !== 'custom') {
21
21
  return undefined;
22
22
  }
23
23
  if (data.useCustomProviderBaseURLInput) {
24
- return 'Provider base URL: (Using Input)';
24
+ return '(Using Input)';
25
25
  }
26
26
  const baseURL = data.customProviderBaseURL.trim();
27
- return baseURL ? `Provider base URL: ${baseURL}` : undefined;
27
+ return baseURL || undefined;
28
28
  }
29
29
  function getOptionLabel(options, value) {
30
30
  return options.find((option) => option.value === (value ?? ''))?.label ?? value ?? 'Default';
31
31
  }
32
- function getReasoningEffortBodyLine(data) {
32
+ function getProviderBodyLabel(data) {
33
+ return data.provider === 'custom' ? 'Custom' : getChatV2ProviderLabel(data.provider);
34
+ }
35
+ function getReasoningEffortBodyValue(data) {
33
36
  switch (data.provider) {
34
37
  case 'openai':
35
- return `Reasoning effort: ${getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort)}`;
38
+ return getOptionLabel(openAIReasoningEffortOptions, data.openAIReasoningEffort);
36
39
  case 'anthropic':
37
- return `Reasoning effort: ${getOptionLabel(anthropicEffortOptions, data.anthropicEffort)}`;
40
+ return getOptionLabel(anthropicEffortOptions, data.anthropicEffort);
38
41
  case 'google':
39
- return `Reasoning effort: ${getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel)}`;
42
+ return getOptionLabel(googleThinkingLevelOptions, data.googleThinkingLevel);
40
43
  case 'custom':
41
44
  return undefined;
42
45
  }
43
46
  }
47
+ function escapeMarkdownInline(value) {
48
+ return value
49
+ .replace(/\r/g, '\\r')
50
+ .replace(/\n/g, '\\n')
51
+ .replace(/&/g, '&amp;')
52
+ .replace(/</g, '&lt;')
53
+ .replace(/>/g, '&gt;')
54
+ .replace(/"/g, '&quot;')
55
+ .replace(/([\\`*_[\]{}()#+\-.!|])/g, '\\$1');
56
+ }
57
+ function getBodyLine(label, value) {
58
+ return `<span style="opacity: 0.55">${label}:</span> ${escapeMarkdownInline(value)}`;
59
+ }
60
+ function getOptionalNumberBodyLine(label, value, usesInput) {
61
+ if (usesInput) {
62
+ return getBodyLine(label, '(Using Input)');
63
+ }
64
+ return value === undefined ? undefined : getBodyLine(label, `${value}`);
65
+ }
66
+ function getStopSequencesBodyLine(data) {
67
+ if (data.useStopSequencesInput) {
68
+ return getBodyLine('Stop sequences', '(Using Input)');
69
+ }
70
+ const stopSequences = (data.stopSequences ?? []).filter((sequence) => sequence.length > 0);
71
+ return stopSequences.length === 0
72
+ ? undefined
73
+ : getBodyLine('Stop sequences', stopSequences.map((sequence) => JSON.stringify(sequence)).join(', '));
74
+ }
44
75
  export class LLMChatV2NodeImpl extends NodeImpl {
45
76
  static create() {
46
77
  return {
@@ -197,17 +228,31 @@ export class LLMChatV2NodeImpl extends NodeImpl {
197
228
  }
198
229
  getBody() {
199
230
  const modelInfo = getChatV2ModelInfo(this.data.provider, this.data.model);
200
- const providerLabel = getChatV2ProviderLabel(this.data.provider);
201
- const baseURLLine = getCustomProviderBaseURLBodyLine(this.data);
231
+ const providerLabel = getProviderBodyLabel(this.data);
232
+ const baseURLValue = getCustomProviderBaseURLBodyValue(this.data);
202
233
  const modelLine = modelInfo?.displayName ?? this.data.model;
203
- const providerDetails = baseURLLine ? [providerLabel, baseURLLine, modelLine] : [providerLabel, modelLine];
204
- const reasoningEffortLine = getReasoningEffortBodyLine(this.data);
205
- return [
206
- ...providerDetails,
207
- ...(reasoningEffortLine ? [reasoningEffortLine] : []),
208
- `Temperature: ${this.data.useTemperatureInput ? '(Using Input)' : this.data.temperature}`,
209
- `Max output tokens: ${this.data.useMaxTokensInput ? '(Using Input)' : this.data.maxTokens}`,
210
- ].join('\n');
234
+ const providerDetails = [
235
+ getBodyLine('Provider', providerLabel),
236
+ ...(baseURLValue ? [getBodyLine('Base URL', baseURLValue)] : []),
237
+ getBodyLine('Model', modelLine),
238
+ ];
239
+ const reasoningEffortValue = getReasoningEffortBodyValue(this.data);
240
+ return {
241
+ type: 'markdown',
242
+ disableLinks: true,
243
+ text: [
244
+ ...providerDetails,
245
+ ...(reasoningEffortValue ? [getBodyLine('Reasoning effort', reasoningEffortValue)] : []),
246
+ getBodyLine('Temperature', this.data.useTemperatureInput ? '(Using Input)' : `${this.data.temperature}`),
247
+ getBodyLine('Max output tokens', this.data.useMaxTokensInput ? '(Using Input)' : `${this.data.maxTokens}`),
248
+ getOptionalNumberBodyLine('Top P', this.data.topP, this.data.useTopPInput),
249
+ getOptionalNumberBodyLine('Top K', this.data.topK, this.data.useTopKInput),
250
+ getOptionalNumberBodyLine('Presence penalty', this.data.presencePenalty, this.data.usePresencePenaltyInput),
251
+ getOptionalNumberBodyLine('Frequency penalty', this.data.frequencyPenalty, this.data.useFrequencyPenaltyInput),
252
+ getStopSequencesBodyLine(this.data),
253
+ getOptionalNumberBodyLine('Seed', this.data.seed, this.data.useSeedInput),
254
+ ].filter((line) => line !== undefined).join('\n'),
255
+ };
211
256
  }
212
257
  async process(inputs, context) {
213
258
  const runtime = await resolveLLMChatV2RuntimeConfig({
@@ -0,0 +1,39 @@
1
+ import { nanoid } from 'nanoid/non-secure';
2
+ import {} from '../GraphProcessor.js';
3
+ import {} from '../NodeBase.js';
4
+ import { nodeDefinition } from '../NodeDefinition.js';
5
+ import { NodeImpl } from '../NodeImpl.js';
6
+ import { NODE_PREFAB_INSTANCE_TYPE, } from '../NodePrefabResolver.js';
7
+ export class NodePrefabInstanceNodeImpl extends NodeImpl {
8
+ static create() {
9
+ return {
10
+ type: NODE_PREFAB_INSTANCE_TYPE,
11
+ title: 'Linked node',
12
+ id: nanoid(),
13
+ visualData: {
14
+ x: 0,
15
+ y: 0,
16
+ width: 240,
17
+ },
18
+ data: {},
19
+ };
20
+ }
21
+ getInputDefinitions() {
22
+ return [];
23
+ }
24
+ getOutputDefinitions() {
25
+ return [];
26
+ }
27
+ async process(_inputData) {
28
+ throw new Error('Library node is missing. Open the Node Library and reconnect this linked node.');
29
+ }
30
+ static getUIData() {
31
+ return {
32
+ contextMenuTitle: 'Linked node',
33
+ infoBoxTitle: 'Linked node',
34
+ infoBoxBody: 'Runs a node from the project Node Library.',
35
+ group: 'Advanced',
36
+ };
37
+ }
38
+ }
39
+ export const nodePrefabInstanceNode = nodeDefinition(NodePrefabInstanceNodeImpl, 'Linked node');
@@ -178,7 +178,8 @@ export class PromptNodeImpl extends NodeImpl {
178
178
  acc[key] = coerceTypeOptional(inputs[key], 'string') ?? '';
179
179
  return acc;
180
180
  }, {});
181
- const outputValue = interpolate(this.chartNode.data.promptText, inputMap, context.graphInputNodeValues, context.contextValues);
181
+ let outputValue = interpolate(this.chartNode.data.promptText, inputMap, context.graphInputNodeValues, context.contextValues);
182
+ outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
182
183
  const type = getInputOrData(this.data, inputs, 'type', 'string');
183
184
  const isCacheBreakpoint = getInputOrData(this.data, inputs, 'isCacheBreakpoint', 'boolean');
184
185
  if (['assistant', 'system', 'user', 'function'].includes(type) === false) {
@@ -9,7 +9,7 @@ import {} from '../DataValue.js';
9
9
  import {} from '../ProcessContext.js';
10
10
  import { dedent } from 'ts-dedent';
11
11
  import { getError } from '../../utils/errors.js';
12
- import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
12
+ import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
13
13
  export class ReferencedGraphAliasNodeImpl extends NodeImpl {
14
14
  static create() {
15
15
  const chartNode = {
@@ -117,14 +117,32 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
117
117
  const boundary = context.getGraphBoundary?.(referencedProject, this.data.graphId) ??
118
118
  getGraphBoundary(referencedProject, this.data.graphId);
119
119
  const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
120
+ const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
121
+ context.isDirectRunTarget ||
122
+ (this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
123
+ const requestedGraphOutputNodeIds = shouldRunWholeGraph
124
+ ? []
125
+ : getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
126
+ if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
127
+ return buildSkippedReferencedGraphOutputs(boundary, this.data.useErrorOutput, this.data.outputCostDuration);
128
+ }
120
129
  // Create a subprocessor using the referenced project's graph
121
130
  const subGraphProcessor = context.createSubProcessor(this.data.graphId, {
122
131
  signal: context.signal,
123
132
  project: referencedProject,
124
133
  });
134
+ if (!shouldRunWholeGraph) {
135
+ subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
136
+ }
125
137
  try {
126
138
  const startTime = Date.now();
127
- const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
139
+ const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
140
+ const outputs = shouldRunWholeGraph
141
+ ? graphOutputs
142
+ : {
143
+ ...buildExcludedGraphBoundaryOutputs(boundary),
144
+ ...graphOutputs,
145
+ };
128
146
  const duration = Date.now() - startTime;
129
147
  if (this.data.useErrorOutput) {
130
148
  outputs['error'] = {
@@ -138,11 +156,7 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
138
156
  value: duration,
139
157
  };
140
158
  }
141
- if (!this.data.outputCostDuration) {
142
- delete outputs['cost'];
143
- delete outputs['duration'];
144
- }
145
- return outputs;
159
+ return applyMetricOutputSetting(outputs, this.data.outputCostDuration);
146
160
  }
147
161
  catch (err) {
148
162
  if (!this.data.useErrorOutput) {
@@ -158,3 +172,31 @@ export class ReferencedGraphAliasNodeImpl extends NodeImpl {
158
172
  }
159
173
  }
160
174
  export const referencedGraphAliasNode = nodeDefinition(ReferencedGraphAliasNodeImpl, 'Referenced Graph Alias');
175
+ function buildSkippedReferencedGraphOutputs(boundary, useErrorOutput, outputCostDuration) {
176
+ const outputs = buildExcludedGraphBoundaryOutputs(boundary);
177
+ if (useErrorOutput) {
178
+ outputs['error'] = {
179
+ type: 'control-flow-excluded',
180
+ value: undefined,
181
+ };
182
+ }
183
+ if (outputCostDuration) {
184
+ outputs['cost'] = {
185
+ type: 'number',
186
+ value: 0,
187
+ };
188
+ outputs['duration'] = {
189
+ type: 'number',
190
+ value: 0,
191
+ };
192
+ }
193
+ return applyMetricOutputSetting(outputs, outputCostDuration);
194
+ }
195
+ function applyMetricOutputSetting(outputs, outputCostDuration) {
196
+ if (outputCostDuration) {
197
+ return outputs;
198
+ }
199
+ delete outputs['cost'];
200
+ delete outputs['duration'];
201
+ return outputs;
202
+ }
@@ -10,7 +10,7 @@ import {} from '../ProcessContext.js';
10
10
  import {} from '../../index.js';
11
11
  import { dedent } from 'ts-dedent';
12
12
  import { getError } from '../../utils/errors.js';
13
- import { buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, } from '../GraphBoundaryCache.js';
13
+ import { applyGraphBoundaryPortOrder, buildExcludedGraphBoundaryOutputs, buildGraphBoundaryInputData, GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED, getGraphBoundary, getGraphBoundaryInputDefinitions, getGraphBoundaryOutputDefinitions, getRequestedGraphOutputNodeIds, } from '../GraphBoundaryCache.js';
14
14
  export class SubGraphNodeImpl extends NodeImpl {
15
15
  static create() {
16
16
  const chartNode = {
@@ -32,11 +32,11 @@ export class SubGraphNodeImpl extends NodeImpl {
32
32
  }
33
33
  getInputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
34
34
  const boundary = this.getBoundary(project, definitionContext);
35
- return boundary ? getGraphBoundaryInputDefinitions(boundary) : [];
35
+ return boundary ? getGraphBoundaryInputDefinitions(boundary, this.data.inputPortOrder) : [];
36
36
  }
37
37
  getGraphOutputs(project, definitionContext) {
38
38
  const boundary = this.getBoundary(project, definitionContext);
39
- return boundary ? getGraphBoundaryOutputDefinitions(boundary) : [];
39
+ return boundary ? getGraphBoundaryOutputDefinitions(boundary, this.data.outputPortOrder) : [];
40
40
  }
41
41
  getOutputDefinitions(_connections, _nodes, project, _referencedProjects, definitionContext) {
42
42
  const outputs = [];
@@ -69,7 +69,7 @@ export class SubGraphNodeImpl extends NodeImpl {
69
69
  if (this.data.graphId) {
70
70
  const boundary = getGraphBoundary(context.project, this.data.graphId);
71
71
  if (boundary) {
72
- for (const input of boundary.inputs) {
72
+ for (const input of applyGraphBoundaryPortOrder(boundary.inputs, this.data.inputPortOrder)) {
73
73
  definitions.push({
74
74
  type: 'dynamic',
75
75
  dataKey: 'inputData',
@@ -104,10 +104,29 @@ export class SubGraphNodeImpl extends NodeImpl {
104
104
  }
105
105
  const boundary = context.getGraphBoundary?.(project, this.data.graphId) ?? getGraphBoundary(project, this.data.graphId);
106
106
  const inputData = buildGraphBoundaryInputData(boundary, inputs, this.data.inputData);
107
+ const shouldRunWholeGraph = !GRAPH_BOUNDARY_OUTPUT_DEMAND_OPTIMIZATION_ENABLED ||
108
+ context.isDirectRunTarget ||
109
+ this.data.useAsGraphPartialOutput === true ||
110
+ (this.data.useErrorOutput === true && context.activeOutputPortIds.has('error'));
111
+ const requestedGraphOutputNodeIds = shouldRunWholeGraph
112
+ ? []
113
+ : getRequestedGraphOutputNodeIds(boundary, context.activeOutputPortIds);
114
+ if (!shouldRunWholeGraph && requestedGraphOutputNodeIds.length === 0) {
115
+ return buildSkippedSubgraphOutputs(boundary, this.data.useErrorOutput);
116
+ }
107
117
  const subGraphProcessor = context.createSubProcessor(this.data.graphId, { signal: context.signal });
118
+ if (!shouldRunWholeGraph) {
119
+ subGraphProcessor.runToNodeIds = requestedGraphOutputNodeIds;
120
+ }
108
121
  try {
109
122
  const startTime = Date.now();
110
- const outputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
123
+ const graphOutputs = await subGraphProcessor.processGraph(context, inputData, context.contextValues);
124
+ const outputs = shouldRunWholeGraph
125
+ ? graphOutputs
126
+ : {
127
+ ...buildExcludedGraphBoundaryOutputs(boundary),
128
+ ...graphOutputs,
129
+ };
111
130
  const duration = Date.now() - startTime;
112
131
  if (this.data.useErrorOutput) {
113
132
  outputs['error'] = {
@@ -137,3 +156,21 @@ export class SubGraphNodeImpl extends NodeImpl {
137
156
  }
138
157
  }
139
158
  export const subGraphNode = nodeDefinition(SubGraphNodeImpl, 'Subgraph');
159
+ function buildSkippedSubgraphOutputs(boundary, useErrorOutput) {
160
+ const outputs = buildExcludedGraphBoundaryOutputs(boundary);
161
+ if (useErrorOutput) {
162
+ outputs['error'] = {
163
+ type: 'control-flow-excluded',
164
+ value: undefined,
165
+ };
166
+ }
167
+ outputs['cost'] = {
168
+ type: 'number',
169
+ value: 0,
170
+ };
171
+ outputs['duration'] = {
172
+ type: 'number',
173
+ value: 0,
174
+ };
175
+ return outputs;
176
+ }
@@ -15,3 +15,5 @@ export * from './defaults.js';
15
15
  export * from './orderedStringPortIds.js';
16
16
  export * from './runtimeLogging.js';
17
17
  export * from './providerStreamParsing.js';
18
+ export * from './projectComparison.js';
19
+ export * from './jsonValueToDataValue.js';
@@ -0,0 +1,48 @@
1
+ export function jsonValueToDataValue(value) {
2
+ if (isDataValue(value)) {
3
+ return value;
4
+ }
5
+ if (typeof value === 'string') {
6
+ return { type: 'string', value };
7
+ }
8
+ if (typeof value === 'number') {
9
+ return { type: 'number', value };
10
+ }
11
+ if (typeof value === 'boolean') {
12
+ return { type: 'boolean', value };
13
+ }
14
+ if (Array.isArray(value)) {
15
+ return jsonArrayToDataValue(value);
16
+ }
17
+ if (isRecord(value)) {
18
+ return { type: 'object', value };
19
+ }
20
+ return { type: 'any', value };
21
+ }
22
+ function jsonArrayToDataValue(value) {
23
+ if (value.length === 0) {
24
+ return { type: 'any[]', value: [] };
25
+ }
26
+ if (value.every((item) => typeof item === 'string')) {
27
+ return { type: 'string[]', value };
28
+ }
29
+ if (value.every((item) => typeof item === 'number')) {
30
+ return { type: 'number[]', value };
31
+ }
32
+ if (value.every((item) => typeof item === 'boolean')) {
33
+ return { type: 'boolean[]', value };
34
+ }
35
+ if (value.every(isRecord)) {
36
+ return { type: 'object[]', value };
37
+ }
38
+ return { type: 'any[]', value };
39
+ }
40
+ function isDataValue(value) {
41
+ return (value != null &&
42
+ typeof value === 'object' &&
43
+ typeof value.type === 'string' &&
44
+ 'value' in value);
45
+ }
46
+ function isRecord(value) {
47
+ return value != null && typeof value === 'object' && !Array.isArray(value);
48
+ }