mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-16 16:04:34 +00:00

* add dynamic inputRender (#5127) * dynamic input component * fix * fix * fix * perf: dynamic render input * update doc * perf: error catch * num input ui * fix form render (#5177) * perf: i18n check * add log * doc * Sync dataset (#5181) * perf: api dataset create (#5047) * Sync dataset (#5120) * add * wait * restructure dataset sync, update types and APIs, add sync hints, and remove legacy logic * feat: add function to retrieve real file ID from third-party doc library and rename team permission check function for clarity * fix come console * refactor: rename team dataset limit check functions for clarity, update API dataset sync limit usage, and rename root directory to "ROOT_FOLDER" * frat: update sync dataset login * fix delete.ts * feat: update pnpm-lock.yaml to include bullmq, fix comments in api.d.ts and type.d.ts, rename API file ID field, optimize dataset sync logic, and add website sync feature with related APIs * feat: update CollectionCard to support site dataset sync, add API root ID constant and init sync API * feat: add RootCollectionId constant to replace hardcoded root ID --------- Co-authored-by: dreamer6680 <146868355@qq.com> * perf: code * feat: update success message for dataset sync, revise related i18n texts, and optimize file selection logic (#5166) Co-authored-by: dreamer6680 <146868355@qq.com> * perf: select file * Sync dataset (#5180) * feat: update success message for dataset sync, revise related i18n texts, and optimize file selection logic * fix: make listfile function return rawid string --------- Co-authored-by: dreamer6680 <146868355@qq.com> * init sh * fix: ts --------- Co-authored-by: dreamer6680 <1468683855@qq.com> Co-authored-by: dreamer6680 <146868355@qq.com> * update doc * i18n --------- Co-authored-by: heheer <heheer@sealos.io> Co-authored-by: dreamer6680 <1468683855@qq.com> Co-authored-by: dreamer6680 <146868355@qq.com>
87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
import { WorkflowIOValueTypeEnum } from '../workflow/constants';
|
|
import { FlowNodeInputTypeEnum } from '../workflow/node/constant';
|
|
import type { FlowNodeInputItemType } from '../workflow/type/io';
|
|
|
|
type SchemaInputValueType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
export type JsonSchemaPropertiesItemType = {
|
|
description?: string;
|
|
type: SchemaInputValueType;
|
|
enum?: string[];
|
|
minimum?: number;
|
|
maximum?: number;
|
|
items?: { type: SchemaInputValueType };
|
|
};
|
|
export type JSONSchemaInputType = {
|
|
type: SchemaInputValueType;
|
|
properties?: Record<string, JsonSchemaPropertiesItemType>;
|
|
required?: string[];
|
|
};
|
|
|
|
export const getNodeInputTypeFromSchemaInputType = ({
|
|
type,
|
|
arrayItems
|
|
}: {
|
|
type: SchemaInputValueType;
|
|
arrayItems?: { type: SchemaInputValueType };
|
|
}) => {
|
|
if (type === 'string') return WorkflowIOValueTypeEnum.string;
|
|
if (type === 'number') return WorkflowIOValueTypeEnum.number;
|
|
if (type === 'integer') return WorkflowIOValueTypeEnum.number;
|
|
if (type === 'boolean') return WorkflowIOValueTypeEnum.boolean;
|
|
if (type === 'object') return WorkflowIOValueTypeEnum.object;
|
|
|
|
if (!arrayItems) return WorkflowIOValueTypeEnum.arrayAny;
|
|
|
|
const itemType = arrayItems.type;
|
|
if (itemType === 'string') return WorkflowIOValueTypeEnum.arrayString;
|
|
if (itemType === 'number') return WorkflowIOValueTypeEnum.arrayNumber;
|
|
if (itemType === 'integer') return WorkflowIOValueTypeEnum.arrayNumber;
|
|
if (itemType === 'boolean') return WorkflowIOValueTypeEnum.arrayBoolean;
|
|
if (itemType === 'object') return WorkflowIOValueTypeEnum.arrayObject;
|
|
|
|
return WorkflowIOValueTypeEnum.arrayAny;
|
|
};
|
|
const getNodeInputRenderTypeFromSchemaInputType = ({
|
|
type,
|
|
enum: enumList,
|
|
minimum,
|
|
maximum
|
|
}: JsonSchemaPropertiesItemType) => {
|
|
if (enumList && enumList.length > 0) {
|
|
return {
|
|
value: enumList[0],
|
|
renderTypeList: [FlowNodeInputTypeEnum.select],
|
|
list: enumList.map((item) => ({ label: item, value: item }))
|
|
};
|
|
}
|
|
if (type === 'string') {
|
|
return {
|
|
renderTypeList: [FlowNodeInputTypeEnum.input]
|
|
};
|
|
}
|
|
if (type === 'number') {
|
|
return {
|
|
renderTypeList: [FlowNodeInputTypeEnum.numberInput],
|
|
max: maximum,
|
|
min: minimum
|
|
};
|
|
}
|
|
if (type === 'boolean') {
|
|
return {
|
|
renderTypeList: [FlowNodeInputTypeEnum.switch]
|
|
};
|
|
}
|
|
return { renderTypeList: [FlowNodeInputTypeEnum.JSONEditor] };
|
|
};
|
|
export const jsonSchema2NodeInput = (jsonSchema: JSONSchemaInputType): FlowNodeInputItemType[] => {
|
|
return Object.entries(jsonSchema?.properties || {}).map(([key, value]) => ({
|
|
key,
|
|
label: key,
|
|
valueType: getNodeInputTypeFromSchemaInputType({ type: value.type, arrayItems: value.items }),
|
|
description: value.description,
|
|
toolDescription: value.description || key,
|
|
required: jsonSchema?.required?.includes(key),
|
|
...getNodeInputRenderTypeFromSchemaInputType(value)
|
|
}));
|
|
};
|