Skip to content

Commit

Permalink
fix type conversion from list to dict during filter empty value (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijianma authored Nov 11, 2024
1 parent 937a108 commit 45163ec
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/agentscope/studio/static/js/workstation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,18 @@ function toggleDraggable(element) {

function filterEmptyValues(obj) {
return Object.entries(obj).reduce((acc, [key, value]) => {
if (typeof value === 'object' && value !== null) {
if (Array.isArray(value)) {
const filteredArray = value.map(item => {
if (typeof item === 'object' && item !== null) {
return filterEmptyValues(item);
}
return item !== '' ? item : null;
}).filter(item => item !== null);

if (filteredArray.length > 0) {
acc[key] = filteredArray;
}
} else if (typeof value === 'object' && value !== null) {
const filteredNestedObj = filterEmptyValues(value);
if (Object.keys(filteredNestedObj).length > 0) {
acc[key] = filteredNestedObj;
Expand Down

0 comments on commit 45163ec

Please sign in to comment.