Skip to content

Commit

Permalink
[BUGFIX] Fix value.startsWith is not a function error (#3747)
Browse files Browse the repository at this point in the history
* Fix value.startsWith is not a function error

* Check for empty array
  • Loading branch information
simsketch authored Jan 2, 2025
1 parent 50475f1 commit d71ad22
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/components/nodes/sequentialagents/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,25 @@ export const transformObjectPropertyToFunction = (obj: ICommonObject, state: ISe
(message) => message.additional_kwargs && message.additional_kwargs?.nodeId === parsedValue.id
)
const messageOutput = messageOutputs[messageOutputs.length - 1]
if (messageOutput) value = messageOutput.content
if (messageOutput) {
// if messageOutput.content is a string, set value to the content
if (typeof messageOutput.content === 'string') value = messageOutput.content
// if messageOutput.content is an array
else if (Array.isArray(messageOutput.content)) {
if (messageOutput.content.length === 0) {
throw new Error(`Message output content is an empty array for node ${parsedValue.id}`)
}
// Get the first element of the array
const messageOutputContentFirstElement: any = messageOutput.content[0]

if (typeof messageOutputContentFirstElement === 'string') value = messageOutputContentFirstElement
// If messageOutputContentFirstElement is an object and has a text property, set value to the text property
else if (typeof messageOutputContentFirstElement === 'object' && messageOutputContentFirstElement.text)
value = messageOutputContentFirstElement.text
// Otherwise, stringify the messageOutputContentFirstElement
else value = JSON.stringify(messageOutputContentFirstElement)
}
}
}
} catch (e) {
// do nothing
Expand Down

0 comments on commit d71ad22

Please sign in to comment.