feat: 为外部工具集增加全局统一 headers 配置

main
sp mac bookpro 2605 2026-07-27 17:45:16 +08:00
parent 5eed97a79c
commit 39349bfb8c
2 changed files with 13 additions and 1 deletions

View File

@ -57,6 +57,7 @@ export interface ExternalToolPluginPayload {
baseUrl: string;
authType: 'none' | 'bearer' | 'basic' | 'apiKey';
authConfig: Record<string, unknown>;
headers?: Record<string, string> | null;
apis: ExternalToolApi[];
}

View File

@ -19,8 +19,9 @@ interface ToolApiFormValue extends Omit<ExternalToolApi, 'headers' | 'parameters
routing: ToolApiRoutingFormValue;
}
interface ToolPluginFormValue extends Omit<ExternalToolPluginPayload, 'authConfig' | 'apis'> {
interface ToolPluginFormValue extends Omit<ExternalToolPluginPayload, 'authConfig' | 'apis' | 'headers'> {
authConfig?: string;
headers?: string;
apis: ToolApiFormValue[];
}
@ -185,6 +186,7 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
baseUrl: values.baseUrl.trim(),
authType: values.authType,
authConfig: parseJsonObject(values.authConfig, '认证配置', values.authType === 'none') || {},
headers: parseJsonObject(values.headers, '统一请求头', true),
apis: values.apis.map((item) => ({
name: item.name.trim(),
description: item.description.trim(),
@ -235,6 +237,7 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
baseUrl: plugin.baseUrl,
authType: plugin.authType,
authConfig: JSON.stringify(plugin.authConfig || {}, null, 2),
headers: JSON.stringify(plugin.headers || {}, null, 2),
apis: plugin.apis.map((item) => ({
name: item.name,
description: item.description,
@ -255,6 +258,7 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
baseUrl: '',
authType: 'bearer',
authConfig: JSON.stringify({ token: '' }, null, 2),
headers: JSON.stringify({}, null, 2),
apis: [{ ...EMPTY_API }],
},
);
@ -273,6 +277,13 @@ export default function ExternalToolEditor({ open, agentId, plugin, onClose, onS
<Form.Item label="工具集描述" name="description">
<Input.TextArea rows={2} placeholder="说明该工具集提供的能力" />
</Form.Item>
<Form.Item label="统一请求头JSON 或对象)" name="headers">
<Input.TextArea
rows={3}
className="agent-editor-code-input"
placeholder={'{\n "Authorization": "Bearer YOUR_TOKEN"\n}'}
/>
</Form.Item>
<div className="agent-editor-tool-grid">
<Form.Item label="认证方式" name="authType" rules={[{ required: true }]}>
<Select