Skip to content

Commit

Permalink
feat: Add component Invoke #2908 (#3067)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

feat: Add component Invoke #2908

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Oct 28, 2024
1 parent d133cc0 commit 497bc14
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 0 deletions.
36 changes: 36 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@ant-design/pro-layout": "^7.17.16",
"@antv/g6": "^5.0.10",
"@js-preview/excel": "^1.7.8",
"@monaco-editor/react": "^4.6.0",
"@tanstack/react-query": "^5.40.0",
"@tanstack/react-query-devtools": "^5.51.5",
"ahooks": "^3.7.10",
Expand Down
15 changes: 15 additions & 0 deletions web/src/assets/svg/invoke-ai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
move: 'Move',
warn: 'Warn',
action: 'Action',
s: 'S',
},
login: {
login: 'Sign in',
Expand Down Expand Up @@ -1016,6 +1017,13 @@ The above is the content you need to summarize.`,
note: 'Note',
noteDescription: 'Note',
notePlaceholder: 'Please enter a note',
invoke: 'Invoke',
invokeDescription:
'This component can invoke remote end point call. Put the output of other components as parameters or set constant parameters to call remote functions.',
url: 'Url',
method: 'Method',
timeout: 'Timeout',
headers: 'Headers',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
8 changes: 8 additions & 0 deletions web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
move: '移動',
warn: '提醒',
action: '操作',
s: '秒',
},
login: {
login: '登入',
Expand Down Expand Up @@ -965,6 +966,13 @@ export default {
note: '註解',
noteDescription: '註解',
notePlaceholder: '請輸入註釋',
invoke: 'Invoke',
invokeDescription:
'此元件可以呼叫遠端端點呼叫。將其他元件的輸出作為參數或設定常數參數來呼叫遠端函數。',
url: '網址',
method: '方法',
timeout: '超時',
headers: '請求頭',
},
footer: {
profile: '“保留所有權利 @ react”',
Expand Down
8 changes: 8 additions & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default {
move: '移动',
warn: '提醒',
action: '操作',
s: '秒',
},
login: {
login: '登录',
Expand Down Expand Up @@ -985,6 +986,13 @@ export default {
note: '注释',
noteDescription: '注释',
notePlaceholder: '请输入注释',
invoke: 'Invoke',
invokeDescription:
'该组件可以调用远程端点调用。将其他组件的输出作为参数或设置常量参数来调用远程函数。',
url: 'Url',
method: '方法',
timeout: '超时',
headers: '请求头',
},
footer: {
profile: 'All rights reserved @ React',
Expand Down
22 changes: 22 additions & 0 deletions web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReactComponent as ExeSqlIcon } from '@/assets/svg/exesql.svg';
import { ReactComponent as GithubIcon } from '@/assets/svg/github.svg';
import { ReactComponent as GoogleScholarIcon } from '@/assets/svg/google-scholar.svg';
import { ReactComponent as GoogleIcon } from '@/assets/svg/google.svg';
import { ReactComponent as InvokeIcon } from '@/assets/svg/invoke-ai.svg';
import { ReactComponent as Jin10Icon } from '@/assets/svg/jin10.svg';
import { ReactComponent as KeywordIcon } from '@/assets/svg/keyword.svg';
import { ReactComponent as NoteIcon } from '@/assets/svg/note.svg';
Expand Down Expand Up @@ -75,6 +76,7 @@ export enum Operator {
TuShare = 'TuShare',
Note = 'Note',
Crawler = 'Crawler',
Invoke = 'Invoke',
}

export const CommonOperatorList = Object.values(Operator).filter(
Expand Down Expand Up @@ -113,6 +115,7 @@ export const operatorIconMap = {
[Operator.TuShare]: TuShareIcon,
[Operator.Note]: NoteIcon,
[Operator.Crawler]: CrawlerIcon,
[Operator.Invoke]: InvokeIcon,
};

export const operatorMap: Record<
Expand Down Expand Up @@ -239,6 +242,9 @@ export const operatorMap: Record<
[Operator.Crawler]: {
backgroundColor: '#dee0e2',
},
[Operator.Invoke]: {
backgroundColor: '#dee0e2',
},
};

export const componentMenuList = [
Expand Down Expand Up @@ -332,6 +338,9 @@ export const componentMenuList = [
{
name: Operator.Crawler,
},
{
name: Operator.Invoke,
},
];

export const initialRetrievalValues = {
Expand Down Expand Up @@ -509,6 +518,18 @@ export const initialCrawlerValues = {
extract_type: 'markdown',
};

export const initialInvokeValues = {
url: 'http://',
method: 'GET',
timeout: 60,
headers: `{
"Accept": "*/*",
"Cache-Control": "no-cache",
"Connection": "keep-alive"
}`,
proxy: 'http://',
};

export const CategorizeAnchorPointPositions = [
{ top: 1, right: 34 },
{ top: 8, right: 18 },
Expand Down Expand Up @@ -621,6 +642,7 @@ export const NodeMap = {
[Operator.TuShare]: 'ragNode',
[Operator.Note]: 'noteNode',
[Operator.Crawler]: 'ragNode',
[Operator.Invoke]: 'ragNode',
};

export const LanguageOptions = [
Expand Down
4 changes: 4 additions & 0 deletions web/src/pages/flow/flow-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import GenerateForm from '../form/generate-form';
import GithubForm from '../form/github-form';
import GoogleForm from '../form/google-form';
import GoogleScholarForm from '../form/google-scholar-form';
import InvokeForm from '../form/invoke-form';
import Jin10Form from '../form/jin10-form';
import KeywordExtractForm from '../form/keyword-extract-form';
import MessageForm from '../form/message-form';
Expand Down Expand Up @@ -74,6 +75,9 @@ const FormMap = {
[Operator.Jin10]: Jin10Form,
[Operator.TuShare]: TuShareForm,
[Operator.Crawler]: CrawlerForm,
[Operator.Invoke]: InvokeForm,
[Operator.Concentrator]: <></>,
[Operator.Note]: <></>,
};

const EmptyContent = () => <div></div>;
Expand Down
119 changes: 119 additions & 0 deletions web/src/pages/flow/form/invoke-form/dynamic-variables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { EditableCell, EditableRow } from '@/components/editable-cell';
import { useTranslate } from '@/hooks/common-hooks';
import { DeleteOutlined } from '@ant-design/icons';
import { Button, Flex, Input, Select, Table, TableProps } from 'antd';
import { useBuildComponentIdSelectOptions } from '../../hooks';
import { IInvokeVariable } from '../../interface';
import { useHandleOperateParameters } from './hooks';

import { trim } from 'lodash';
import styles from './index.less';

interface IProps {
nodeId?: string;
}

const components = {
body: {
row: EditableRow,
cell: EditableCell,
},
};

const DynamicVariables = ({ nodeId }: IProps) => {
const { t } = useTranslate('flow');

const options = useBuildComponentIdSelectOptions(nodeId);
const {
dataSource,
handleAdd,
handleRemove,
handleSave,
handleComponentIdChange,
handleValueChange,
} = useHandleOperateParameters(nodeId!);

const columns: TableProps<IInvokeVariable>['columns'] = [
{
title: t('key'),
dataIndex: 'key',
key: 'key',
// width: 40,
onCell: (record: IInvokeVariable) => ({
record,
editable: true,
dataIndex: 'key',
title: 'key',
handleSave,
}),
},
{
title: t('componentId'),
dataIndex: 'component_id',
key: 'component_id',
align: 'center',
width: 140,
render(text, record) {
return (
<Select
style={{ width: '100%' }}
allowClear
options={options}
value={text}
disabled={trim(record.value) !== ''}
onChange={handleComponentIdChange(record)}
/>
);
},
},
{
title: t('value'),
dataIndex: 'value',
key: 'value',
align: 'center',
width: 140,
render(text, record) {
return (
<Input
value={text}
disabled={!!record.component_id}
onChange={handleValueChange(record)}
/>
);
},
},
{
title: t('operation'),
dataIndex: 'operation',
width: 20,
key: 'operation',
align: 'center',
fixed: 'right',
render(_, record) {
return <DeleteOutlined onClick={handleRemove(record.id)} />;
},
},
];

return (
<section>
<Flex justify="end">
<Button size="small" onClick={handleAdd}>
{t('add')}
</Button>
</Flex>
<Table
dataSource={dataSource}
columns={columns}
rowKey={'id'}
className={styles.variableTable}
components={components}
rowClassName={() => styles.editableRow}
scroll={{ x: true }}
bordered
/>
</section>
);
};

export default DynamicVariables;
Loading

0 comments on commit 497bc14

Please sign in to comment.