mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-25 20:02:47 +00:00
Some checks are pending
Document deploy / sync-images (push) Waiting to run
Document deploy / generate-timestamp (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.cn suffix:cn]) (push) Blocked by required conditions
Document deploy / build-images (map[domain:https://fastgpt.io suffix:io]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.cn kube_config:KUBE_CONFIG_CN suffix:cn]) (push) Blocked by required conditions
Document deploy / update-images (map[deployment:fastgpt-docs domain:https://fastgpt.io kube_config:KUBE_CONFIG_IO suffix:io]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / get-vars (push) Waiting to run
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:amd64 runs-on:ubuntu-24.04]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / build-fastgpt-images (map[arch:arm64 runs-on:ubuntu-24.04-arm]) (push) Blocked by required conditions
Build FastGPT images in Personal warehouse / release-fastgpt-images (push) Blocked by required conditions
* add manual create http toolset (#5743) * add manual create http toolset * optimize code * optimize * fix * fix * rename filename * feat: integrate ts-rest (#5741) * feat: integrate ts-rest * chore: classify core contract and pro contract * chore: update lockfile * chore: tweak dir structure * chore: tweak dir structure * update tsrest code (#5755) * doc * update tsrest code * fix http toolset (#5753) * fix http toolset * fix * perf: http toolset * fix: toolresponse result (#5760) * doc * fix: toolresponse result * fix: mongo watch * remove log * feat: integrated to minio (#5748) * feat: migrate to minio * feat: migrate apps' and dataset's avatar to minio * feat: migrate more avatars to minio * fix: lock file * feat: migrate copyright settings' logo to minio * feat: integrate minio * chore: improve code * chore: rename variables * refactor: s3 class * fix: s3 and mongo operations * chore: add session for avatar source * fix: init s3 buckets * fix: bugbot issues * expired time code * perf: avatar code * union type * export favouriteContract * empty bucket check --------- Co-authored-by: archer <545436317@qq.com> * refactor: zod schema to generate OpenAPI instead (#5771) * doc * fix: text split code (#5773) * fix: toolresponse result * remove log * stream remove * fix: text split code * fix: workflow (#5779) * fix: toolresponse result * remove log * fix: value check * fix: workflow * openapi doc * perf: bucket delete cron * doc * feat: apikey health * feat: export variables * api code move * perf: workflow performance (#5783) * perf: reactflow context * perf: workflow context split * perf: nodeList computed map * perf: nodes dependen * perf: workflow performance * workflow performance * removel og * lock * version * loop drag * reactflow size * reactflow size * fix: s3init (#5784) * doc * fix: s3init * perf: dynamic import * remove moongose dep * worker build * worker code * perf: worker build * fix: error throw * doc * doc * fix: build * fix: dockerfile * nextjs config * fix: worker * fix: build (#5791) * fix: build * vector cache code * fix: app info modal avatar upload method replace (#5787) * fix: app info modal avatar upload method replace * chore: replace all useSelectFile with useUploadAvatar * remove invalid code * add size * Update projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/render/RenderInput/templates/CommonInputForm.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update projects/app/src/pageComponents/app/detail/WorkflowComponents/context/workflowInitContext.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
174 lines
5.3 KiB
TypeScript
174 lines
5.3 KiB
TypeScript
import { getNanoid } from '../../../common/string/tools';
|
|
import type { PathDataType } from './type';
|
|
import { type RuntimeNodeItemType } from '../../workflow/runtime/type';
|
|
import { FlowNodeOutputTypeEnum, FlowNodeTypeEnum } from '../../workflow/node/constant';
|
|
import { type HttpToolConfigType } from '../type';
|
|
import { PluginSourceEnum } from '../plugin/constants';
|
|
import { jsonSchema2NodeInput, jsonSchema2NodeOutput } from '../jsonschema';
|
|
import { type StoreSecretValueType } from '../../../common/secret/type';
|
|
import { type JsonSchemaPropertiesItemType } from '../jsonschema';
|
|
import { NodeOutputKeyEnum, WorkflowIOValueTypeEnum } from '../../workflow/constants';
|
|
import { i18nT } from '../../../../web/i18n/utils';
|
|
|
|
export const getHTTPToolSetRuntimeNode = ({
|
|
name,
|
|
avatar,
|
|
baseUrl,
|
|
customHeaders,
|
|
apiSchemaStr,
|
|
toolList = [],
|
|
headerSecret
|
|
}: {
|
|
name?: string;
|
|
avatar?: string;
|
|
baseUrl?: string;
|
|
customHeaders?: string;
|
|
apiSchemaStr?: string;
|
|
toolList?: HttpToolConfigType[];
|
|
headerSecret?: StoreSecretValueType;
|
|
}): RuntimeNodeItemType => {
|
|
return {
|
|
nodeId: getNanoid(16),
|
|
flowNodeType: FlowNodeTypeEnum.toolSet,
|
|
avatar,
|
|
intro: 'HTTP Tools',
|
|
toolConfig: {
|
|
httpToolSet: {
|
|
toolList,
|
|
...(baseUrl !== undefined && { baseUrl }),
|
|
...(apiSchemaStr !== undefined && { apiSchemaStr }),
|
|
...(customHeaders !== undefined && { customHeaders }),
|
|
...(headerSecret !== undefined && { headerSecret })
|
|
}
|
|
},
|
|
inputs: [],
|
|
outputs: [],
|
|
name: name || '',
|
|
version: ''
|
|
};
|
|
};
|
|
|
|
export const getHTTPToolRuntimeNode = ({
|
|
tool,
|
|
nodeId,
|
|
avatar = 'core/app/type/httpToolsFill',
|
|
parentId
|
|
}: {
|
|
tool: Omit<HttpToolConfigType, 'path' | 'method'>;
|
|
nodeId?: string;
|
|
avatar?: string;
|
|
parentId: string;
|
|
}): RuntimeNodeItemType => {
|
|
return {
|
|
nodeId: nodeId || getNanoid(16),
|
|
flowNodeType: FlowNodeTypeEnum.tool,
|
|
avatar,
|
|
intro: tool.description,
|
|
toolConfig: {
|
|
httpTool: {
|
|
toolId: `${PluginSourceEnum.http}-${parentId}/${tool.name}`
|
|
}
|
|
},
|
|
inputs: jsonSchema2NodeInput(tool.inputSchema),
|
|
outputs: [
|
|
...jsonSchema2NodeOutput(tool.outputSchema),
|
|
{
|
|
id: NodeOutputKeyEnum.rawResponse,
|
|
key: NodeOutputKeyEnum.rawResponse,
|
|
required: true,
|
|
label: i18nT('workflow:raw_response'),
|
|
description: i18nT('workflow:tool_raw_response_description'),
|
|
valueType: WorkflowIOValueTypeEnum.any,
|
|
type: FlowNodeOutputTypeEnum.static
|
|
}
|
|
],
|
|
name: tool.name,
|
|
version: ''
|
|
};
|
|
};
|
|
|
|
export const pathData2ToolList = async (
|
|
pathData: PathDataType[]
|
|
): Promise<HttpToolConfigType[]> => {
|
|
try {
|
|
return pathData.map((pathItem) => {
|
|
const inputProperties: Record<string, JsonSchemaPropertiesItemType> = {};
|
|
const inputRequired: string[] = [];
|
|
const outputProperties: Record<string, JsonSchemaPropertiesItemType> = {};
|
|
const outputRequired: string[] = [];
|
|
|
|
if (pathItem.params && Array.isArray(pathItem.params)) {
|
|
pathItem.params.forEach((param) => {
|
|
if (param.name && param.schema) {
|
|
inputProperties[param.name] = {
|
|
type: param.schema.type || 'any',
|
|
description: param.description || ''
|
|
};
|
|
|
|
if (param.required) {
|
|
inputRequired.push(param.name);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if (pathItem.request?.content?.['application/json']?.schema) {
|
|
const requestSchema = pathItem.request.content['application/json'].schema;
|
|
|
|
if (requestSchema.properties) {
|
|
Object.entries(requestSchema.properties).forEach(([key, value]: [string, any]) => {
|
|
inputProperties[key] = {
|
|
type: value.type || 'any',
|
|
description: value.description || ''
|
|
};
|
|
});
|
|
}
|
|
|
|
if (requestSchema.required && Array.isArray(requestSchema.required)) {
|
|
inputRequired.push(...requestSchema.required);
|
|
}
|
|
}
|
|
|
|
const responseToProcess =
|
|
pathItem.response?.['200'] ||
|
|
pathItem.response?.['201'] ||
|
|
pathItem.response?.['202'] ||
|
|
pathItem.response?.default;
|
|
|
|
if (responseToProcess?.content?.['application/json']?.schema) {
|
|
const responseSchema = responseToProcess.content['application/json'].schema;
|
|
if (responseSchema.properties) {
|
|
Object.entries(responseSchema.properties).forEach(([key, value]: [string, any]) => {
|
|
outputProperties[key] = {
|
|
type: value.type || 'any',
|
|
description: value.description || ''
|
|
};
|
|
});
|
|
}
|
|
if (responseSchema.required && Array.isArray(responseSchema.required)) {
|
|
outputRequired.push(...responseSchema.required);
|
|
}
|
|
}
|
|
|
|
return {
|
|
name: pathItem.name,
|
|
description: pathItem.description || pathItem.name,
|
|
path: pathItem.path,
|
|
method: pathItem.method?.toLowerCase(),
|
|
inputSchema: {
|
|
type: 'object',
|
|
properties: inputProperties,
|
|
required: inputRequired
|
|
},
|
|
outputSchema: {
|
|
type: 'object',
|
|
properties: outputProperties,
|
|
required: outputRequired
|
|
}
|
|
};
|
|
});
|
|
} catch (error) {
|
|
console.error('Error converting API schema to tool list:', error);
|
|
return [];
|
|
}
|
|
};
|