MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / NodeConfigPanel

Function NodeConfigPanel

frontend-workflow/src/components/NodeConfigPanel.tsx:13–461  ·  view source on GitHub ↗
({ node, onClose, onDelete, onUpdate }: NodeConfigPanelProps)

Source from the content-addressed store, hash-verified

11}
12
13const NodeConfigPanel = ({ node, onClose, onDelete, onUpdate }: NodeConfigPanelProps) => {
14 const [config, setConfig] = useState<AgentConfig>({});
15 const [schemaKey, setSchemaKey] = useState('');
16 const [schemaValue, setSchemaValue] = useState('');
17
18 useEffect(() => {
19 if (node) {
20 // 合并默认配置和当前配置
21 const defaultConfig = node.data.agentType.defaultConfig || {};
22 const currentConfig = node.data.config || {};
23 setConfig({ ...defaultConfig, ...currentConfig });
24 }
25 }, [node]);
26
27 if (!node) return null;
28
29 const { agentType } = node.data;
30 const IconComponent = Icons[agentType.icon as keyof typeof Icons] as any;
31
32 const handleSave = () => {
33 onUpdate(node.id, config);
34 };
35
36 const handleReset = () => {
37 const defaultConfig = agentType.defaultConfig || {};
38 setConfig(defaultConfig);
39 };
40
41 const addSchemaField = () => {
42 if (schemaKey && schemaValue) {
43 setConfig({
44 ...config,
45 response_schema: {
46 ...(config.response_schema || {}),
47 [schemaKey]: schemaValue,
48 },
49 });
50 setSchemaKey('');
51 setSchemaValue('');
52 }
53 };
54
55 const removeSchemaField = (key: string) => {
56 const newSchema = { ...(config.response_schema || {}) };
57 delete newSchema[key];
58 setConfig({
59 ...config,
60 response_schema: newSchema,
61 });
62 };
63
64 const addRequiredField = (field: string) => {
65 if (field && !config.required_fields?.includes(field)) {
66 setConfig({
67 ...config,
68 required_fields: [...(config.required_fields || []), field],
69 });
70 }

Callers

nothing calls this directly

Calls 4

removeSchemaFieldFunction · 0.85
removeRequiredFieldFunction · 0.85
addRequiredFieldFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected