-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor AssistantDetail component and enhance CodeEditor functionality
- Replaced BasicInfo and KnowledgeFiles components with General and Files components for improved modularity. - Introduced a new Script component and updated the layout to include Functions, enhancing the assistant's capabilities. - Enhanced CodeEditor with a responsive layout and added resize observer for better usability. - Updated styles for improved visual consistency and user experience across the assistant detail interface. These changes contribute to a more organized and user-friendly assistant detail interface, improving overall usability.
- Loading branch information
Showing
10 changed files
with
501 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
.editor { | ||
width: 100%; | ||
height: 100%; | ||
position: relative; | ||
} | ||
|
||
._local { | ||
border-radius: var(--radius) !important; | ||
overflow: hidden; | ||
} | ||
width: 100%; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
packages/xgen/pages/assistants/detail/components/Files.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { useState } from 'react' | ||
import { Table, Button, Upload, Space, Typography } from 'antd' | ||
import { UploadOutlined, DeleteOutlined } from '@ant-design/icons' | ||
import type { UploadFile } from 'antd/es/upload/interface' | ||
import styles from '../index.less' | ||
|
||
const { Title } = Typography | ||
|
||
interface FilesProps { | ||
files: UploadFile[] | ||
onFilesChange: (files: UploadFile[]) => void | ||
} | ||
|
||
// Generate 100 test files | ||
const fileTypes = [ | ||
{ ext: 'json', type: 'application/json' }, | ||
{ ext: 'yaml', type: 'application/yaml' }, | ||
{ ext: 'md', type: 'text/markdown' }, | ||
{ ext: 'js', type: 'application/javascript' }, | ||
{ ext: 'py', type: 'text/x-python' }, | ||
{ ext: 'ts', type: 'application/typescript' } | ||
] | ||
|
||
const testFiles: UploadFile[] = Array.from({ length: 100 }, (_, index) => { | ||
const fileType = fileTypes[index % fileTypes.length] | ||
return { | ||
uid: String(index + 1), | ||
name: `file_${index + 1}.${fileType.ext}`, | ||
size: Math.floor(Math.random() * 1024 * 1024 * 5), // Random size up to 5MB | ||
type: fileType.type, | ||
status: 'done' | ||
} | ||
}) | ||
|
||
export default function Files({ files: propFiles, onFilesChange }: FilesProps) { | ||
const [files, setFiles] = useState<UploadFile[]>(testFiles) | ||
|
||
const columns = [ | ||
{ | ||
title: 'Name', | ||
dataIndex: 'name', | ||
key: 'name', | ||
ellipsis: true | ||
}, | ||
{ | ||
title: 'Size', | ||
dataIndex: 'size', | ||
key: 'size', | ||
width: 120, | ||
render: (size: number) => { | ||
if (size < 1024) { | ||
return `${size} B` | ||
} else if (size < 1024 * 1024) { | ||
return `${(size / 1024).toFixed(1)} KB` | ||
} else { | ||
return `${(size / (1024 * 1024)).toFixed(1)} MB` | ||
} | ||
} | ||
}, | ||
{ | ||
title: 'Action', | ||
key: 'action', | ||
width: 80, | ||
render: (_: any, record: UploadFile) => ( | ||
<Button | ||
type='text' | ||
icon={<DeleteOutlined />} | ||
onClick={() => handleRemove(record)} | ||
style={{ color: 'var(--color_text_grey)' }} | ||
/> | ||
) | ||
} | ||
] | ||
|
||
const handleRemove = (file: UploadFile) => { | ||
const newFiles = files.filter((item) => item.uid !== file.uid) | ||
setFiles(newFiles) | ||
onFilesChange(newFiles) | ||
} | ||
|
||
const handleUpload = (info: any) => { | ||
const newFiles = [...files, ...info.fileList] | ||
setFiles(newFiles) | ||
onFilesChange(newFiles) | ||
} | ||
|
||
return ( | ||
<div className={styles.files}> | ||
<div className={styles.filesHeader}> | ||
<Title level={5} style={{ margin: 0, fontWeight: 500 }}> | ||
Assistant Files | ||
</Title> | ||
<Upload | ||
multiple | ||
fileList={[]} | ||
beforeUpload={() => false} | ||
onChange={handleUpload} | ||
showUploadList={false} | ||
> | ||
<Button type='primary' icon={<UploadOutlined />}> | ||
Upload | ||
</Button> | ||
</Upload> | ||
</div> | ||
<div className={styles.filesTable}> | ||
<Table | ||
dataSource={files} | ||
columns={columns} | ||
pagination={false} | ||
rowKey='uid' | ||
size='middle' | ||
scroll={{ y: 'calc(100vh - 64px - 24px - 48px - 48px - 48px - 72px)' }} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
} |
81 changes: 81 additions & 0 deletions
81
packages/xgen/pages/assistants/detail/components/Functions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { useState } from 'react' | ||
import Editor from 'react-monaco-editor' | ||
import { useGlobal } from '@/context/app' | ||
import vars from '@/styles/preset/vars' | ||
import styles from '../index.less' | ||
|
||
const defaultFunctions = { | ||
functions: [ | ||
{ | ||
name: 'example_function', | ||
description: 'An example function', | ||
parameters: { | ||
type: 'object', | ||
properties: { | ||
param1: { | ||
type: 'string', | ||
description: 'First parameter' | ||
}, | ||
param2: { | ||
type: 'number', | ||
description: 'Second parameter' | ||
} | ||
}, | ||
required: ['param1'] | ||
} | ||
} | ||
] | ||
} | ||
|
||
export default function Functions() { | ||
const [value, setValue] = useState(JSON.stringify(defaultFunctions, null, 2)) | ||
const global = useGlobal() | ||
const theme = global.theme === 'dark' ? 'x-dark' : 'x-light' | ||
|
||
const editorDidMount = (editor: any, monaco: any) => { | ||
monaco.editor.defineTheme('x-dark', { | ||
base: 'vs-dark', | ||
inherit: true, | ||
rules: [], | ||
colors: { | ||
'editor.background': vars[global.theme].color_bg_nav | ||
} | ||
}) | ||
|
||
monaco.editor.defineTheme('x-light', { | ||
base: 'vs', | ||
inherit: true, | ||
rules: [], | ||
colors: { | ||
'editor.background': vars[global.theme].color_bg_nav | ||
} | ||
}) | ||
|
||
monaco.editor.setTheme(theme) | ||
} | ||
|
||
return ( | ||
<div className={styles.functions}> | ||
<Editor | ||
width='100%' | ||
height='100%' | ||
language='json' | ||
theme={theme} | ||
value={value} | ||
onChange={setValue} | ||
editorDidMount={editorDidMount} | ||
options={{ | ||
wordWrap: 'on', | ||
formatOnPaste: true, | ||
formatOnType: true, | ||
renderLineHighlight: 'none', | ||
smoothScrolling: true, | ||
padding: { top: 15 }, | ||
lineNumbersMinChars: 3, | ||
minimap: { enabled: false }, | ||
scrollbar: { verticalScrollbarSize: 8, horizontalSliderSize: 8, useShadows: false } | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.