Skip to content

Commit 87f959a

Browse files
newfish-cmykc121914yu
authored andcommitted
fix http toolset (#5753)
* fix http toolset * fix
1 parent ba65727 commit 87f959a

File tree

11 files changed

+564
-363
lines changed

11 files changed

+564
-363
lines changed

packages/global/core/app/jsonschema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SwaggerParser from '@apidevtools/swagger-parser';
55
import yaml from 'js-yaml';
66
import type { OpenAPIV3 } from 'openapi-types';
77
import type { OpenApiJsonSchema } from './httpTools/type';
8+
import { i18nT } from '../../../web/i18n/utils';
89

910
type SchemaInputValueType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
1011
export type JsonSchemaPropertiesItemType = {
@@ -180,7 +181,7 @@ export const str2OpenApiSchema = async (yamlStr = ''): Promise<OpenApiJsonSchema
180181
.filter(Boolean) as OpenApiJsonSchema['pathData'];
181182
return { pathData, serverPath };
182183
} catch (err) {
183-
throw new Error('Invalid Schema');
184+
return Promise.reject(i18nT('common:plugin.Invalid Schema'));
184185
}
185186
};
186187
export const getSchemaValueType = (schema: { type: string; items?: { type: string } }) => {

packages/service/core/app/http.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getErrText } from '@fastgpt/global/common/error/utils';
55
import type { RequireOnlyOne } from '@fastgpt/global/common/type/utils';
66
import type { HttpToolConfigType } from '@fastgpt/global/core/app/type';
77
import { contentTypeMap, ContentTypes } from '@fastgpt/global/core/workflow/constants';
8+
import { replaceEditorVariable } from '@fastgpt/global/core/workflow/runtime/utils';
89

910
export type RunHTTPToolParams = {
1011
baseUrl: string;
@@ -32,40 +33,49 @@ const buildHttpRequest = ({
3233
staticHeaders,
3334
staticBody
3435
}: Omit<RunHTTPToolParams, 'baseUrl' | 'toolPath'>) => {
36+
const replaceVariables = (text: string) => {
37+
return replaceEditorVariable({
38+
text,
39+
nodes: [],
40+
variables: params
41+
});
42+
};
43+
3544
const body = (() => {
3645
if (!staticBody || staticBody.type === ContentTypes.none) {
37-
return ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase()) ? params : undefined;
46+
return ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase()) ? {} : undefined;
3847
}
3948

4049
if (staticBody.type === ContentTypes.json) {
41-
const staticContent = staticBody.content ? JSON.parse(staticBody.content) : {};
42-
return { ...staticContent, ...params };
50+
const contentWithReplacedVars = staticBody.content
51+
? replaceVariables(staticBody.content)
52+
: '{}';
53+
const staticContent = JSON.parse(contentWithReplacedVars);
54+
return { ...staticContent };
4355
}
4456

4557
if (staticBody.type === ContentTypes.formData) {
4658
const formData = new (require('form-data'))();
4759
staticBody.formData?.forEach(({ key, value }) => {
48-
formData.append(key, value);
49-
});
50-
Object.entries(params).forEach(([key, value]) => {
51-
formData.append(key, value);
60+
const replacedKey = replaceVariables(key);
61+
const replacedValue = replaceVariables(value);
62+
formData.append(replacedKey, replacedValue);
5263
});
5364
return formData;
5465
}
5566

5667
if (staticBody.type === ContentTypes.xWwwFormUrlencoded) {
5768
const urlencoded = new URLSearchParams();
5869
staticBody.formData?.forEach(({ key, value }) => {
59-
urlencoded.append(key, value);
60-
});
61-
Object.entries(params).forEach(([key, value]) => {
62-
urlencoded.append(key, String(value));
70+
const replacedKey = replaceVariables(key);
71+
const replacedValue = replaceVariables(value);
72+
urlencoded.append(replacedKey, replacedValue);
6373
});
6474
return urlencoded.toString();
6575
}
6676

6777
if (staticBody.type === ContentTypes.xml || staticBody.type === ContentTypes.raw) {
68-
return staticBody.content || '';
78+
return replaceVariables(staticBody.content || '');
6979
}
7080

7181
return undefined;
@@ -78,7 +88,9 @@ const buildHttpRequest = ({
7888
...(headerSecret ? getSecretValue({ storeSecret: headerSecret }) : {}),
7989
...(staticHeaders?.reduce(
8090
(acc, { key, value }) => {
81-
acc[key] = value;
91+
const replacedKey = replaceVariables(key);
92+
const replacedValue = replaceVariables(value);
93+
acc[replacedKey] = replacedValue;
8294
return acc;
8395
},
8496
{} as Record<string, string>
@@ -89,7 +101,9 @@ const buildHttpRequest = ({
89101
const staticParamsObj =
90102
staticParams?.reduce(
91103
(acc, { key, value }) => {
92-
acc[key] = value;
104+
const replacedKey = replaceVariables(key);
105+
const replacedValue = replaceVariables(value);
106+
acc[replacedKey] = replacedValue;
93107
return acc;
94108
},
95109
{} as Record<string, any>

packages/web/i18n/en/app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Add_tool": "Add tool",
33
"AutoOptimize": "Automatic optimization",
44
"Click_to_delete_this_field": "Click to delete this field",
5-
"Custom_params": "Custom parameters",
5+
"Custom_params": "input parameters",
66
"Edit_tool": "Edit tool",
77
"Filed_is_deprecated": "This field is deprecated",
88
"HTTPTools_Create_Type": "Create Type",
@@ -95,6 +95,7 @@
9595
"document_upload": "Document Upload",
9696
"edit_app": "Application details",
9797
"edit_info": "Edit",
98+
"empty_tool_tips": "Please add tools on the left side",
9899
"execute_time": "Execution Time",
99100
"export_config_successful": "Configuration copied, some sensitive information automatically filtered. Please check for any remaining sensitive data.",
100101
"export_configs": "Export",
@@ -105,12 +106,15 @@
105106
"file_upload_tip": "Once enabled, documents/images can be uploaded. Documents are retained for 7 days, images for 15 days. Using this feature may incur additional costs. To ensure a good experience, please choose an AI model with a larger context length when using this feature.",
106107
"go_to_chat": "Go to Conversation",
107108
"go_to_run": "Go to Execution",
109+
"http_toolset_add_tips": "Click the \"Add\" button to add tools",
110+
"http_toolset_config_tips": "Click \"Start Configuration\" to add tools",
108111
"image_upload": "Image Upload",
109112
"image_upload_tip": "How to activate model image recognition capabilities",
110113
"import_configs": "Import",
111114
"import_configs_failed": "Import configuration failed, please ensure the configuration is correct!",
112115
"import_configs_success": "Import Successful",
113116
"initial_form": "initial state",
117+
"input_params_tips": "Tool input parameters will not be passed directly to the request URL; they can be referenced on the right side using \"/\".",
114118
"interval.12_hours": "Every 12 Hours",
115119
"interval.2_hours": "Every 2 Hours",
116120
"interval.3_hours": "Every 3 Hours",

packages/web/i18n/zh-CN/app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Add_tool": "添加工具",
33
"AutoOptimize": "自动优化",
44
"Click_to_delete_this_field": "点击删除该字段",
5-
"Custom_params": "自定义参数",
5+
"Custom_params": "输入参数",
66
"Edit_tool": "编辑工具",
77
"Filed_is_deprecated": "该字段已弃用",
88
"HTTPTools_Create_Type": "创建方式",
@@ -98,6 +98,7 @@
9898
"edit_app": "应用详情",
9999
"edit_info": "编辑信息",
100100
"edit_param": "编辑参数",
101+
"empty_tool_tips": "请在左侧添加工具",
101102
"execute_time": "执行时间",
102103
"export_config_successful": "已复制配置,自动过滤部分敏感信息,请注意检查是否仍有敏感数据",
103104
"export_configs": "导出配置",
@@ -108,12 +109,15 @@
108109
"file_upload_tip": "开启后,可以上传文档/图片。文档保留7天,图片保留15天。使用该功能可能产生较多额外费用。为保证使用体验,使用该功能时,请选择上下文长度较大的AI模型。",
109110
"go_to_chat": "去对话",
110111
"go_to_run": "去运行",
112+
"http_toolset_add_tips": "点击添加按钮来添加工具",
113+
"http_toolset_config_tips": "点击开始配置来添加工具",
111114
"image_upload": "图片上传",
112115
"image_upload_tip": "如何启动模型图片识别能力",
113116
"import_configs": "导入配置",
114117
"import_configs_failed": "导入配置失败,请确保配置正常!",
115118
"import_configs_success": "导入成功",
116119
"initial_form": "初始状态",
120+
"input_params_tips": "工具的输入参数,不会直接传递到请求地址,可在右侧通过 \"/\" 来引用变量",
117121
"interval.12_hours": "每12小时",
118122
"interval.2_hours": "每2小时",
119123
"interval.3_hours": "每3小时",

packages/web/i18n/zh-Hant/app.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Add_tool": "添加工具",
33
"AutoOptimize": "自動優化",
44
"Click_to_delete_this_field": "點擊刪除該字段",
5-
"Custom_params": "自定義參數",
5+
"Custom_params": "輸入參數",
66
"Filed_is_deprecated": "該字段已棄用",
77
"HTTPTools_Create_Type": "創建方式",
88
"HTTPTools_Create_Type_Tip": "選擇後不支持修改",
@@ -95,6 +95,7 @@
9595
"document_upload": "文件上傳",
9696
"edit_app": "應用詳情",
9797
"edit_info": "編輯資訊",
98+
"empty_tool_tips": "請在左側添加工具",
9899
"execute_time": "執行時間",
99100
"export_config_successful": "已複製設定,自動過濾部分敏感資訊,請注意檢查是否仍有敏感資料",
100101
"export_configs": "匯出設定",
@@ -105,12 +106,15 @@
105106
"file_upload_tip": "開啟後,可以上傳文件/圖片。文件保留 7 天,圖片保留 15 天。使用這個功能可能產生較多額外費用。為了確保使用體驗,使用這個功能時,請選擇上下文長度較大的 AI 模型。",
106107
"go_to_chat": "前往對話",
107108
"go_to_run": "前往執行",
109+
"http_toolset_add_tips": "點擊添加按鈕來添加工具",
110+
"http_toolset_config_tips": "點擊開始配置來添加工具",
108111
"image_upload": "圖片上傳",
109112
"image_upload_tip": "如何啟用模型圖片辨識功能",
110113
"import_configs": "匯入設定",
111114
"import_configs_failed": "匯入設定失敗,請確認設定是否正常!",
112115
"import_configs_success": "匯入成功",
113116
"initial_form": "初始狀態",
117+
"input_params_tips": "工具的輸入參數,不會直接傳遞到請求地址,可在右側通過 \"/\" 來引用變數",
114118
"interval.12_hours": "每 12 小時",
115119
"interval.2_hours": "每 2 小時",
116120
"interval.3_hours": "每 3 小時",

0 commit comments

Comments
 (0)