Feat: Make the variable assignment form match the type of the key.

This commit is contained in:
bill 2025-11-18 16:50:46 +08:00
parent 341e5904c8
commit ba10b64637
7 changed files with 43 additions and 16 deletions

View file

@ -81,7 +81,6 @@ export function AccordionOperators({
Operator.DataOperations,
Operator.VariableAssigner,
Operator.ListOperations,
Operator.VariableAssigner,
Operator.VariableAggregator,
]}
isCustomDropdown={isCustomDropdown}

View file

@ -4,6 +4,7 @@ import {
HoverCardTrigger,
} from '@/components/ui/hover-card';
import { cn } from '@/lib/utils';
import { getStructuredDatatype } from '@/utils/canvas-util';
import { get, isEmpty, isPlainObject } from 'lodash';
import { ChevronRight } from 'lucide-react';
import { PropsWithChildren, ReactNode, useCallback } from 'react';
@ -62,22 +63,28 @@ export function StructuredOutputSecondaryMenu({
value: option.value + `.${key}`,
};
const dataType = get(value, 'type');
const { dataType, compositeDataType } =
getStructuredDatatype(value);
if (
isEmpty(types) ||
(!isEmpty(types) &&
(types?.some((x) => x === dataType) ||
(types?.some((x) => x === compositeDataType) ||
hasSpecificTypeChild(value ?? {}, types)))
) {
return (
<li key={key} className="pl-1">
<div
onClick={handleSubMenuClick(nextOption, dataType)}
onClick={handleSubMenuClick(
nextOption,
compositeDataType,
)}
className="hover:bg-bg-card p-1 text-text-primary rounded-sm flex justify-between"
>
{key}
<span className="text-text-secondary">{dataType}</span>
<span className="text-text-secondary">
{compositeDataType}
</span>
</div>
{[JsonSchemaDataType.Object, JsonSchemaDataType.Array].some(
(x) => x === dataType,
@ -122,7 +129,7 @@ export function StructuredOutputSecondaryMenu({
side="left"
align="start"
className={cn(
'min-w-[140px] border border-border rounded-md shadow-lg p-0',
'min-w-72 border border-border rounded-md shadow-lg p-0',
)}
>
<section className="p-2">

View file

@ -81,7 +81,8 @@ function MessageForm({ node }: INextOperatorForm) {
)}
{...field}
onValueChange={field.onChange}
placeholder={t('flow.messagePlaceholder')}
placeholder={t('common.selectPlaceholder')}
allowClear
></RAGFlowSelect>
</FormControl>
</FormItem>

View file

@ -1,7 +1,7 @@
import { RAGFlowNodeType } from '@/interfaces/database/flow';
import { isEmpty } from 'lodash';
import { useMemo } from 'react';
import { ExportFileType, initialMessageValues } from '../../constant';
import { initialMessageValues } from '../../constant';
import { convertToObjectArray } from '../../utils';
export function useValues(node?: RAGFlowNodeType) {
@ -15,7 +15,6 @@ export function useValues(node?: RAGFlowNodeType) {
return {
...formData,
content: convertToObjectArray(formData.content),
output_format: formData.output_format || ExportFileType.PDF,
};
}, [node]);

View file

@ -1,3 +1,4 @@
import { getStructuredDatatype } from '@/utils/canvas-util';
import { get, isPlainObject } from 'lodash';
import { ReactNode, useCallback } from 'react';
import {
@ -106,10 +107,10 @@ export function useFindAgentStructuredOutputTypeByValue() {
if (isPlainObject(values) && properties) {
for (const [key, value] of Object.entries(properties)) {
const nextPath = path ? `${path}.${key}` : key;
const dataType = get(value, 'type');
const { dataType, compositeDataType } = getStructuredDatatype(value);
if (nextPath === target) {
return dataType;
return compositeDataType;
}
if (

View file

@ -1,9 +1,13 @@
import { JSONSchema } from '@/components/jsonjoy-builder';
import { getStructuredDatatype } from '@/utils/canvas-util';
import { get, isPlainObject, toLower } from 'lodash';
import { JsonSchemaDataType } from '../constant';
function predicate(types: string[], type: string) {
return types.some((x) => toLower(x) === toLower(type));
function predicate(types: string[], value: unknown) {
return types.some(
(x) =>
toLower(x) === toLower(getStructuredDatatype(value).compositeDataType),
);
}
export function hasSpecificTypeChild(
@ -12,7 +16,7 @@ export function hasSpecificTypeChild(
) {
if (Array.isArray(data)) {
for (const value of data) {
if (isPlainObject(value) && predicate(types, value.type)) {
if (isPlainObject(value) && predicate(types, value)) {
return true;
}
if (hasSpecificTypeChild(value, types)) {
@ -23,7 +27,11 @@ export function hasSpecificTypeChild(
if (isPlainObject(data)) {
for (const value of Object.values(data)) {
if (isPlainObject(value) && predicate(types, value.type)) {
if (
isPlainObject(value) &&
predicate(types, value) &&
get(data, 'type') !== JsonSchemaDataType.Array
) {
return true;
}

View file

@ -6,7 +6,7 @@ import {
import { BaseNode } from '@/interfaces/database/agent';
import { Edge } from '@xyflow/react';
import { isEmpty } from 'lodash';
import { get, isEmpty } from 'lodash';
import { ComponentType, ReactNode } from 'react';
export function filterAllUpstreamNodeIds(edges: Edge[], nodeIds: string[]) {
@ -87,3 +87,15 @@ export function buildNodeOutputOptions({
),
}));
}
export function getStructuredDatatype(value: Record<string, any> | unknown) {
const dataType = get(value, 'type');
const arrayItemsType = get(value, 'items.type', JsonSchemaDataType.String);
const compositeDataType =
dataType === JsonSchemaDataType.Array
? `${dataType}<${arrayItemsType}>`
: dataType;
return { dataType, compositeDataType };
}