diff --git a/src/components/ExternalToolEditor/index.tsx b/src/components/ExternalToolEditor/index.tsx index 36e79a4..a5fc252 100644 --- a/src/components/ExternalToolEditor/index.tsx +++ b/src/components/ExternalToolEditor/index.tsx @@ -130,7 +130,8 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS }; /** - * 弹窗打开时初始化表单值。 + * 弹窗打开时初始化表单值,并同步初始化 JSON 编辑器内容, + * 确保用户首次切换到 JSON 编辑标签时即可看到完整配置。 */ const handleAfterOpenChange = (visible: boolean) => { if (!visible) return; @@ -171,11 +172,14 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS apis: [{ ...EMPTY_API }], }; - isSyncingRef.current = true; + // 初始化表单 form.setFieldsValue(initial); - setTimeout(() => { - isSyncingRef.current = false; - }, 0); + // 直接初始化 JSON 内容,避免首次进入 JSON 编辑页时显示为空或不完整 + try { + setJsonContent(JSON.stringify(formValueToJson(initial), null, 2)); + } catch (e) { + setJsonContent(JSON.stringify(initial, null, 2)); + } }; return (