@alpic80/rivet-core 1.19.1-aidon.2 → 1.24.0-aidon.1

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 (107) hide show
  1. package/README.md +4 -0
  2. package/dist/cjs/bundle.cjs +4187 -1020
  3. package/dist/cjs/bundle.cjs.map +4 -4
  4. package/dist/esm/api/createProcessor.js +8 -17
  5. package/dist/esm/api/looseDataValue.js +16 -0
  6. package/dist/esm/exports.js +2 -0
  7. package/dist/esm/integrations/CodeRunner.js +36 -0
  8. package/dist/esm/integrations/GptTokenizerTokenizer.js +7 -4
  9. package/dist/esm/integrations/openai/OpenAIEmbeddingGenerator.js +1 -1
  10. package/dist/esm/model/DataValue.js +14 -2
  11. package/dist/esm/model/GraphProcessor.js +275 -104
  12. package/dist/esm/model/NodeBase.js +11 -1
  13. package/dist/esm/model/NodeImpl.js +8 -0
  14. package/dist/esm/model/Nodes.js +31 -4
  15. package/dist/esm/model/ProjectReferenceLoader.js +1 -0
  16. package/dist/esm/model/nodes/AssembleMessageNode.js +12 -2
  17. package/dist/esm/model/nodes/AssemblePromptNode.js +22 -0
  18. package/dist/esm/model/nodes/CallGraphNode.js +3 -4
  19. package/dist/esm/model/nodes/ChatLoopNode.js +150 -0
  20. package/dist/esm/model/nodes/ChatNode.js +7 -934
  21. package/dist/esm/model/nodes/ChatNodeBase.js +1275 -0
  22. package/dist/esm/model/nodes/ChunkNode.js +2 -2
  23. package/dist/esm/model/nodes/CodeNode.js +40 -4
  24. package/dist/esm/model/nodes/CronNode.js +248 -0
  25. package/dist/esm/model/nodes/DelegateFunctionCallNode.js +37 -12
  26. package/dist/esm/model/nodes/DestructureNode.js +1 -1
  27. package/dist/esm/model/nodes/DocumentNode.js +183 -0
  28. package/dist/esm/model/nodes/ExtractJsonNode.js +4 -4
  29. package/dist/esm/model/nodes/ExtractRegexNode.js +10 -11
  30. package/dist/esm/model/nodes/GetEmbeddingNode.js +1 -1
  31. package/dist/esm/model/nodes/HttpCallNode.js +3 -1
  32. package/dist/esm/model/nodes/IfNode.js +5 -0
  33. package/dist/esm/model/nodes/ImageToMDNode.js +116 -0
  34. package/dist/esm/model/nodes/LoopUntilNode.js +214 -0
  35. package/dist/esm/model/nodes/PromptNode.js +29 -6
  36. package/dist/esm/model/nodes/ReadAllFilesNode.js +210 -0
  37. package/dist/esm/model/nodes/ReadDirectoryNode.js +31 -25
  38. package/dist/esm/model/nodes/ReferencedGraphAliasNode.js +199 -0
  39. package/dist/esm/model/nodes/TextNode.js +9 -4
  40. package/dist/esm/model/nodes/ToMarkdownTableNode.js +119 -0
  41. package/dist/esm/model/nodes/ToTreeNode.js +133 -0
  42. package/dist/esm/model/nodes/{GptFunctionNode.js → ToolNode.js} +10 -10
  43. package/dist/esm/model/nodes/UserInputNode.js +10 -12
  44. package/dist/esm/plugins/aidon/nodes/ChatAidonNode.js +3 -3
  45. package/dist/esm/plugins/anthropic/anthropic.js +29 -10
  46. package/dist/esm/plugins/anthropic/fetchEventSource.js +3 -2
  47. package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +267 -147
  48. package/dist/esm/plugins/anthropic/plugin.js +9 -1
  49. package/dist/esm/plugins/gentrace/plugin.js +6 -6
  50. package/dist/esm/plugins/google/google.js +113 -5
  51. package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +211 -54
  52. package/dist/esm/plugins/google/plugin.js +13 -6
  53. package/dist/esm/plugins/openai/nodes/RunThreadNode.js +2 -2
  54. package/dist/esm/recording/ExecutionRecorder.js +5 -1
  55. package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +15 -2
  56. package/dist/esm/utils/coerceType.js +1 -1
  57. package/dist/esm/utils/fetchEventSource.js +1 -1
  58. package/dist/esm/utils/interpolation.js +108 -3
  59. package/dist/esm/utils/openai.js +106 -50
  60. package/dist/esm/utils/paths.js +80 -0
  61. package/dist/esm/utils/serialization/serialization_v4.js +5 -0
  62. package/dist/types/api/createProcessor.d.ts +11 -5
  63. package/dist/types/api/looseDataValue.d.ts +4 -0
  64. package/dist/types/api/streaming.d.ts +1 -1
  65. package/dist/types/exports.d.ts +2 -0
  66. package/dist/types/integrations/CodeRunner.d.ts +18 -0
  67. package/dist/types/model/DataValue.d.ts +29 -6
  68. package/dist/types/model/EditorDefinition.d.ts +6 -1
  69. package/dist/types/model/GraphProcessor.d.ts +14 -7
  70. package/dist/types/model/NodeBase.d.ts +4 -0
  71. package/dist/types/model/NodeImpl.d.ts +5 -4
  72. package/dist/types/model/Nodes.d.ts +13 -4
  73. package/dist/types/model/ProcessContext.d.ts +16 -1
  74. package/dist/types/model/Project.d.ts +19 -7
  75. package/dist/types/model/ProjectReferenceLoader.d.ts +5 -0
  76. package/dist/types/model/RivetPlugin.d.ts +6 -0
  77. package/dist/types/model/RivetUIContext.d.ts +5 -1
  78. package/dist/types/model/Settings.d.ts +1 -0
  79. package/dist/types/model/nodes/AssemblePromptNode.d.ts +4 -1
  80. package/dist/types/model/nodes/ChatLoopNode.d.ts +21 -0
  81. package/dist/types/model/nodes/ChatNode.d.ts +2 -62
  82. package/dist/types/model/nodes/ChatNodeBase.d.ts +85 -0
  83. package/dist/types/model/nodes/CodeNode.d.ts +8 -2
  84. package/dist/types/model/nodes/CronNode.d.ts +34 -0
  85. package/dist/types/model/nodes/DelegateFunctionCallNode.d.ts +1 -0
  86. package/dist/types/model/nodes/DocumentNode.d.ts +28 -0
  87. package/dist/types/model/nodes/ImageToMDNode.d.ts +20 -0
  88. package/dist/types/model/nodes/LoopUntilNode.d.ts +32 -0
  89. package/dist/types/model/nodes/PromptNode.d.ts +2 -0
  90. package/dist/types/model/nodes/ReadAllFilesNode.d.ts +30 -0
  91. package/dist/types/model/nodes/ReadDirectoryNode.d.ts +1 -1
  92. package/dist/types/model/nodes/ReferencedGraphAliasNode.d.ts +31 -0
  93. package/dist/types/model/nodes/ToMarkdownTableNode.d.ts +19 -0
  94. package/dist/types/model/nodes/ToTreeNode.d.ts +21 -0
  95. package/dist/types/model/nodes/UserInputNode.d.ts +2 -3
  96. package/dist/types/plugins/anthropic/anthropic.d.ts +94 -13
  97. package/dist/types/plugins/anthropic/nodes/ChatAnthropicNode.d.ts +7 -2
  98. package/dist/types/plugins/google/google.d.ts +93 -18
  99. package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +3 -2
  100. package/dist/types/recording/RecordedEvents.d.ts +2 -0
  101. package/dist/types/utils/base64.d.ts +1 -1
  102. package/dist/types/utils/chatMessageToOpenAIChatCompletionMessage.d.ts +3 -1
  103. package/dist/types/utils/interpolation.d.ts +3 -0
  104. package/dist/types/utils/openai.d.ts +127 -21
  105. package/dist/types/utils/paths.d.ts +8 -0
  106. package/package.json +15 -11
  107. /package/dist/types/model/nodes/{GptFunctionNode.d.ts → ToolNode.d.ts} +0 -0
@@ -0,0 +1,133 @@
1
+ import {} from '../NodeBase.js';
2
+ import { nanoid } from 'nanoid/non-secure';
3
+ import { NodeImpl } from '../NodeImpl.js';
4
+ import { nodeDefinition } from '../NodeDefinition.js';
5
+ import {} from '../DataValue.js';
6
+ import {} from '../EditorDefinition.js';
7
+ import { dedent } from 'ts-dedent';
8
+ import { coerceTypeOptional } from '../../utils/coerceType.js';
9
+ import { extractInterpolationVariables, interpolate } from '../../utils/interpolation.js';
10
+ import { get, sortBy } from 'lodash-es';
11
+ export class ToTreeNodeImpl extends NodeImpl {
12
+ static create() {
13
+ const chartNode = {
14
+ type: 'toTree',
15
+ title: 'To Tree',
16
+ id: nanoid(),
17
+ visualData: {
18
+ x: 0,
19
+ y: 0,
20
+ width: 300,
21
+ },
22
+ data: {
23
+ format: '{{path}}',
24
+ childrenProperty: 'children',
25
+ useSortAlphabetically: true,
26
+ },
27
+ };
28
+ return chartNode;
29
+ }
30
+ getInputDefinitions() {
31
+ return [
32
+ {
33
+ id: 'objects',
34
+ title: 'Objects',
35
+ dataType: ['object[]', 'object'],
36
+ required: true,
37
+ },
38
+ ];
39
+ }
40
+ getOutputDefinitions() {
41
+ return [
42
+ {
43
+ id: 'tree',
44
+ title: 'Tree',
45
+ dataType: 'string',
46
+ },
47
+ ];
48
+ }
49
+ getEditors() {
50
+ return [
51
+ {
52
+ type: 'string',
53
+ label: 'Children Property',
54
+ dataKey: 'childrenProperty',
55
+ },
56
+ {
57
+ type: 'code',
58
+ label: 'Format',
59
+ dataKey: 'format',
60
+ language: 'prompt-interpolation-markdown',
61
+ theme: 'prompt-interpolation',
62
+ },
63
+ {
64
+ type: 'toggle',
65
+ label: 'Sort Alphabetically',
66
+ dataKey: 'useSortAlphabetically',
67
+ },
68
+ ];
69
+ }
70
+ getBody() {
71
+ return dedent `
72
+ Format: ${this.data.format}
73
+ Children: ${this.data.childrenProperty}
74
+ Sort: ${this.data.useSortAlphabetically ? 'Yes' : 'No'}
75
+ `;
76
+ }
77
+ static getUIData() {
78
+ return {
79
+ infoBoxBody: dedent `
80
+ Converts an array of objects into a tree structure and renders it as text.
81
+
82
+ The format field supports interpolation using {{property}} syntax to determine
83
+ how each node is displayed.
84
+
85
+ Use the children property to specify which field contains child nodes.
86
+ `,
87
+ infoBoxTitle: 'To Tree Node',
88
+ contextMenuTitle: 'To Tree',
89
+ group: ['Text'],
90
+ };
91
+ }
92
+ buildTree(objects, parentPath = '', level = 0, isLast = true) {
93
+ if (!Array.isArray(objects) || objects.length === 0)
94
+ return '';
95
+ let result = '';
96
+ const sortedObjects = this.data.useSortAlphabetically
97
+ ? sortBy(objects, (obj) => String(get(obj, 'path', '')))
98
+ : objects;
99
+ sortedObjects.forEach((obj, index) => {
100
+ const isLastItem = index === sortedObjects.length - 1;
101
+ const prefix = level === 0 ? '' : isLast ? '└── ' : '├── ';
102
+ const indent = level === 0 ? '' : ' '.repeat(level - 1) + (isLast ? ' ' : '│ ');
103
+ // Get all potential interpolation variables from the format string
104
+ const matches = extractInterpolationVariables(this.data.format);
105
+ const interpolationVars = matches.reduce((acc, match) => {
106
+ const key = match;
107
+ acc[key] = String(get(obj, key, ''));
108
+ return acc;
109
+ }, {});
110
+ const formattedNode = interpolate(this.data.format, interpolationVars);
111
+ // Add this node to the result
112
+ result += indent + prefix + formattedNode + '\n';
113
+ // Process children if they exist
114
+ const children = get(obj, this.data.childrenProperty);
115
+ if (Array.isArray(children) && children.length > 0) {
116
+ const newPath = parentPath ? `${parentPath}/${formattedNode}` : formattedNode;
117
+ result += this.buildTree(children, newPath, level + 1, isLastItem);
118
+ }
119
+ });
120
+ return result;
121
+ }
122
+ async process(inputs) {
123
+ const objects = coerceTypeOptional(inputs['objects'], 'object[]') ?? [];
124
+ const treeOutput = this.buildTree(objects);
125
+ return {
126
+ ['tree']: {
127
+ type: 'string',
128
+ value: treeOutput,
129
+ },
130
+ };
131
+ }
132
+ }
133
+ export const toTreeNode = nodeDefinition(ToTreeNodeImpl, 'To Tree');
@@ -13,7 +13,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
13
13
  static create() {
14
14
  const chartNode = {
15
15
  type: 'gptFunction',
16
- title: 'GPT Function',
16
+ title: 'Tool',
17
17
  id: nanoid(),
18
18
  visualData: {
19
19
  x: 0,
@@ -21,7 +21,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
21
21
  width: 250,
22
22
  },
23
23
  data: {
24
- name: 'newFunction',
24
+ name: 'newTool',
25
25
  description: 'No description provided',
26
26
  schema: dedent `
27
27
  {
@@ -39,7 +39,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
39
39
  id: 'name',
40
40
  title: 'Name',
41
41
  dataType: 'string',
42
- description: 'The name of the function that GPT will see as available to call',
42
+ description: 'The name of the tool that the LLM will see as available to call',
43
43
  });
44
44
  }
45
45
  if (this.data.useDescriptionInput) {
@@ -47,7 +47,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
47
47
  id: 'description',
48
48
  title: 'Description',
49
49
  dataType: 'string',
50
- description: 'The description of the function that GPT will see as available to call',
50
+ description: 'The description of the tool that the LLM will see as available to call',
51
51
  });
52
52
  }
53
53
  if (this.data.useSchemaInput) {
@@ -55,7 +55,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
55
55
  id: 'schema',
56
56
  title: 'Schema',
57
57
  dataType: 'object',
58
- description: 'The schema of the function that GPT will see as available to call',
58
+ description: 'The schema of the tool that the LLM will see as available to call',
59
59
  });
60
60
  }
61
61
  // Extract inputs from promptText, everything like {{input}}
@@ -81,7 +81,7 @@ export class GptFunctionNodeImpl extends NodeImpl {
81
81
  id: 'function',
82
82
  title: 'Function',
83
83
  dataType: 'gpt-function',
84
- description: 'The GPT function that can be called by the LLM.',
84
+ description: 'The tool that can be called by the LLM.',
85
85
  },
86
86
  ];
87
87
  }
@@ -127,10 +127,10 @@ export class GptFunctionNodeImpl extends NodeImpl {
127
127
  static getUIData() {
128
128
  return {
129
129
  infoBoxBody: dedent `
130
- Defines a GPT function, which is a method that the LLM can call in its responses.
130
+ Defines a tool, which is a method that the LLM can call in its responses.
131
131
  `,
132
- infoBoxTitle: 'GPT Function Node',
133
- contextMenuTitle: 'GPT Function',
132
+ infoBoxTitle: 'Tool Node',
133
+ contextMenuTitle: 'Tool',
134
134
  group: ['AI'],
135
135
  };
136
136
  }
@@ -166,4 +166,4 @@ export class GptFunctionNodeImpl extends NodeImpl {
166
166
  };
167
167
  }
168
168
  }
169
- export const gptFunctionNode = nodeDefinition(GptFunctionNodeImpl, 'GPT Function');
169
+ export const gptFunctionNode = nodeDefinition(GptFunctionNodeImpl, 'Tool');
@@ -5,6 +5,7 @@ import {} from '../../index.js';
5
5
  import { dedent } from 'ts-dedent';
6
6
  import { nodeDefinition } from '../NodeDefinition.js';
7
7
  import { coerceType } from '../../utils/coerceType.js';
8
+ import {} from '../ProcessContext.js';
8
9
  export class UserInputNodeImpl extends NodeImpl {
9
10
  static create() {
10
11
  const chartNode = {
@@ -89,21 +90,18 @@ export class UserInputNodeImpl extends NodeImpl {
89
90
  group: ['Input/Output'],
90
91
  };
91
92
  }
92
- async process() {
93
+ async process(inputs, context) {
94
+ const questions = this.data.useInput ? coerceType(inputs['questions'], 'string[]') : [this.data.prompt];
95
+ const renderingFormat = this.data.renderingFormat === 'preformatted' ? 'text' : 'markdown';
96
+ const response = await context.requestUserInput(questions, renderingFormat);
93
97
  return {
94
- ['output']: undefined,
95
- ['questionsAndAnswers']: undefined,
96
- };
97
- }
98
- getOutputValuesFromUserInput(questions, answers) {
99
- const questionsList = this.data.useInput
100
- ? coerceType(questions['questions'], 'string[]')
101
- : [this.data.prompt];
102
- return {
103
- ['output']: answers,
98
+ ['output']: {
99
+ type: 'string[]',
100
+ value: response.value,
101
+ },
104
102
  ['questionsAndAnswers']: {
105
103
  type: 'string[]',
106
- value: zip(questionsList, answers.value).map(([q, a]) => `${q}\n${a}`),
104
+ value: zip(questions, response.value).map(([q, a]) => `${q}\n${a}`),
107
105
  },
108
106
  };
109
107
  }
@@ -84,7 +84,7 @@ class ChatAidonNodeImpl extends ChatNodeImpl {
84
84
  const customHeaders = schemaDetail.headers; // Moved this line up to the loop
85
85
  // Check if custom headers are set and are of type string
86
86
  if (customHeaders && typeof customHeaders === "string") {
87
- let parsedCustomHeaders = JSON.parse(customHeaders);
87
+ const parsedCustomHeaders = JSON.parse(customHeaders);
88
88
  headers = {
89
89
  ...headers,
90
90
  ...parsedCustomHeaders
@@ -129,7 +129,7 @@ class ChatAidonNodeImpl extends ChatNodeImpl {
129
129
  //call the tool(s) to get the results to add to the message
130
130
  for (const functionCall of functionCalls) {
131
131
  // Find the schema detail that contains the function name
132
- const toolSchema = toolSchemas.find(detail => detail.name == functionCall.name);
132
+ const toolSchema = toolSchemas.find(detail => detail.name === functionCall.name);
133
133
  if (!toolSchema) {
134
134
  throw new Error(`Function ${functionCall.name} not found in any schema`);
135
135
  }
@@ -181,7 +181,7 @@ const createPluginNodeImpl = (chatNode) => {
181
181
  impl.chartNode.data = data; // Ensure data is set correctly in the base class
182
182
  const outputs = impl.getOutputDefinitions();
183
183
  return outputs.filter(output => {
184
- return !(output.id === 'function-calls');
184
+ return output.id !== 'function-calls';
185
185
  });
186
186
  },
187
187
  getEditors(data) {
@@ -56,7 +56,7 @@ export const anthropicModels = {
56
56
  },
57
57
  displayName: 'Claude 3 Opus',
58
58
  },
59
- 'claude-3-5-sonnet-20240620': {
59
+ 'claude-3-5-sonnet-latest': {
60
60
  maxTokens: 200_000,
61
61
  cost: {
62
62
  prompt: 3e-6,
@@ -64,19 +64,36 @@ export const anthropicModels = {
64
64
  },
65
65
  displayName: 'Claude 3.5 Sonnet',
66
66
  },
67
+ 'claude-3-5-haiku-latest': {
68
+ maxTokens: 200_000,
69
+ cost: {
70
+ prompt: 0.8e-6,
71
+ completion: 4e-6,
72
+ },
73
+ displayName: 'Claude 3.5 Haiku',
74
+ },
75
+ 'claude-3-7-sonnet-latest': {
76
+ maxTokens: 200_000,
77
+ cost: {
78
+ prompt: 3e-6,
79
+ completion: 15e-6,
80
+ },
81
+ displayName: 'Claude 3.7 Sonnet',
82
+ },
67
83
  };
68
84
  export const anthropicModelOptions = Object.entries(anthropicModels).map(([id, { displayName }]) => ({
69
85
  value: id,
70
86
  label: displayName,
71
87
  }));
72
- export async function* streamChatCompletions({ apiKey, signal, ...rest }) {
88
+ export async function* streamChatCompletions({ apiEndpoint, apiKey, signal, ...rest }) {
73
89
  const defaultSignal = new AbortController().signal;
74
- const response = await fetchEventSource('https://api.anthropic.com/v1/complete', {
90
+ const response = await fetchEventSource(`${apiEndpoint}/completions`, {
75
91
  method: 'POST',
76
92
  headers: {
77
93
  'Content-Type': 'application/json',
78
94
  'x-api-key': apiKey,
79
95
  'anthropic-version': '2023-06-01',
96
+ 'anthropic-dangerous-direct-browser-access': 'true',
80
97
  },
81
98
  body: JSON.stringify({
82
99
  ...rest,
@@ -110,15 +127,16 @@ export async function* streamChatCompletions({ apiKey, signal, ...rest }) {
110
127
  throw new AnthropicError(`No chunks received. Response: ${JSON.stringify(responseJson)}`, response, responseJson);
111
128
  }
112
129
  }
113
- export async function callMessageApi({ apiKey, signal, tools, ...rest }) {
130
+ export async function callMessageApi({ apiEndpoint, apiKey, signal, tools, beta, ...rest }) {
114
131
  const defaultSignal = new AbortController().signal;
115
- const response = await fetch('https://api.anthropic.com/v1/messages', {
132
+ const response = await fetch(`${apiEndpoint}/messages`, {
116
133
  method: 'POST',
117
134
  headers: {
118
135
  'Content-Type': 'application/json',
119
136
  'x-api-key': apiKey,
120
137
  'anthropic-version': '2023-06-01',
121
- 'anthropic-beta': tools ? 'tools-2024-04-04' : 'messages-2023-12-15',
138
+ 'anthropic-dangerous-direct-browser-access': 'true',
139
+ ...(beta ? { 'anthropic-beta': beta } : {}),
122
140
  },
123
141
  body: JSON.stringify({
124
142
  ...rest,
@@ -133,16 +151,17 @@ export async function callMessageApi({ apiKey, signal, tools, ...rest }) {
133
151
  }
134
152
  return responseJson;
135
153
  }
136
- export async function* streamMessageApi({ apiKey, signal, ...rest }) {
154
+ export async function* streamMessageApi({ apiEndpoint, apiKey, signal, beta, ...rest }) {
137
155
  // Use the Messages API for Claude 3 models
138
156
  const defaultSignal = new AbortController().signal;
139
- const response = await fetchEventSource('https://api.anthropic.com/v1/messages', {
157
+ const response = await fetchEventSource(`${apiEndpoint}/messages`, {
140
158
  method: 'POST',
141
159
  headers: {
142
160
  'Content-Type': 'application/json',
143
161
  'x-api-key': apiKey,
144
162
  'anthropic-version': '2023-06-01',
145
- 'anthropic-beta': 'messages-2023-12-15',
163
+ 'anthropic-dangerous-direct-browser-access': 'true',
164
+ ...(beta ? { 'anthropic-beta': beta } : {}),
146
165
  },
147
166
  body: JSON.stringify({
148
167
  ...rest,
@@ -157,7 +176,7 @@ export async function* streamMessageApi({ apiKey, signal, ...rest }) {
157
176
  if (chunk === '[message_stop]') {
158
177
  return;
159
178
  }
160
- else if (/\[\w+\]/.test(chunk)) {
179
+ else if (/^\[\w+\]$/.test(chunk)) {
161
180
  nextDataType = chunk.slice(1, -1);
162
181
  continue;
163
182
  }
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_CHAT_NODE_TIMEOUT } from '../../utils/defaults.js';
1
2
  // https://github.com/openai/openai-node/issues/18#issuecomment-1518715285
2
3
  export class EventSourceResponse extends Response {
3
4
  name;
@@ -24,7 +25,7 @@ export class EventSourceResponse extends Response {
24
25
  const reader = this.streams.eventStream.getReader();
25
26
  try {
26
27
  while (true) {
27
- const { done, value } = await this.raceWithTimeout(reader.read());
28
+ const { done, value } = await this.raceWithTimeout(reader.read(), DEFAULT_CHAT_NODE_TIMEOUT);
28
29
  if (done) {
29
30
  break;
30
31
  }
@@ -36,7 +37,7 @@ export class EventSourceResponse extends Response {
36
37
  }
37
38
  }
38
39
  async raceWithTimeout(promise, timeout = 5000) {
39
- // eslint-disable-next-line no-async-promise-executor -- Error handled correctly
40
+ // eslint-disable-next-line no-async-promise-executor,@typescript-eslint/no-misused-promises -- Error handled correctly
40
41
  return new Promise(async (resolve, reject) => {
41
42
  const timer = setTimeout(() => {
42
43
  reject(new Error('Timeout: API response took too long.'));