Feat: The query variables of the subsequent operators can reference the structured variables defined in the agent operator. #10866 (#10902)

### What problem does this PR solve?

Feat: The query variables of the subsequent operators can reference the
structured variables defined in the agent operator. #10866

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-10-30 19:06:44 +08:00
committed by GitHub
parent 5674d762f7
commit 5059d3db18
12 changed files with 423 additions and 127 deletions

View File

@ -0,0 +1,44 @@
import { JSONSchema } from '@/components/jsonjoy-builder';
import { Operator } from '@/constants/agent';
import { isPlainObject } from 'lodash';
export function filterAgentStructuredOutput(
structuredOutput: JSONSchema,
operator?: string,
) {
if (typeof structuredOutput === 'boolean') {
return structuredOutput;
}
if (
structuredOutput.properties &&
isPlainObject(structuredOutput.properties)
) {
const filterByPredicate = (predicate: (value: JSONSchema) => boolean) => {
const properties = Object.entries({
...structuredOutput.properties,
}).reduce(
(pre, [key, value]) => {
if (predicate(value)) {
pre[key] = value;
}
return pre;
},
{} as Record<string, JSONSchema>,
);
return { ...structuredOutput, properties };
};
if (operator === Operator.Iteration) {
return filterByPredicate(
(value) => typeof value !== 'boolean' && value.type === 'array',
);
} else {
return filterByPredicate(
(value) => typeof value !== 'boolean' && value.type !== 'array',
);
}
}
return structuredOutput;
}