Feat: Add a form for variable aggregation operators #10427 (#11095)

### What problem does this PR solve?

Feat: Add a form for variable aggregation operators #10427

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-11-07 11:44:22 +08:00
committed by GitHub
parent 34283d4db4
commit a880beb1f6
11 changed files with 289 additions and 22 deletions

View File

@ -1,6 +1,10 @@
import { get } from 'lodash';
import { get, isPlainObject } from 'lodash';
import { ReactNode, useCallback } from 'react';
import { AgentStructuredOutputField, Operator } from '../constant';
import {
AgentStructuredOutputField,
JsonSchemaDataType,
Operator,
} from '../constant';
import useGraphStore from '../store';
function getNodeId(value: string) {
@ -82,3 +86,70 @@ export function useFindAgentStructuredOutputLabel() {
return findAgentStructuredOutputLabel;
}
export function useFindAgentStructuredOutputTypeByValue() {
const { getOperatorTypeFromId } = useGraphStore((state) => state);
const filterStructuredOutput = useGetStructuredOutputByValue();
const findTypeByValue = useCallback(
(
values: unknown,
target: string,
path: string = '',
): string | undefined => {
const properties =
get(values, 'properties') || get(values, 'items.properties');
if (isPlainObject(values) && properties) {
for (const [key, value] of Object.entries(properties)) {
const nextPath = path ? `${path}.${key}` : key;
const dataType = get(value, 'type');
if (nextPath === target) {
return dataType;
}
if (
[JsonSchemaDataType.Object, JsonSchemaDataType.Array].some(
(x) => x === dataType,
)
) {
const type = findTypeByValue(value, target, nextPath);
if (type) {
return type;
}
}
}
}
},
[],
);
const findAgentStructuredOutputTypeByValue = useCallback(
(value?: string) => {
if (!value) {
return;
}
const fields = value.split('@');
const nodeId = fields.at(0);
const jsonSchema = filterStructuredOutput(value);
if (
getOperatorTypeFromId(nodeId) === Operator.Agent &&
fields.at(1)?.startsWith(AgentStructuredOutputField)
) {
const jsonSchemaFields = fields
.at(1)
?.slice(AgentStructuredOutputField.length + 1);
if (jsonSchemaFields) {
const type = findTypeByValue(jsonSchema, jsonSchemaFields);
return type;
}
}
},
[filterStructuredOutput, findTypeByValue, getOperatorTypeFromId],
);
return findAgentStructuredOutputTypeByValue;
}