@@ -7,7 +7,6 @@ import { StructuredTool } from '@langchain/core/tools'
7
7
import { ICommonObject , IDatabaseEntity , INode , INodeData , INodeOptionsValue , INodeParams } from '../../../src/Interface'
8
8
import { availableDependencies , defaultAllowBuiltInDep , getCredentialData , getCredentialParam } from '../../../src/utils'
9
9
import { v4 as uuidv4 } from 'uuid'
10
- import { CustomChainHandler } from '../../../src'
11
10
12
11
class ChatflowTool_Tools implements INode {
13
12
label : string
@@ -24,7 +23,7 @@ class ChatflowTool_Tools implements INode {
24
23
constructor ( ) {
25
24
this . label = 'Chatflow Tool'
26
25
this . name = 'ChatflowTool'
27
- this . version = 4 .0
26
+ this . version = 5 .0
28
27
this . type = 'ChatflowTool'
29
28
this . icon = 'chatflowTool.svg'
30
29
this . category = 'Tools'
@@ -58,6 +57,12 @@ class ChatflowTool_Tools implements INode {
58
57
placeholder :
59
58
'State of the Union QA - useful for when you need to ask questions about the most recent state of the union address.'
60
59
} ,
60
+ {
61
+ label : 'Return Direct' ,
62
+ name : 'returnDirect' ,
63
+ type : 'boolean' ,
64
+ optional : true
65
+ } ,
61
66
{
62
67
label : 'Override Config' ,
63
68
name : 'overrideConfig' ,
@@ -135,6 +140,7 @@ class ChatflowTool_Tools implements INode {
135
140
const _name = nodeData . inputs ?. name as string
136
141
const description = nodeData . inputs ?. description as string
137
142
const useQuestionFromChat = nodeData . inputs ?. useQuestionFromChat as boolean
143
+ const returnDirect = nodeData . inputs ?. returnDirect as boolean
138
144
const customInput = nodeData . inputs ?. customInput as string
139
145
const overrideConfig =
140
146
typeof nodeData . inputs ?. overrideConfig === 'string' &&
@@ -168,6 +174,7 @@ class ChatflowTool_Tools implements INode {
168
174
name,
169
175
baseURL,
170
176
description,
177
+ returnDirect,
171
178
chatflowid : selectedChatflowId ,
172
179
startNewSession,
173
180
headers,
@@ -206,6 +213,7 @@ class ChatflowTool extends StructuredTool {
206
213
constructor ( {
207
214
name,
208
215
description,
216
+ returnDirect,
209
217
input,
210
218
chatflowid,
211
219
startNewSession,
@@ -215,6 +223,7 @@ class ChatflowTool extends StructuredTool {
215
223
} : {
216
224
name : string
217
225
description : string
226
+ returnDirect : boolean
218
227
input : string
219
228
chatflowid : string
220
229
startNewSession : boolean
@@ -231,6 +240,7 @@ class ChatflowTool extends StructuredTool {
231
240
this . headers = headers
232
241
this . chatflowid = chatflowid
233
242
this . overrideConfig = overrideConfig
243
+ this . returnDirect = returnDirect
234
244
}
235
245
236
246
async call (
@@ -249,15 +259,6 @@ class ChatflowTool extends StructuredTool {
249
259
} catch ( e ) {
250
260
throw new Error ( `Received tool input did not match expected schema: ${ JSON . stringify ( arg ) } ` )
251
261
}
252
- // iterate over the callbacks and the sse streamer
253
- if ( config . callbacks instanceof CallbackManager ) {
254
- const callbacks = config . callbacks . handlers
255
- for ( let i = 0 ; i < callbacks . length ; i += 1 ) {
256
- if ( callbacks [ i ] instanceof CustomChainHandler ) {
257
- ; ( callbacks [ i ] as any ) . sseStreamer = undefined
258
- }
259
- }
260
- }
261
262
const callbackManager_ = await CallbackManager . configure (
262
263
config . callbacks ,
263
264
this . callbacks ,
@@ -283,6 +284,9 @@ class ChatflowTool extends StructuredTool {
283
284
await runManager ?. handleToolError ( e )
284
285
throw e
285
286
}
287
+ if ( result && typeof result !== 'string' ) {
288
+ result = JSON . stringify ( result )
289
+ }
286
290
await runManager ?. handleToolEnd ( result )
287
291
return result
288
292
}
0 commit comments