@valerypopoff/rivet2-core 2.0.7 → 2.0.9

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 (63) hide show
  1. package/dist/cjs/bundle.cjs +1757 -789
  2. package/dist/cjs/bundle.cjs.map +4 -4
  3. package/dist/esm/api/createProcessor.js +9 -2
  4. package/dist/esm/api/streaming.js +1 -0
  5. package/dist/esm/exports.js +1 -0
  6. package/dist/esm/model/DebuggerTransportSentinel.js +78 -0
  7. package/dist/esm/model/GraphAbortReasons.js +69 -0
  8. package/dist/esm/model/GraphBoundaryCache.js +92 -0
  9. package/dist/esm/model/GraphPreprocessor.js +212 -32
  10. package/dist/esm/model/GraphProcessor.js +493 -172
  11. package/dist/esm/model/NodeExclusionPolicy.js +67 -0
  12. package/dist/esm/model/NodeExecutionPlanner.js +66 -22
  13. package/dist/esm/model/NodeImpl.js +6 -4
  14. package/dist/esm/model/ProcessContextBuilder.js +2 -17
  15. package/dist/esm/model/RecordingPlayer.js +27 -7
  16. package/dist/esm/model/SplitRunProcessor.js +48 -9
  17. package/dist/esm/model/SubprocessorBridge.js +30 -23
  18. package/dist/esm/model/chat-v2/chatV2Outputs.js +183 -0
  19. package/dist/esm/model/chat-v2/chatV2Pipeline.js +30 -212
  20. package/dist/esm/model/nodes/CodeNewNode.js +1 -1
  21. package/dist/esm/model/nodes/CodeNode.js +1 -1
  22. package/dist/esm/model/nodes/GetGlobalNode.js +14 -4
  23. package/dist/esm/model/nodes/GraphOutputNode.js +31 -2
  24. package/dist/esm/model/nodes/HttpCallNode.js +20 -18
  25. package/dist/esm/model/nodes/LoopUntilNode.js +18 -45
  26. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +24 -63
  27. package/dist/esm/model/nodes/SetGlobalNode.js +2 -1
  28. package/dist/esm/model/nodes/SubGraphNode.js +22 -63
  29. package/dist/esm/model/nodes/codeNodeErrorDiagnostics.js +2 -3
  30. package/dist/esm/recording/ExecutionRecorder.js +19 -6
  31. package/dist/esm/utils/emitDetached.js +2 -2
  32. package/dist/esm/utils/interpolation.js +41 -1
  33. package/dist/esm/utils/serialization/serialization.js +6 -5
  34. package/dist/esm/utils/serialization/serializationHelpers.js +2 -2
  35. package/dist/esm/utils/serialization/serializationInput.js +48 -0
  36. package/dist/esm/utils/serialization/serializationUtils.js +2 -33
  37. package/dist/esm/utils/serialization/serialization_v2.js +8 -8
  38. package/dist/types/api/createProcessor.d.ts +9 -2
  39. package/dist/types/api/streaming.d.ts +1 -0
  40. package/dist/types/exports.d.ts +1 -0
  41. package/dist/types/model/DebuggerTransportSentinel.d.ts +21 -0
  42. package/dist/types/model/EditorDefinition.d.ts +2 -0
  43. package/dist/types/model/ExecutorProtocol.d.ts +5 -0
  44. package/dist/types/model/GraphAbortReasons.d.ts +23 -0
  45. package/dist/types/model/GraphBoundaryCache.d.ts +27 -0
  46. package/dist/types/model/GraphPreprocessor.d.ts +39 -3
  47. package/dist/types/model/GraphProcessor.d.ts +20 -1
  48. package/dist/types/model/NodeExclusionPolicy.d.ts +21 -0
  49. package/dist/types/model/NodeExecutionPlanner.d.ts +3 -8
  50. package/dist/types/model/NodeImpl.d.ts +10 -5
  51. package/dist/types/model/Nodes.d.ts +2 -2
  52. package/dist/types/model/ProcessContext.d.ts +3 -0
  53. package/dist/types/model/ProcessContextBuilder.d.ts +4 -20
  54. package/dist/types/model/SplitRunProcessor.d.ts +8 -3
  55. package/dist/types/model/chat-v2/chatV2Outputs.d.ts +29 -0
  56. package/dist/types/model/nodes/LoopUntilNode.d.ts +5 -4
  57. package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +5 -4
  58. package/dist/types/model/nodes/SubGraphNode.d.ts +6 -5
  59. package/dist/types/model/nodes/codeNodeErrorDiagnostics.d.ts +1 -2
  60. package/dist/types/recording/RecordedEvents.d.ts +4 -0
  61. package/dist/types/utils/emitDetached.d.ts +2 -2
  62. package/dist/types/utils/serialization/serializationInput.d.ts +7 -0
  63. package/package.json +1 -1
@@ -0,0 +1,183 @@
1
+ import { inferType } from '../../utils/coerceType.js';
2
+ import { createAssistantMessagesOutput } from '../chat/streamChatResponse.js';
3
+ import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
4
+ import { calculateChatV2Cost } from './modelRegistry.js';
5
+ const CHAT_V2_REQUEST_STATUS_PORT_ID = 'requestStatus';
6
+ const CHAT_V2_REQUEST_ERROR_PORT_ID = 'requestError';
7
+ function toFunctionCallOutputValue(functionCall) {
8
+ let argumentsValue = functionCall.lastParsedArguments;
9
+ if (argumentsValue == null) {
10
+ try {
11
+ argumentsValue = JSON.parse(functionCall.arguments);
12
+ }
13
+ catch {
14
+ argumentsValue = functionCall.arguments;
15
+ }
16
+ }
17
+ return {
18
+ name: functionCall.name,
19
+ arguments: argumentsValue,
20
+ id: functionCall.id,
21
+ };
22
+ }
23
+ function createControlFlowExcludedOutput() {
24
+ return {
25
+ type: 'control-flow-excluded',
26
+ value: undefined,
27
+ };
28
+ }
29
+ export function normalizeChatV2Usage(usage, options) {
30
+ if (usage == null) {
31
+ return undefined;
32
+ }
33
+ const promptTokens = usage.inputTokens ?? 0;
34
+ const completionTokens = usage.outputTokens ?? 0;
35
+ const totalTokens = usage.totalTokens ?? promptTokens + completionTokens;
36
+ const cachedTokens = (usage.inputTokenDetails?.cacheReadTokens ?? 0) + (usage.inputTokenDetails?.cacheWriteTokens ?? 0);
37
+ const reasoningTokens = usage.outputTokenDetails?.reasoningTokens ?? 0;
38
+ return {
39
+ promptTokens,
40
+ completionTokens,
41
+ totalTokens,
42
+ cachedTokens,
43
+ reasoningTokens,
44
+ totalCost: calculateChatV2Cost(options.provider, options.modelId, promptTokens, completionTokens),
45
+ };
46
+ }
47
+ function tryParseStructuredResponseText(response) {
48
+ try {
49
+ return JSON.parse(response);
50
+ }
51
+ catch {
52
+ return undefined;
53
+ }
54
+ }
55
+ function createChatV2ResponseOutput(response, structuredOutput, responseFormat) {
56
+ if (!isChatV2StructuredResponseFormat(responseFormat)) {
57
+ return { type: 'string', value: response };
58
+ }
59
+ const parsedOutput = structuredOutput !== undefined ? structuredOutput : tryParseStructuredResponseText(response);
60
+ return parsedOutput !== undefined ? inferType(parsedOutput) : { type: 'string', value: response };
61
+ }
62
+ function createChatV2ReasoningOutput(reasoning) {
63
+ if (Array.isArray(reasoning)) {
64
+ const nonEmptyReasoning = reasoning.filter((part) => typeof part === 'string' && part.trim().length > 0);
65
+ return nonEmptyReasoning.length > 0
66
+ ? {
67
+ type: 'string[]',
68
+ value: nonEmptyReasoning,
69
+ }
70
+ : createControlFlowExcludedOutput();
71
+ }
72
+ const reasoningText = typeof reasoning === 'string' ? reasoning : '';
73
+ return reasoningText.trim().length > 0
74
+ ? {
75
+ type: 'string',
76
+ value: reasoningText,
77
+ }
78
+ : createControlFlowExcludedOutput();
79
+ }
80
+ function createChatV2RetryAttemptOutput(type, values) {
81
+ return values.length > 0
82
+ ? {
83
+ type,
84
+ value: values,
85
+ }
86
+ : createControlFlowExcludedOutput();
87
+ }
88
+ export function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }) {
89
+ const outputs = {
90
+ ['response']: createChatV2ResponseOutput(response, structuredOutput, responseFormat),
91
+ ['in-messages']: { type: 'chat-message[]', value: requestMessages },
92
+ ['all-messages']: createAssistantMessagesOutput(requestMessages, response, functionCalls, {
93
+ functionCallMode,
94
+ }),
95
+ ['responseTokens']: { type: 'number', value: usage?.completionTokens ?? 0 },
96
+ };
97
+ if (functionCalls.length > 0) {
98
+ outputs['function-calls'] = {
99
+ type: 'object[]',
100
+ value: functionCalls.map(toFunctionCallOutputValue),
101
+ };
102
+ }
103
+ else if (includeFunctionCalls) {
104
+ outputs['function-calls'] = createControlFlowExcludedOutput();
105
+ }
106
+ if (outputUsage) {
107
+ outputs['usage'] = {
108
+ type: 'object',
109
+ value: usage ?? {
110
+ promptTokens: 0,
111
+ completionTokens: 0,
112
+ totalTokens: 0,
113
+ cachedTokens: 0,
114
+ reasoningTokens: 0,
115
+ totalCost: undefined,
116
+ },
117
+ };
118
+ }
119
+ if (outputReasoning) {
120
+ outputs['reasoning'] = createChatV2ReasoningOutput(reasoning);
121
+ }
122
+ if (outputRequestStatus) {
123
+ if (retryOnNon200) {
124
+ outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = createChatV2RetryAttemptOutput('number[]', requestStatuses.length > 0 ? requestStatuses : [requestStatus ?? 200]);
125
+ outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] = createChatV2RetryAttemptOutput('string[]', requestErrors);
126
+ }
127
+ else {
128
+ outputs[CHAT_V2_REQUEST_STATUS_PORT_ID] = {
129
+ type: 'number',
130
+ value: requestStatus ?? 200,
131
+ };
132
+ outputs[CHAT_V2_REQUEST_ERROR_PORT_ID] =
133
+ responseError != null
134
+ ? {
135
+ type: 'string',
136
+ value: responseError,
137
+ }
138
+ : createControlFlowExcludedOutput();
139
+ }
140
+ }
141
+ return outputs;
142
+ }
143
+ export function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }) {
144
+ const outputs = {
145
+ [CHAT_V2_REQUEST_ERROR_PORT_ID]: retryOnNon200
146
+ ? createChatV2RetryAttemptOutput('string[]', requestErrors)
147
+ : {
148
+ type: 'string',
149
+ value: responseError,
150
+ },
151
+ [CHAT_V2_REQUEST_STATUS_PORT_ID]: retryOnNon200
152
+ ? createChatV2RetryAttemptOutput('number[]', requestStatuses)
153
+ : responseStatus == null
154
+ ? {
155
+ type: 'control-flow-excluded',
156
+ value: undefined,
157
+ }
158
+ : {
159
+ type: 'number',
160
+ value: responseStatus,
161
+ },
162
+ ['response']: createControlFlowExcludedOutput(),
163
+ ['in-messages']: {
164
+ type: 'chat-message[]',
165
+ value: requestMessages,
166
+ },
167
+ ['all-messages']: {
168
+ type: 'chat-message[]',
169
+ value: requestMessages,
170
+ },
171
+ ['responseTokens']: createControlFlowExcludedOutput(),
172
+ };
173
+ if (includeFunctionCalls) {
174
+ outputs['function-calls'] = createControlFlowExcludedOutput();
175
+ }
176
+ if (outputUsage) {
177
+ outputs['usage'] = createControlFlowExcludedOutput();
178
+ }
179
+ if (outputReasoning) {
180
+ outputs['reasoning'] = createControlFlowExcludedOutput();
181
+ }
182
+ return outputs;
183
+ }
@@ -1,15 +1,10 @@
1
- import { inferType } from '../../utils/coerceType.js';
2
1
  import { coercePromptToChatMessages, prependSystemPrompt } from '../chat/chatMessages.js';
3
- import { createAssistantMessagesOutput } from '../chat/streamChatResponse.js';
4
2
  import { streamChatV2 } from './aiSdkBridge.js';
5
3
  import { chatMessagesToModelMessages } from './messageConverter.js';
6
- import { calculateChatV2Cost } from './modelRegistry.js';
7
- import { isChatV2StructuredResponseFormat } from './chatV2ResponseFormat.js';
8
4
  import { chatV2ToolsToAiSdk } from './toolConverter.js';
9
5
  import { getChatV2ProviderErrorStatusCode, isChatV2ProviderApiCallError, isChatV2ProviderFetchError, normalizeChatV2ProviderError, } from './chatV2Errors.js';
10
6
  import { normalizeLLMChatV2RetryCooldownMs, normalizeLLMChatV2RetryCount, waitForLLMChatV2RetryCooldown, } from './chatV2Retry.js';
11
- const REQUEST_STATUS_PORT_ID = 'requestStatus';
12
- const REQUEST_ERROR_PORT_ID = 'requestError';
7
+ import { createChatV2CommonOutputs, createChatV2ProviderFailureOutputs, normalizeChatV2Usage, } from './chatV2Outputs.js';
13
8
  class StreamChatV2RetryFailure extends Error {
14
9
  error;
15
10
  requestStatuses;
@@ -25,214 +20,12 @@ class StreamChatV2RetryFailure extends Error {
25
20
  function isStreamChatV2RetryFailure(error) {
26
21
  return error instanceof StreamChatV2RetryFailure;
27
22
  }
28
- function toFunctionCallOutputValue(functionCall) {
29
- let argumentsValue = functionCall.lastParsedArguments;
30
- if (argumentsValue == null) {
31
- try {
32
- argumentsValue = JSON.parse(functionCall.arguments);
33
- }
34
- catch {
35
- argumentsValue = functionCall.arguments;
36
- }
37
- }
38
- return {
39
- name: functionCall.name,
40
- arguments: argumentsValue,
41
- id: functionCall.id,
42
- };
43
- }
44
- function normalizeUsage(usage, options) {
45
- if (usage == null) {
46
- return undefined;
47
- }
48
- const promptTokens = usage.inputTokens ?? 0;
49
- const completionTokens = usage.outputTokens ?? 0;
50
- const totalTokens = usage.totalTokens ?? promptTokens + completionTokens;
51
- const cachedTokens = (usage.inputTokenDetails?.cacheReadTokens ?? 0) + (usage.inputTokenDetails?.cacheWriteTokens ?? 0);
52
- const reasoningTokens = usage.outputTokenDetails?.reasoningTokens ?? 0;
53
- return {
54
- promptTokens,
55
- completionTokens,
56
- totalTokens,
57
- cachedTokens,
58
- reasoningTokens,
59
- totalCost: calculateChatV2Cost(options.provider, options.modelId, promptTokens, completionTokens),
60
- };
61
- }
62
- function tryParseStructuredResponseText(response) {
63
- try {
64
- return JSON.parse(response);
65
- }
66
- catch {
67
- return undefined;
68
- }
69
- }
70
- function buildResponseOutput(response, structuredOutput, responseFormat) {
71
- if (!isChatV2StructuredResponseFormat(responseFormat)) {
72
- return { type: 'string', value: response };
73
- }
74
- const parsedOutput = structuredOutput !== undefined ? structuredOutput : tryParseStructuredResponseText(response);
75
- return parsedOutput !== undefined ? inferType(parsedOutput) : { type: 'string', value: response };
76
- }
77
- function buildCommonOutputs(requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, options) {
78
- const outputs = {
79
- ['response']: buildResponseOutput(response, structuredOutput, options.responseFormat),
80
- ['in-messages']: { type: 'chat-message[]', value: requestMessages },
81
- ['all-messages']: createAssistantMessagesOutput(requestMessages, response, functionCalls, {
82
- functionCallMode: options.functionCallMode,
83
- }),
84
- ['responseTokens']: { type: 'number', value: usage?.completionTokens ?? 0 },
85
- };
86
- if (functionCalls.length > 0) {
87
- outputs['function-calls'] = {
88
- type: 'object[]',
89
- value: functionCalls.map(toFunctionCallOutputValue),
90
- };
91
- }
92
- else if (options.includeFunctionCalls) {
93
- outputs['function-calls'] = {
94
- type: 'control-flow-excluded',
95
- value: undefined,
96
- };
97
- }
98
- if (options.outputUsage) {
99
- outputs['usage'] = {
100
- type: 'object',
101
- value: usage ?? {
102
- promptTokens: 0,
103
- completionTokens: 0,
104
- totalTokens: 0,
105
- cachedTokens: 0,
106
- reasoningTokens: 0,
107
- totalCost: undefined,
108
- },
109
- };
110
- }
111
- if (options.outputReasoning) {
112
- outputs['reasoning'] = buildReasoningOutput(reasoning);
113
- }
114
- if (options.outputRequestStatus) {
115
- if (options.retryOnNon200) {
116
- outputs[REQUEST_STATUS_PORT_ID] = buildRetryAttemptOutput('number[]', requestStatuses.length > 0 ? requestStatuses : [requestStatus ?? 200]);
117
- outputs[REQUEST_ERROR_PORT_ID] = buildRetryAttemptOutput('string[]', requestErrors);
118
- }
119
- else {
120
- outputs[REQUEST_STATUS_PORT_ID] = {
121
- type: 'number',
122
- value: requestStatus ?? 200,
123
- };
124
- outputs[REQUEST_ERROR_PORT_ID] =
125
- responseError != null
126
- ? {
127
- type: 'string',
128
- value: responseError,
129
- }
130
- : {
131
- type: 'control-flow-excluded',
132
- value: undefined,
133
- };
134
- }
135
- }
136
- return outputs;
137
- }
138
- function buildReasoningOutput(reasoning) {
139
- if (Array.isArray(reasoning)) {
140
- const nonEmptyReasoning = reasoning.filter((part) => typeof part === 'string' && part.trim().length > 0);
141
- return nonEmptyReasoning.length > 0
142
- ? {
143
- type: 'string[]',
144
- value: nonEmptyReasoning,
145
- }
146
- : {
147
- type: 'control-flow-excluded',
148
- value: undefined,
149
- };
150
- }
151
- const reasoningText = typeof reasoning === 'string' ? reasoning : '';
152
- return reasoningText.trim().length > 0
153
- ? {
154
- type: 'string',
155
- value: reasoningText,
156
- }
157
- : {
158
- type: 'control-flow-excluded',
159
- value: undefined,
160
- };
161
- }
162
23
  function getProviderFailureMessage(error) {
163
24
  if (error instanceof Error) {
164
25
  return error.message;
165
26
  }
166
27
  return String(error);
167
28
  }
168
- function buildProviderFailureOutputs(requestMessages, responseStatus, responseError, requestStatuses, requestErrors, options) {
169
- const outputs = {};
170
- Object.assign(outputs, {
171
- [REQUEST_ERROR_PORT_ID]: options.retryOnNon200
172
- ? buildRetryAttemptOutput('string[]', requestErrors)
173
- : {
174
- type: 'string',
175
- value: responseError,
176
- },
177
- [REQUEST_STATUS_PORT_ID]: options.retryOnNon200
178
- ? buildRetryAttemptOutput('number[]', requestStatuses)
179
- : responseStatus == null
180
- ? {
181
- type: 'control-flow-excluded',
182
- value: undefined,
183
- }
184
- : {
185
- type: 'number',
186
- value: responseStatus,
187
- },
188
- ['response']: {
189
- type: 'control-flow-excluded',
190
- value: undefined,
191
- },
192
- ['in-messages']: {
193
- type: 'chat-message[]',
194
- value: requestMessages,
195
- },
196
- ['all-messages']: {
197
- type: 'chat-message[]',
198
- value: requestMessages,
199
- },
200
- ['responseTokens']: {
201
- type: 'control-flow-excluded',
202
- value: undefined,
203
- },
204
- });
205
- if (options.includeFunctionCalls) {
206
- outputs['function-calls'] = {
207
- type: 'control-flow-excluded',
208
- value: undefined,
209
- };
210
- }
211
- if (options.outputUsage) {
212
- outputs['usage'] = {
213
- type: 'control-flow-excluded',
214
- value: undefined,
215
- };
216
- }
217
- if (options.outputReasoning) {
218
- outputs['reasoning'] = {
219
- type: 'control-flow-excluded',
220
- value: undefined,
221
- };
222
- }
223
- return outputs;
224
- }
225
- function buildRetryAttemptOutput(type, values) {
226
- return values.length > 0
227
- ? {
228
- type,
229
- value: values,
230
- }
231
- : {
232
- type: 'control-flow-excluded',
233
- value: undefined,
234
- };
235
- }
236
29
  function buildNon200StatusError(statusCode) {
237
30
  const error = new Error(`Provider request returned non-200 status: ${statusCode}`);
238
31
  error.name = 'AI_APICallError';
@@ -303,7 +96,12 @@ function buildProviderFailureResult(requestMessages, options, normalizedError, r
303
96
  : [statusCode]
304
97
  : [];
305
98
  const retryRequestErrors = options.retryOnNon200 ? (requestErrors.length > 0 ? requestErrors : [responseError]) : [];
306
- const commonOutputs = buildProviderFailureOutputs(requestMessages, statusCode, responseError, retryRequestStatuses, retryRequestErrors, {
99
+ const commonOutputs = createChatV2ProviderFailureOutputs({
100
+ requestMessages,
101
+ responseStatus: statusCode,
102
+ responseError,
103
+ requestStatuses: retryRequestStatuses,
104
+ requestErrors: retryRequestErrors,
307
105
  outputUsage: options.outputUsage,
308
106
  outputReasoning: options.outputReasoning,
309
107
  includeFunctionCalls: options.includeFunctionCalls,
@@ -360,7 +158,17 @@ export async function runChatV2Pipeline(options) {
360
158
  onPartialOutput: options.emitPartialOutputs === false
361
159
  ? undefined
362
160
  : ({ text, functionCalls }) => {
363
- options.context.onPartialOutputs?.(buildCommonOutputs(requestMessages, text, undefined, functionCalls, undefined, '', undefined, undefined, [], [], {
161
+ options.context.onPartialOutputs?.(createChatV2CommonOutputs({
162
+ requestMessages,
163
+ response: text,
164
+ structuredOutput: undefined,
165
+ functionCalls,
166
+ usage: undefined,
167
+ reasoning: '',
168
+ requestStatus: undefined,
169
+ responseError: undefined,
170
+ requestStatuses: [],
171
+ requestErrors: [],
364
172
  outputUsage: false,
365
173
  outputReasoning: false,
366
174
  outputRequestStatus: false,
@@ -388,13 +196,23 @@ export async function runChatV2Pipeline(options) {
388
196
  if ('commonOutputs' in streamed) {
389
197
  return streamed;
390
198
  }
391
- const usage = normalizeUsage(streamed.result.usage, options);
199
+ const usage = normalizeChatV2Usage(streamed.result.usage, options);
392
200
  const requestStatuses = streamed.requestStatuses;
393
201
  const requestErrors = normalizeProviderFailureMessages(streamed.requestErrors, options);
394
202
  const responseError = streamed.responseError
395
203
  ? normalizeProviderFailureMessage(streamed.responseError, options)
396
204
  : undefined;
397
- const commonOutputs = buildCommonOutputs(requestMessages, streamed.result.responseText, streamed.result.structuredOutput, streamed.result.functionCalls, usage, streamed.result.reasoning, streamed.result.requestStatus, responseError, requestStatuses, requestErrors, {
205
+ const commonOutputs = createChatV2CommonOutputs({
206
+ requestMessages,
207
+ response: streamed.result.responseText,
208
+ structuredOutput: streamed.result.structuredOutput,
209
+ functionCalls: streamed.result.functionCalls,
210
+ usage,
211
+ reasoning: streamed.result.reasoning,
212
+ requestStatus: streamed.result.requestStatus,
213
+ responseError,
214
+ requestStatuses,
215
+ requestErrors,
398
216
  outputUsage: options.outputUsage,
399
217
  outputReasoning: options.outputReasoning,
400
218
  outputRequestStatus: options.outputRequestStatus,
@@ -177,7 +177,7 @@ export class CodeNewNodeImpl extends NodeImpl {
177
177
  };
178
178
  }
179
179
  async process(inputs, context) {
180
- const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id, context.processId);
180
+ const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
181
181
  const interpolationContext = getJsValueInterpolationRuntimeContext(this.data.code, CODE_NEW_INPUTS_IDENTIFIER);
182
182
  const { inputNames, inputsIdentifier } = interpolationContext;
183
183
  const { source, userCodeLineOffset } = buildCodeNewWrapper(this.data.code, interpolationContext);
@@ -164,7 +164,7 @@ export class CodeNodeImpl extends NodeImpl {
164
164
  };
165
165
  }
166
166
  async process(inputs, context) {
167
- const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id, context.processId);
167
+ const sourceUrl = buildCodeNodeSourceUrl(this.chartNode.id);
168
168
  let outputs;
169
169
  try {
170
170
  outputs = await context.codeRunner.runCode(appendCodeNodeSourceUrl(this.data.code, sourceUrl), inputs, {
@@ -22,9 +22,9 @@ export class GetGlobalNodeImpl extends NodeImpl {
22
22
  data: {
23
23
  id: 'variable-name',
24
24
  dataType: 'string',
25
- onDemand: true,
25
+ onDemand: false,
26
26
  useIdInput: false,
27
- wait: false,
27
+ wait: true,
28
28
  },
29
29
  };
30
30
  return chartNode;
@@ -35,7 +35,7 @@ export class GetGlobalNodeImpl extends NodeImpl {
35
35
  {
36
36
  id: 'id',
37
37
  title: 'Variable ID',
38
- dataType: this.data.dataType,
38
+ dataType: 'string',
39
39
  },
40
40
  ];
41
41
  }
@@ -58,11 +58,18 @@ export class GetGlobalNodeImpl extends NodeImpl {
58
58
  }
59
59
  getEditors() {
60
60
  return [
61
+ {
62
+ type: 'custom',
63
+ label: 'Search Global Variables',
64
+ customEditorId: 'GetGlobalVariableSelector',
65
+ autoFocus: true,
66
+ },
61
67
  {
62
68
  type: 'string',
63
69
  label: 'Variable ID',
64
70
  dataKey: 'id',
65
71
  useInputToggleDataKey: 'useIdInput',
72
+ includeInGraphSearch: true,
66
73
  },
67
74
  {
68
75
  type: 'dataTypeSelector',
@@ -73,11 +80,13 @@ export class GetGlobalNodeImpl extends NodeImpl {
73
80
  type: 'toggle',
74
81
  label: 'On Demand',
75
82
  dataKey: 'onDemand',
83
+ turnOffDataKeysWhenEnabled: ['wait'],
76
84
  },
77
85
  {
78
86
  type: 'toggle',
79
87
  label: 'Wait',
80
88
  dataKey: 'wait',
89
+ turnOffDataKeysWhenEnabled: ['onDemand'],
81
90
  },
82
91
  ];
83
92
  }
@@ -103,11 +112,11 @@ export class GetGlobalNodeImpl extends NodeImpl {
103
112
  if (this.data.wait) {
104
113
  throw new Error('Cannot use onDemand and wait together');
105
114
  }
115
+ const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
106
116
  return {
107
117
  ['value']: {
108
118
  type: `fn<${this.data.dataType}>`,
109
119
  value: () => {
110
- const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
111
120
  const value = context.getGlobal(id);
112
121
  if (value) {
113
122
  return value.value;
@@ -119,6 +128,7 @@ export class GetGlobalNodeImpl extends NodeImpl {
119
128
  return scalarDefaults[this.data.dataType];
120
129
  },
121
130
  },
131
+ ['variable_id_out']: { type: 'string', value: id },
122
132
  };
123
133
  }
124
134
  const id = this.data.useIdInput ? coerceType(inputs['id'], 'string') : this.data.id;
@@ -8,6 +8,34 @@ import {} from '../ProcessContext.js';
8
8
  import { dedent } from 'ts-dedent';
9
9
  import {} from '../EditorDefinition.js';
10
10
  import {} from '../NodeBodySpec.js';
11
+ function isPlainObjectRecordValue(value) {
12
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
13
+ return false;
14
+ }
15
+ const prototype = Object.getPrototypeOf(value);
16
+ return prototype === Object.prototype || prototype === null;
17
+ }
18
+ function coerceAnyGraphOutputValue(value, dataType) {
19
+ if (value.type === 'control-flow-excluded' || dataType === 'any' || value.type === dataType) {
20
+ return value;
21
+ }
22
+ if (value.type !== 'any') {
23
+ return value;
24
+ }
25
+ if (dataType === 'object' && isPlainObjectRecordValue(value.value)) {
26
+ return {
27
+ type: 'object',
28
+ value: value.value,
29
+ };
30
+ }
31
+ if (dataType === 'object[]' && Array.isArray(value.value) && value.value.every(isPlainObjectRecordValue)) {
32
+ return {
33
+ type: 'object[]',
34
+ value: value.value,
35
+ };
36
+ }
37
+ return value;
38
+ }
11
39
  export class GraphOutputNodeImpl extends NodeImpl {
12
40
  static create() {
13
41
  const chartNode = {
@@ -75,7 +103,8 @@ export class GraphOutputNodeImpl extends NodeImpl {
75
103
  };
76
104
  }
77
105
  async process(inputs, context) {
78
- const value = inputs['value'] ?? { type: 'any', value: undefined };
106
+ const inputValue = inputs['value'];
107
+ const value = coerceAnyGraphOutputValue(inputValue ?? { type: 'any', value: undefined }, this.data.dataType);
79
108
  const isExcluded = value.type === 'control-flow-excluded';
80
109
  if (isExcluded && context.graphOutputs[this.data.id] == null) {
81
110
  context.graphOutputs[this.data.id] = {
@@ -85,7 +114,7 @@ export class GraphOutputNodeImpl extends NodeImpl {
85
114
  }
86
115
  else if ((context.graphOutputs[this.data.id] == null ||
87
116
  context.graphOutputs[this.data.id]?.type === 'control-flow-excluded') &&
88
- inputs['value']) {
117
+ inputValue) {
89
118
  context.graphOutputs[this.data.id] = value;
90
119
  }
91
120
  if (isExcluded) {