Skip to content

Commit 026f737

Browse files
authored
Merge pull request #1605 from Mai-with-u/dev
Dev
2 parents 475c8da + d32be47 commit 026f737

96 files changed

Lines changed: 5128 additions & 2721 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Plan.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

bot.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def run_runner_process():
105105

106106
require_legacy_upgrade_confirmation(Path(script_dir))
107107

108+
logger.info(t("startup.worker_dir_set", script_dir=script_dir))
109+
108110
from src.main import MainSystem # noqa
109111
from src.manager.async_task_manager import async_task_manager # noqa
110112

@@ -117,9 +119,6 @@ def run_runner_process():
117119
# 设置工作目录为脚本所在目录
118120
# script_dir = os.path.dirname(os.path.abspath(__file__))
119121
# os.chdir(script_dir)
120-
logger.info(t("startup.worker_dir_set", script_dir=script_dir))
121-
122-
123122
confirm_logger = get_logger("confirm")
124123
# 获取没有加载env时的环境变量
125124
env_mask = {key: os.getenv(key) for key in os.environ}

dashboard/eslint.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import reactRefresh from 'eslint-plugin-react-refresh'
66
import tseslint from 'typescript-eslint'
77

88
export default tseslint.config(
9-
{ ignores: ['dist'] },
9+
{ ignores: ['dist', 'out'] },
1010
jsxA11y.flatConfigs.recommended,
1111
{
1212
extends: [js.configs.recommended, ...tseslint.configs.recommended],
@@ -25,10 +25,7 @@ export default tseslint.config(
2525
acc[key] = 'warn'
2626
return acc
2727
}, {}),
28-
'react-refresh/only-export-components': [
29-
'warn',
30-
{ allowConstantExport: true },
31-
],
28+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
3229
// 关闭或降级其他规则
3330
'@typescript-eslint/no-explicit-any': 'warn',
3431
'@typescript-eslint/no-unused-vars': 'warn',
@@ -37,4 +34,11 @@ export default tseslint.config(
3734
'jsx-a11y/no-autofocus': 'warn',
3835
},
3936
},
37+
{
38+
files: ['**/*.d.ts'],
39+
rules: {
40+
// Ambient global declarations use `var` in TypeScript declaration files.
41+
'no-var': 'off',
42+
},
43+
}
4044
)

dashboard/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
"@radix-ui/react-tabs": "^1.1.13",
122122
"@radix-ui/react-toast": "^1.2.15",
123123
"@radix-ui/react-tooltip": "^1.2.8",
124+
"@react-spring/web": "10.0.3",
124125
"@tanstack/react-router": "^1.140.0",
125126
"@tanstack/react-virtual": "^3.13.13",
126127
"@tanstack/router-devtools": "^1.140.0",
@@ -130,6 +131,7 @@
130131
"@uppy/dashboard": "^5.1.0",
131132
"@uppy/react": "^5.1.1",
132133
"@uppy/xhr-upload": "^5.1.1",
134+
"@use-gesture/react": "^10.3.1",
133135
"axios": "^1.13.2",
134136
"class-variance-authority": "^0.7.1",
135137
"clsx": "^2.1.1",
@@ -142,6 +144,7 @@
142144
"idb": "^8.0.3",
143145
"katex": "^0.16.27",
144146
"lucide-react": "^0.556.0",
147+
"motion": "^12.38.0",
145148
"react": "^19.2.1",
146149
"react-day-picker": "^9.12.0",
147150
"react-dom": "^19.2.1",
@@ -154,9 +157,7 @@
154157
"remark-gfm": "^4.0.1",
155158
"remark-math": "^6.0.0",
156159
"smol-toml": "^1.5.2",
157-
"tailwind-merge": "^3.4.0",
158-
"@react-spring/web": "10.0.3",
159-
"@use-gesture/react": "^10.3.1"
160+
"tailwind-merge": "^3.4.0"
160161
},
161162
"devDependencies": {
162163
"@tailwindcss/vite": "^4.2.1",

dashboard/src/components/CodeEditor.tsx

Lines changed: 27 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import { useEffect, useState } from 'react'
2-
import CodeMirror from '@uiw/react-codemirror'
3-
import { css } from '@codemirror/lang-css'
4-
import { json, jsonParseLinter } from '@codemirror/lang-json'
5-
import { linter } from '@codemirror/lint'
6-
import { python } from '@codemirror/lang-python'
7-
import { oneDark } from '@codemirror/theme-one-dark'
8-
import { EditorView } from '@codemirror/view'
9-
import { StreamLanguage } from '@codemirror/language'
10-
import { toml as tomlMode } from '@codemirror/legacy-modes/mode/toml'
11-
12-
import { useTheme } from '@/components/use-theme'
1+
import { lazy, Suspense } from 'react'
132

143
export type Language = 'python' | 'json' | 'toml' | 'css' | 'text'
154

16-
interface CodeEditorProps {
5+
export interface CodeEditorProps {
176
value: string
187

198
onChange?: (value: string) => void
@@ -27,109 +16,38 @@ interface CodeEditorProps {
2716
className?: string
2817
}
2918

30-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31-
const languageExtensions: Record<Language, any[]> = {
32-
python: [python()],
33-
json: [json(), linter(jsonParseLinter())],
34-
toml: [StreamLanguage.define(tomlMode)],
35-
css: [css()],
36-
text: [],
37-
}
19+
const CodeEditorImpl = lazy(() => import('./CodeEditorImpl'))
3820

39-
export function CodeEditor({
40-
value,
41-
onChange,
42-
language = 'text',
43-
readOnly = false,
44-
height = '400px',
21+
function CodeEditorFallback({
22+
height,
4523
minHeight,
4624
maxHeight,
47-
placeholder,
48-
theme,
4925
className = '',
50-
}: CodeEditorProps) {
51-
const [mounted, setMounted] = useState(false)
52-
const { resolvedTheme } = useTheme()
53-
54-
useEffect(() => {
55-
setMounted(true)
56-
}, [])
57-
58-
if (!mounted) {
59-
return (
60-
<div
61-
className={`rounded-md border bg-muted animate-pulse ${className}`}
62-
style={{ height, minHeight, maxHeight }}
63-
/>
64-
)
65-
}
66-
67-
const extensions = [
68-
...(languageExtensions[language] || []),
69-
EditorView.lineWrapping,
70-
// 应用 JetBrains Mono 字体
71-
EditorView.theme({
72-
'&': {
73-
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
74-
},
75-
'.cm-content': {
76-
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
77-
},
78-
'.cm-gutters': {
79-
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
80-
},
81-
'.cm-scroller': {
82-
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
83-
},
84-
}),
85-
]
86-
87-
if (readOnly) {
88-
extensions.push(EditorView.editable.of(false))
89-
}
26+
}: Pick<CodeEditorProps, 'height' | 'minHeight' | 'maxHeight' | 'className'>) {
27+
return (
28+
<div
29+
className={`bg-muted animate-pulse rounded-md border ${className}`}
30+
style={{ height, minHeight, maxHeight }}
31+
/>
32+
)
33+
}
9034

91-
// 如果外部传了 theme prop 则使用,否则从 context 自动获取
92-
const effectiveTheme = theme ?? resolvedTheme
35+
export function CodeEditor(props: CodeEditorProps) {
36+
const { height = '400px', minHeight, maxHeight, className = '' } = props
9337

9438
return (
95-
<div className={`rounded-md overflow-hidden border custom-scrollbar ${className}`}>
96-
<CodeMirror
97-
value={value}
98-
height={height}
99-
minHeight={minHeight}
100-
maxHeight={maxHeight}
101-
theme={effectiveTheme === 'dark' ? oneDark : undefined}
102-
extensions={extensions}
103-
onChange={onChange}
104-
placeholder={placeholder}
105-
basicSetup={{
106-
lineNumbers: true,
107-
highlightActiveLineGutter: true,
108-
highlightSpecialChars: true,
109-
history: true,
110-
foldGutter: true,
111-
drawSelection: true,
112-
dropCursor: true,
113-
allowMultipleSelections: true,
114-
indentOnInput: true,
115-
syntaxHighlighting: true,
116-
bracketMatching: true,
117-
closeBrackets: true,
118-
autocompletion: true,
119-
rectangularSelection: true,
120-
crosshairCursor: true,
121-
highlightActiveLine: true,
122-
highlightSelectionMatches: true,
123-
closeBracketsKeymap: true,
124-
defaultKeymap: true,
125-
searchKeymap: true,
126-
historyKeymap: true,
127-
foldKeymap: true,
128-
completionKeymap: true,
129-
lintKeymap: true,
130-
}}
131-
/>
132-
</div>
39+
<Suspense
40+
fallback={
41+
<CodeEditorFallback
42+
height={height}
43+
minHeight={minHeight}
44+
maxHeight={maxHeight}
45+
className={className}
46+
/>
47+
}
48+
>
49+
<CodeEditorImpl {...props} />
50+
</Suspense>
13351
)
13452
}
13553

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { css } from '@codemirror/lang-css'
2+
import { json, jsonParseLinter } from '@codemirror/lang-json'
3+
import { python } from '@codemirror/lang-python'
4+
import { StreamLanguage } from '@codemirror/language'
5+
import { toml as tomlMode } from '@codemirror/legacy-modes/mode/toml'
6+
import { linter } from '@codemirror/lint'
7+
import { oneDark } from '@codemirror/theme-one-dark'
8+
import { EditorView } from '@codemirror/view'
9+
import CodeMirror from '@uiw/react-codemirror'
10+
11+
import { useTheme } from '@/components/use-theme'
12+
13+
import type { CodeEditorProps, Language } from './CodeEditor'
14+
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
const languageExtensions: Record<Language, any[]> = {
17+
python: [python()],
18+
json: [json(), linter(jsonParseLinter())],
19+
toml: [StreamLanguage.define(tomlMode)],
20+
css: [css()],
21+
text: [],
22+
}
23+
24+
export default function CodeEditorImpl({
25+
value,
26+
onChange,
27+
language = 'text',
28+
readOnly = false,
29+
height = '400px',
30+
minHeight,
31+
maxHeight,
32+
placeholder,
33+
theme,
34+
className = '',
35+
}: CodeEditorProps) {
36+
const { resolvedTheme } = useTheme()
37+
38+
const extensions = [
39+
...(languageExtensions[language] || []),
40+
EditorView.lineWrapping,
41+
// 应用 JetBrains Mono 字体
42+
EditorView.theme({
43+
'&': {
44+
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
45+
},
46+
'.cm-content': {
47+
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
48+
},
49+
'.cm-gutters': {
50+
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
51+
},
52+
'.cm-scroller': {
53+
fontFamily: '"JetBrains Mono", "Fira Code", "Consolas", "Monaco", monospace',
54+
},
55+
}),
56+
]
57+
58+
if (readOnly) {
59+
extensions.push(EditorView.editable.of(false))
60+
}
61+
62+
// 如果外部传了 theme prop 则使用,否则从 context 自动获取
63+
const effectiveTheme = theme ?? resolvedTheme
64+
65+
return (
66+
<div className={`custom-scrollbar overflow-hidden rounded-md border ${className}`}>
67+
<CodeMirror
68+
value={value}
69+
height={height}
70+
minHeight={minHeight}
71+
maxHeight={maxHeight}
72+
theme={effectiveTheme === 'dark' ? oneDark : undefined}
73+
extensions={extensions}
74+
onChange={onChange}
75+
placeholder={placeholder}
76+
basicSetup={{
77+
lineNumbers: true,
78+
highlightActiveLineGutter: true,
79+
highlightSpecialChars: true,
80+
history: true,
81+
foldGutter: true,
82+
drawSelection: true,
83+
dropCursor: true,
84+
allowMultipleSelections: true,
85+
indentOnInput: true,
86+
syntaxHighlighting: true,
87+
bracketMatching: true,
88+
closeBrackets: true,
89+
autocompletion: true,
90+
rectangularSelection: true,
91+
crosshairCursor: true,
92+
highlightActiveLine: true,
93+
highlightSelectionMatches: true,
94+
closeBracketsKeymap: true,
95+
defaultKeymap: true,
96+
searchKeymap: true,
97+
historyKeymap: true,
98+
foldKeymap: true,
99+
completionKeymap: true,
100+
lintKeymap: true,
101+
}}
102+
/>
103+
</div>
104+
)
105+
}

0 commit comments

Comments
 (0)