Feat: Filter structured output data directly during the rendering stage. #10866 (#10958)

### What problem does this PR solve?

Feat: Filter structured output data directly during the rendering stage.
#10866

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-11-03 14:48:35 +08:00
committed by GitHub
parent 256b0fb19c
commit 5a88c01111
5 changed files with 41 additions and 111 deletions

View File

@ -2,64 +2,6 @@ import { JSONSchema } from '@/components/jsonjoy-builder';
import { get, isPlainObject } from 'lodash';
import { JsonSchemaDataType } from '../constant';
// Loop operators can only accept variables of type list.
// Recursively traverse the JSON schema, keeping attributes with type "array" and discarding others.
export function filterLoopOperatorInput(
structuredOutput: JSONSchema,
type: string,
path = [],
) {
if (typeof structuredOutput === 'boolean') {
return structuredOutput;
}
if (
structuredOutput.properties &&
isPlainObject(structuredOutput.properties)
) {
const properties = Object.entries({
...structuredOutput.properties,
}).reduce(
(pre, [key, value]) => {
if (
typeof value !== 'boolean' &&
(value.type === type || hasArrayChild(value))
) {
pre[key] = filterLoopOperatorInput(value, type, path);
}
return pre;
},
{} as Record<string, JSONSchema>,
);
return { ...structuredOutput, properties };
}
return structuredOutput;
}
export function filterAgentStructuredOutput(
structuredOutput: JSONSchema,
type?: string,
) {
if (typeof structuredOutput === 'boolean') {
return structuredOutput;
}
if (
structuredOutput.properties &&
isPlainObject(structuredOutput.properties)
) {
if (type) {
return filterLoopOperatorInput(structuredOutput, type);
}
return structuredOutput;
}
return structuredOutput;
}
export function hasSpecificTypeChild(
data: Record<string, any> | Array<any>,
type: string,