mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-30 08:35:33 +08:00
Feat: Remove the code that outputs jsonschema from the webhook.#10427 (#12297)
### What problem does this PR solve? Feat: Remove the code that outputs jsonschema from the webhook.#10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -24,8 +24,6 @@ export const FormSchema = z.object(VariableAssignerSchema);
|
|||||||
|
|
||||||
export type VariableAssignerFormSchemaType = z.infer<typeof FormSchema>;
|
export type VariableAssignerFormSchemaType = z.infer<typeof FormSchema>;
|
||||||
|
|
||||||
// const outputList = buildOutputList(initialVariableAssignerValues.outputs);
|
|
||||||
|
|
||||||
function VariableAssignerForm({ node }: INextOperatorForm) {
|
function VariableAssignerForm({ node }: INextOperatorForm) {
|
||||||
const defaultValues = useFormValues(initialDataOperationsValues, node);
|
const defaultValues = useFormValues(initialDataOperationsValues, node);
|
||||||
|
|
||||||
@ -41,10 +39,7 @@ function VariableAssignerForm({ node }: INextOperatorForm) {
|
|||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<FormWrapper>
|
<FormWrapper>
|
||||||
<DynamicVariables name="variables" label="Variables"></DynamicVariables>
|
<DynamicVariables name="variables" label="Variables"></DynamicVariables>
|
||||||
{/* <Output list={outputList} isFormRequired></Output> */}
|
|
||||||
</FormWrapper>
|
</FormWrapper>
|
||||||
{/* <DevTool control={form.control} placement="top-left" /> */}
|
|
||||||
{/* set up the dev tool */}
|
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,7 @@ import { getStructuredDatatype } from '@/utils/canvas-util';
|
|||||||
import { get, isPlainObject } from 'lodash';
|
import { get, isPlainObject } from 'lodash';
|
||||||
import { ReactNode, useCallback } from 'react';
|
import { ReactNode, useCallback } from 'react';
|
||||||
import {
|
import {
|
||||||
AgentDialogueMode,
|
|
||||||
AgentStructuredOutputField,
|
AgentStructuredOutputField,
|
||||||
BeginId,
|
|
||||||
JsonSchemaDataType,
|
JsonSchemaDataType,
|
||||||
Operator,
|
Operator,
|
||||||
} from '../constant';
|
} from '../constant';
|
||||||
@ -18,94 +16,36 @@ function getNodeId(value: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useShowSecondaryMenu() {
|
export function useShowSecondaryMenu() {
|
||||||
const { getOperatorTypeFromId, getNode } = useGraphStore((state) => state);
|
const { getOperatorTypeFromId } = useGraphStore((state) => state);
|
||||||
|
|
||||||
const showSecondaryMenu = useCallback(
|
const showSecondaryMenu = useCallback(
|
||||||
(value: string, outputLabel: string) => {
|
(value: string, outputLabel: string) => {
|
||||||
const nodeId = getNodeId(value);
|
const nodeId = getNodeId(value);
|
||||||
const operatorType = getOperatorTypeFromId(nodeId);
|
return (
|
||||||
|
getOperatorTypeFromId(nodeId) === Operator.Agent &&
|
||||||
// For Agent nodes, show secondary menu for 'structured' field
|
|
||||||
if (
|
|
||||||
operatorType === Operator.Agent &&
|
|
||||||
outputLabel === AgentStructuredOutputField
|
outputLabel === AgentStructuredOutputField
|
||||||
) {
|
);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For Begin nodes in webhook mode, show secondary menu for schema properties (body, headers, query, etc.)
|
|
||||||
if (operatorType === Operator.Begin) {
|
|
||||||
const node = getNode(nodeId);
|
|
||||||
const mode = get(node, 'data.form.mode');
|
|
||||||
if (mode === AgentDialogueMode.Webhook) {
|
|
||||||
// Check if this output field is from the schema
|
|
||||||
const outputs = get(node, 'data.form.outputs', {});
|
|
||||||
const outputField = outputs[outputLabel];
|
|
||||||
// Show secondary menu if the field is an object or has properties
|
|
||||||
return (
|
|
||||||
outputField &&
|
|
||||||
(outputField.type === 'object' ||
|
|
||||||
(outputField.properties &&
|
|
||||||
Object.keys(outputField.properties).length > 0))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
[getOperatorTypeFromId, getNode],
|
[getOperatorTypeFromId],
|
||||||
);
|
);
|
||||||
|
|
||||||
return showSecondaryMenu;
|
return showSecondaryMenu;
|
||||||
}
|
}
|
||||||
function useGetBeginOutputsOrSchema() {
|
|
||||||
const { getNode } = useGraphStore((state) => state);
|
|
||||||
|
|
||||||
const getBeginOutputs = useCallback(() => {
|
|
||||||
const node = getNode(BeginId);
|
|
||||||
const outputs = get(node, 'data.form.outputs', {});
|
|
||||||
return outputs;
|
|
||||||
}, [getNode]);
|
|
||||||
|
|
||||||
const getBeginSchema = useCallback(() => {
|
|
||||||
const node = getNode(BeginId);
|
|
||||||
const outputs = get(node, 'data.form.schema', {});
|
|
||||||
return outputs;
|
|
||||||
}, [getNode]);
|
|
||||||
|
|
||||||
return { getBeginOutputs, getBeginSchema };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useGetStructuredOutputByValue() {
|
export function useGetStructuredOutputByValue() {
|
||||||
const { getNode, getOperatorTypeFromId } = useGraphStore((state) => state);
|
const { getNode } = useGraphStore((state) => state);
|
||||||
|
|
||||||
const { getBeginOutputs } = useGetBeginOutputsOrSchema();
|
|
||||||
|
|
||||||
const getStructuredOutput = useCallback(
|
const getStructuredOutput = useCallback(
|
||||||
(value: string) => {
|
(value: string) => {
|
||||||
const nodeId = getNodeId(value);
|
const node = getNode(getNodeId(value));
|
||||||
const node = getNode(nodeId);
|
const structuredOutput = get(
|
||||||
const operatorType = getOperatorTypeFromId(nodeId);
|
node,
|
||||||
const fields = splitValue(value);
|
`data.form.outputs.${AgentStructuredOutputField}`,
|
||||||
const outputLabel = fields.at(1);
|
);
|
||||||
|
|
||||||
let structuredOutput;
|
|
||||||
if (operatorType === Operator.Agent) {
|
|
||||||
structuredOutput = get(
|
|
||||||
node,
|
|
||||||
`data.form.outputs.${AgentStructuredOutputField}`,
|
|
||||||
);
|
|
||||||
} else if (operatorType === Operator.Begin) {
|
|
||||||
// For Begin nodes in webhook mode, get the specific schema property
|
|
||||||
const outputs = getBeginOutputs();
|
|
||||||
if (outputLabel) {
|
|
||||||
structuredOutput = outputs[outputLabel];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return structuredOutput;
|
return structuredOutput;
|
||||||
},
|
},
|
||||||
[getBeginOutputs, getNode, getOperatorTypeFromId],
|
[getNode],
|
||||||
);
|
);
|
||||||
|
|
||||||
return getStructuredOutput;
|
return getStructuredOutput;
|
||||||
@ -126,14 +66,13 @@ export function useFindAgentStructuredOutputLabel() {
|
|||||||
icon?: ReactNode;
|
icon?: ReactNode;
|
||||||
}>,
|
}>,
|
||||||
) => {
|
) => {
|
||||||
|
// agent structured output
|
||||||
const fields = splitValue(value);
|
const fields = splitValue(value);
|
||||||
const operatorType = getOperatorTypeFromId(fields.at(0));
|
|
||||||
|
|
||||||
// Handle Agent structured fields
|
|
||||||
if (
|
if (
|
||||||
operatorType === Operator.Agent &&
|
getOperatorTypeFromId(fields.at(0)) === Operator.Agent &&
|
||||||
fields.at(1)?.startsWith(AgentStructuredOutputField)
|
fields.at(1)?.startsWith(AgentStructuredOutputField)
|
||||||
) {
|
) {
|
||||||
|
// is agent structured output
|
||||||
const agentOption = options.find((x) => value.includes(x.value));
|
const agentOption = options.find((x) => value.includes(x.value));
|
||||||
const jsonSchemaFields = fields
|
const jsonSchemaFields = fields
|
||||||
.at(1)
|
.at(1)
|
||||||
@ -145,19 +84,6 @@ export function useFindAgentStructuredOutputLabel() {
|
|||||||
value: value,
|
value: value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Begin webhook fields
|
|
||||||
if (operatorType === Operator.Begin && fields.at(1)) {
|
|
||||||
const fieldOption = options
|
|
||||||
.filter((x) => x.parentLabel === BeginId)
|
|
||||||
.find((x) => value.startsWith(x.value));
|
|
||||||
|
|
||||||
return {
|
|
||||||
...fieldOption,
|
|
||||||
label: fields.at(1),
|
|
||||||
value: value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[getOperatorTypeFromId],
|
[getOperatorTypeFromId],
|
||||||
);
|
);
|
||||||
@ -168,7 +94,6 @@ export function useFindAgentStructuredOutputLabel() {
|
|||||||
export function useFindAgentStructuredOutputTypeByValue() {
|
export function useFindAgentStructuredOutputTypeByValue() {
|
||||||
const { getOperatorTypeFromId } = useGraphStore((state) => state);
|
const { getOperatorTypeFromId } = useGraphStore((state) => state);
|
||||||
const filterStructuredOutput = useGetStructuredOutputByValue();
|
const filterStructuredOutput = useGetStructuredOutputByValue();
|
||||||
const { getBeginSchema } = useGetBeginOutputsOrSchema();
|
|
||||||
|
|
||||||
const findTypeByValue = useCallback(
|
const findTypeByValue = useCallback(
|
||||||
(
|
(
|
||||||
@ -211,12 +136,10 @@ export function useFindAgentStructuredOutputTypeByValue() {
|
|||||||
}
|
}
|
||||||
const fields = splitValue(value);
|
const fields = splitValue(value);
|
||||||
const nodeId = fields.at(0);
|
const nodeId = fields.at(0);
|
||||||
const operatorType = getOperatorTypeFromId(nodeId);
|
|
||||||
const jsonSchema = filterStructuredOutput(value);
|
const jsonSchema = filterStructuredOutput(value);
|
||||||
|
|
||||||
// Handle Agent structured fields
|
|
||||||
if (
|
if (
|
||||||
operatorType === Operator.Agent &&
|
getOperatorTypeFromId(nodeId) === Operator.Agent &&
|
||||||
fields.at(1)?.startsWith(AgentStructuredOutputField)
|
fields.at(1)?.startsWith(AgentStructuredOutputField)
|
||||||
) {
|
) {
|
||||||
const jsonSchemaFields = fields
|
const jsonSchemaFields = fields
|
||||||
@ -228,32 +151,13 @@ export function useFindAgentStructuredOutputTypeByValue() {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle Begin webhook fields (body, headers, query, etc.)
|
|
||||||
if (operatorType === Operator.Begin) {
|
|
||||||
const outputLabel = fields.at(1);
|
|
||||||
const schema = getBeginSchema();
|
|
||||||
if (outputLabel && schema) {
|
|
||||||
const jsonSchemaFields = fields.at(1);
|
|
||||||
if (jsonSchemaFields) {
|
|
||||||
const type = findTypeByValue(schema, jsonSchemaFields);
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
[
|
[filterStructuredOutput, findTypeByValue, getOperatorTypeFromId],
|
||||||
filterStructuredOutput,
|
|
||||||
findTypeByValue,
|
|
||||||
getBeginSchema,
|
|
||||||
getOperatorTypeFromId,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return findAgentStructuredOutputTypeByValue;
|
return findAgentStructuredOutputTypeByValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Consider merging with useFindAgentStructuredOutputLabel
|
|
||||||
export function useFindAgentStructuredOutputLabelByValue() {
|
export function useFindAgentStructuredOutputLabelByValue() {
|
||||||
const { getNode } = useGraphStore((state) => state);
|
const { getNode } = useGraphStore((state) => state);
|
||||||
|
|
||||||
|
|||||||
@ -318,8 +318,7 @@ export function useFilterQueryVariableOptionsByTypes({
|
|||||||
isAgentStructured(
|
isAgentStructured(
|
||||||
y.value,
|
y.value,
|
||||||
y.value.slice(-AgentStructuredOutputField.length),
|
y.value.slice(-AgentStructuredOutputField.length),
|
||||||
) ||
|
),
|
||||||
y.value.startsWith(BeginId), // begin node outputs
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user