Skip to content

Commit

Permalink
feat: create app by json
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jan 10, 2025
1 parent f556fbf commit 2b84533
Show file tree
Hide file tree
Showing 21 changed files with 1,026 additions and 285 deletions.
19 changes: 19 additions & 0 deletions packages/global/core/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { FlowNodeInputItemType } from '../workflow/type/io.d';
import { getAppChatConfig } from '../workflow/utils';
import { StoreNodeItemType } from '../workflow/type/node';
import { DatasetSearchModeEnum } from '../dataset/constants';
import { WorkflowTemplateBasicType } from 'core/workflow/type';
import { AppTypeEnum } from './constants';

export const getDefaultAppForm = (): AppSimpleEditFormType => {
return {
Expand Down Expand Up @@ -127,3 +129,20 @@ export const appWorkflow2Form = ({

return defaultAppForm;
};

export const getAppType = (config?: WorkflowTemplateBasicType | AppSimpleEditFormType) => {
if (!config) return '';

if ('aiSettings' in config) {
return AppTypeEnum.simple;
}

if (!('nodes' in config)) return '';
if (config.nodes.some((node) => node.flowNodeType === 'workflowStart')) {
return AppTypeEnum.workflow;
}
if (config.nodes.some((node) => node.flowNodeType === 'pluginInput')) {
return AppTypeEnum.plugin;
}
return '';
};
1 change: 1 addition & 0 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const iconPaths = {
'core/app/ttsFill': () => import('./icons/core/app/ttsFill.svg'),
'core/app/type/httpPlugin': () => import('./icons/core/app/type/httpPlugin.svg'),
'core/app/type/httpPluginFill': () => import('./icons/core/app/type/httpPluginFill.svg'),
'core/app/type/jsonImport': () => import('./icons/core/app/type/jsonImport.svg'),
'core/app/type/plugin': () => import('./icons/core/app/type/plugin.svg'),
'core/app/type/pluginFill': () => import('./icons/core/app/type/pluginFill.svg'),
'core/app/type/pluginLight': () => import('./icons/core/app/type/pluginLight.svg'),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions packages/web/components/common/Textarea/DragEditor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import React, { DragEvent, useCallback, useState } from 'react';
import { Box, Button, Flex, Textarea } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import { useSystem } from '../../../../hooks/useSystem';
import MyIcon from '../../Icon';
import { useToast } from '../../../../hooks/useToast';

type Props = {
value: string;
onChange: (value: string) => void;
placeholder?: string;
rows?: number;
File?: ({ onSelect }: { onSelect: (e: File[], sign?: any) => void }) => React.JSX.Element;
onOpen?: () => void;
};

const DragEditor = ({ value, onChange, placeholder, rows = 16, File, onOpen }: Props) => {
const { t } = useTranslation();
const { isPc } = useSystem();
const { toast } = useToast();
const [isDragging, setIsDragging] = useState(false);

const handleDragEnter = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(true);
}, []);

const handleDragLeave = useCallback((e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
setIsDragging(false);
}, []);

const readJSONFile = useCallback(
(file: File) => {
const reader = new FileReader();
reader.onload = (e) => {
if (!file.name.endsWith('.json')) {
toast({
title: t('app:not_json_file'),
status: 'error'
});
return;
}
if (e.target) {
const res = JSON.parse(e.target.result as string);
onChange(JSON.stringify(res, null, 2));
}
};
reader.readAsText(file);
},
[t, toast]
);

const onSelectFile = useCallback(
async (e: File[]) => {
const file = e[0];
readJSONFile(file);
},
[readJSONFile]
);

const handleDrop = useCallback(
async (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
const file = e.dataTransfer.files[0];
console.log(file);
readJSONFile(file);
setIsDragging(false);
},
[readJSONFile]
);

return (
<>
<Box w={['100%', '31rem']}>
{isDragging ? (
<Flex
align={'center'}
justify={'center'}
w={'full'}
h={'17.5rem'}
borderRadius={'md'}
border={'1px dashed'}
borderColor={'myGray.400'}
onDragEnter={handleDragEnter}
onDragOver={(e) => e.preventDefault()}
onDrop={handleDrop}
onDragLeave={handleDragLeave}
>
<Flex align={'center'} justify={'center'} flexDir={'column'} gap={'0.62rem'}>
<MyIcon name={'configmap'} w={'1.5rem'} color={'myGray.500'} />
<Box color={'myGray.600'} fontSize={'mini'}>
{t('app:file_recover')}
</Box>
</Flex>
</Flex>
) : (
<Box>
<Flex justify={'space-between'} align={'center'} pb={2}>
<Box fontSize={'sm'} color={'myGray.900'} fontWeight={'500'}>
{t('common:common.json_config')}
</Box>
<Button onClick={onOpen} variant={'whiteBase'} p={0}>
<Flex px={'0.88rem'} py={'0.44rem'} color={'myGray.600'} fontSize={'mini'}>
<MyIcon name={'file/uploadFile'} w={'1rem'} mr={'0.38rem'} />
{t('common:common.upload_file')}
</Flex>
</Button>
</Flex>
<Box
onDragEnter={handleDragEnter}
onDragOver={(e) => e.preventDefault()}
onDrop={handleDrop}
onDragLeave={handleDragLeave}
>
<Textarea
bg={'myGray.50'}
border={'1px solid'}
borderRadius={'md'}
borderColor={'myGray.200'}
value={value}
placeholder={
placeholder ||
(isPc
? t('app:paste_config') + '\n' + t('app:or_drag_JSON')
: t('app:paste_config'))
}
rows={rows}
onChange={(e) => onChange(e.target.value)}
/>
</Box>
</Box>
)}
</Box>
{File && <File onSelect={onSelectFile} />}
</>
);
};

export default React.memo(DragEditor);
5 changes: 5 additions & 0 deletions packages/web/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"interval.6_hours": "Every 6 Hours",
"interval.per_hour": "Every Hour",
"intro": "A comprehensive model application orchestration system that offers out-of-the-box data processing and model invocation capabilities. It allows for rapid Dataset construction and workflow orchestration through Flow visualization, enabling complex Dataset scenarios!",
"invalid_json_format": "JSON format error",
"llm_not_support_vision": "This model does not support image recognition",
"llm_use_vision": "Vision",
"llm_use_vision_tip": "After clicking on the model selection, you can see whether the model supports image recognition and the ability to control whether to start image recognition. \nAfter starting image recognition, the model will read the image content in the file link, and if the user question is less than 500 words, it will automatically parse the image in the user question.",
Expand All @@ -94,6 +95,7 @@
"open_vision_function_tip": "Models with icon switches have image recognition capabilities. \nAfter being turned on, the model will parse the pictures in the file link and automatically parse the pictures in the user's question (user question ≤ 500 words).",
"or_drag_JSON": "or drag in JSON file",
"paste_config": "Paste Configuration",
"paste_config_or_drag": "Paste config or drag JSON file here",
"permission.des.manage": "Based on write permissions, you can configure publishing channels, view conversation logs, and assign permissions to the application.",
"permission.des.read": "Use the app to have conversations",
"permission.des.write": "Can view and edit apps",
Expand Down Expand Up @@ -150,9 +152,12 @@
"type.Create workflow bot": "Create Workflow",
"type.Create workflow tip": "Build complex multi-turn dialogue AI applications through low-code methods, recommended for advanced users.",
"type.Http plugin": "HTTP Plugin",
"type.Import from json": "Import JSON",
"type.Import from json tip": "Create an application with corresponding properties by importing a JSON file",
"type.Plugin": "Plugin",
"type.Simple bot": "Simple App",
"type.Workflow bot": "Workflow",
"type_not_recognized": "App type not recognized",
"upload_file_max_amount": "Maximum File Quantity",
"upload_file_max_amount_tip": "Maximum number of files uploaded in a single round of conversation",
"variable.select type_desc": "You can define a global variable that does not need to be filled in by the user.\n\nThe value of this variable can come from the API interface, the Query of the shared link, or assigned through the [Variable Update] module.",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
"core.app.Config schedule plan": "Configure Scheduled Execution",
"core.app.Config whisper": "Configure Voice Input",
"core.app.Config_auto_execute": "Click to configure automatic execution rules",
"core.app.Create app by curl": "Create by curl",
"core.app.Interval timer config": "Scheduled Execution Configuration",
"core.app.Interval timer run": "Scheduled Execution",
"core.app.Interval timer tip": "Can Execute App on Schedule",
Expand Down
5 changes: 5 additions & 0 deletions packages/web/i18n/zh-CN/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"interval.6_hours": "每6小时",
"interval.per_hour": "每小时",
"intro": "是一个大模型应用编排系统,提供开箱即用的数据处理、模型调用等能力,可以快速的构建知识库并通过 Flow 可视化进行工作流编排,实现复杂的知识库场景!",
"invalid_json_format": "JSON 格式错误",
"llm_not_support_vision": "该模型不支持图片识别",
"llm_use_vision": "图片识别",
"llm_use_vision_tip": "点击模型选择后,可以看到模型是否支持图片识别以及控制是否启动图片识别的能力。启动图片识别后,模型会读取文件链接里图片内容,并且如果用户问题少于 500 字,会自动解析用户问题中的图片。",
Expand All @@ -94,6 +95,7 @@
"open_vision_function_tip": "有图示开关的模型即拥有图片识别能力。若开启,模型会解析文件链接里的图片,并自动解析用户问题中的图片(用户问题≤500字时生效)。",
"or_drag_JSON": "或拖入JSON文件",
"paste_config": "粘贴配置",
"paste_config_or_drag": "粘贴配置或拖入 JSON 文件",
"permission.des.manage": "写权限基础上,可配置发布渠道、查看对话日志、分配该应用权限",
"permission.des.read": "可使用该应用进行对话",
"permission.des.write": "可查看和编辑应用",
Expand Down Expand Up @@ -150,9 +152,12 @@
"type.Create workflow bot": "创建工作流",
"type.Create workflow tip": "通过低代码的方式,构建逻辑复杂的多轮对话 AI 应用,推荐高级玩家使用",
"type.Http plugin": "HTTP 插件",
"type.Import from json": "导入 JSON 配置",
"type.Import from json tip": "通过粘贴或导入 JSON 文件,直接创建对应属性的应用",
"type.Plugin": "插件",
"type.Simple bot": "简易应用",
"type.Workflow bot": "工作流",
"type_not_recognized": "未识别到应用类型",
"upload_file_max_amount": "最大文件数量",
"upload_file_max_amount_tip": "单轮对话中最大上传文件数量",
"variable.select type_desc": "可以为工作流定义全局变量,常用临时缓存。赋值的方式包括:\n1. 从对话页面的 query 参数获取。\n2. 通过 API 的 variables 对象传递。\n3. 通过【变量更新】节点进行赋值。",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/zh-CN/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
"core.app.Config schedule plan": "配置定时执行",
"core.app.Config whisper": "配置语音输入",
"core.app.Config_auto_execute": "点击配置自动执行规则",
"core.app.Create app by curl": "通过 curl 创建",
"core.app.Interval timer config": "定时执行配置",
"core.app.Interval timer run": "定时执行",
"core.app.Interval timer tip": "可定时执行应用",
Expand Down
5 changes: 5 additions & 0 deletions packages/web/i18n/zh-Hant/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"interval.6_hours": "每 6 小時",
"interval.per_hour": "每小時",
"intro": "FastGPT 是一個基於大型語言模型的知識庫平臺,提供開箱即用的資料處理、向量檢索和視覺化 AI 工作流程編排等功能,讓您可以輕鬆開發和部署複雜的問答系統,而無需繁瑣的設定或配置。",
"invalid_json_format": "JSON 格式錯誤",
"llm_not_support_vision": "這個模型不支援圖片辨識",
"llm_use_vision": "圖片辨識",
"llm_use_vision_tip": "點選模型選擇後,可以看到模型是否支援圖片辨識以及控制是否啟用圖片辨識的功能。啟用圖片辨識後,模型會讀取檔案連結中的圖片內容,並且如果使用者問題少於 500 字,會自動解析使用者問題中的圖片。",
Expand All @@ -94,6 +95,7 @@
"open_vision_function_tip": "有圖示開關的模型即擁有圖片辨識功能。若開啟,模型會解析檔案連結中的圖片,並自動解析使用者問題中的圖片(使用者問題 ≤ 500 字時生效)。",
"or_drag_JSON": "或拖曳 JSON 檔案",
"paste_config": "貼上設定",
"paste_config_or_drag": "貼上配置或拖入 JSON 文件",
"permission.des.manage": "在寫入權限基礎上,可以設定發布通道、檢視對話紀錄、分配這個應用程式的權限",
"permission.des.read": "可以使用這個應用程式進行對話",
"permission.des.write": "可以檢視和編輯應用程式",
Expand Down Expand Up @@ -150,9 +152,12 @@
"type.Create workflow bot": "建立工作流程",
"type.Create workflow tip": "透過低程式碼的方式,建立邏輯複雜的多輪對話 AI 應用程式,建議進階使用者使用",
"type.Http plugin": "HTTP 外掛",
"type.Import from json": "導入 JSON 配置",
"type.Import from json tip": "透過貼上或匯入 JSON 文件,直接建立對應屬性的應用",
"type.Plugin": "外掛",
"type.Simple bot": "簡易應用程式",
"type.Workflow bot": "工作流程",
"type_not_recognized": "未識別到應用程式類型",
"upload_file_max_amount": "最大檔案數量",
"upload_file_max_amount_tip": "單輪對話中最大上傳檔案數量",
"variable.select type_desc": "可以為工作流程定義全域變數,常用於暫存。賦值的方式包括:\n1. 從對話頁面的 query 參數取得。\n2. 透過 API 的 variables 物件傳遞。\n3. 透過【變數更新】節點進行賦值。",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/zh-Hant/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@
"core.app.Config schedule plan": "設定排程執行",
"core.app.Config whisper": "設定語音輸入",
"core.app.Config_auto_execute": "點選配置自動執行規則",
"core.app.Create app by curl": "透過 curl 創建",
"core.app.Interval timer config": "排程執行設定",
"core.app.Interval timer run": "排程執行",
"core.app.Interval timer tip": "可排程執行應用程式",
Expand Down
12 changes: 12 additions & 0 deletions projects/app/src/pages/app/detail/components/SimpleApp/AppCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { postTransition2Workflow } from '@/web/core/app/api/app';
import { form2AppWorkflow } from '@/web/core/app/utils';
import { SimpleAppSnapshotType } from './useSnapshots';
import { ExportPopover } from '../WorkflowComponents/AppCard';

const AppCard = ({
appForm,
Expand Down Expand Up @@ -118,6 +119,7 @@ const AppCard = ({
)}
{appDetail.permission.isOwner && (
<MyMenu
size={'xs'}
Button={
<IconButton
variant={'whitePrimary'}
Expand All @@ -129,6 +131,16 @@ const AppCard = ({
menuList={[
{
children: [
{
label: (
<Flex>
{ExportPopover({
appName: appDetail.name,
appForm
})}
</Flex>
)
},
{
icon: 'core/app/type/workflow',
label: t('app:transition_to_workflow'),
Expand Down
Loading

0 comments on commit 2b84533

Please sign in to comment.