feat(app): 移除内置agents并添加CORS支持和技能上传优化
移除了agents/registry.json中的所有内置agents配置,将agents数组清空。 为web应用添加了CORS中间件支持,允许指定的前端地址跨域访问。 重构了技能上传功能,增加了LLM重写机制,自动规范化上传的技能格式。 新增了工具名称提取逻辑,从技能正文中自动识别Required Tools段落。 更新了技能学习候选者和草稿的载荷结构,添加评估报告统计信息。 修改了意图路由技能的说明,改进任务状态管理逻辑。
This commit is contained in:
@ -28,8 +28,10 @@ import {
|
||||
deleteUserFile,
|
||||
createUserFileDir,
|
||||
getAccessToken,
|
||||
isApiError,
|
||||
} from '@/lib/api';
|
||||
import type { UserFileContent, UserFileItem } from '@/lib/api';
|
||||
import { canMutateUserFilesPath } from '@/lib/user-file-paths';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { type AppLocale, pickAppText } from '@/lib/i18n/core';
|
||||
@ -44,6 +46,10 @@ function sleep(ms: number): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
function isAuthError(error: unknown): boolean {
|
||||
return isApiError(error, 401);
|
||||
}
|
||||
|
||||
export default function FilesPage() {
|
||||
const { locale } = useAppI18n();
|
||||
const [items, setItems] = useState<UserFileItem[]>([]);
|
||||
@ -78,6 +84,9 @@ export default function FilesPage() {
|
||||
return;
|
||||
} catch (err) {
|
||||
lastError = err;
|
||||
if (isAuthError(err)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
const message = lastError instanceof Error ? lastError.message : pickAppText(locale, '加载文件失败', 'Failed to load files');
|
||||
@ -156,6 +165,15 @@ export default function FilesPage() {
|
||||
const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = e.target.files;
|
||||
if (!files || files.length === 0) return;
|
||||
if (!canMutateUserFilesPath(currentPath)) {
|
||||
setLoadError(pickAppText(
|
||||
locale,
|
||||
'请先进入 uploads、outputs、shared 或 tasks 目录后再上传。',
|
||||
'Open uploads, outputs, shared, or tasks before uploading.'
|
||||
));
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
setUploading(true);
|
||||
setUploadProgress(0);
|
||||
@ -178,6 +196,14 @@ export default function FilesPage() {
|
||||
const handleCreateDir = async () => {
|
||||
const name = newDirName.trim();
|
||||
if (!name) return;
|
||||
if (!canMutateUserFilesPath(currentPath)) {
|
||||
setLoadError(pickAppText(
|
||||
locale,
|
||||
'请先进入 uploads、outputs、shared 或 tasks 目录后再新建文件夹。',
|
||||
'Open uploads, outputs, shared, or tasks before creating a folder.'
|
||||
));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const dirPath = currentPath ? `${currentPath}/${name}` : name;
|
||||
await createUserFileDir(dirPath);
|
||||
@ -191,6 +217,7 @@ export default function FilesPage() {
|
||||
|
||||
// Build breadcrumbs
|
||||
const breadcrumbs = currentPath ? currentPath.split('/') : [];
|
||||
const canMutateCurrentPath = canMutateUserFilesPath(currentPath);
|
||||
|
||||
const formatSize = (bytes: number | null) => {
|
||||
if (bytes === null || bytes === undefined) return '';
|
||||
@ -224,7 +251,12 @@ export default function FilesPage() {
|
||||
size="sm"
|
||||
className="h-11"
|
||||
onClick={() => setShowMkdir(true)}
|
||||
disabled={loading}
|
||||
disabled={loading || !canMutateCurrentPath}
|
||||
title={
|
||||
canMutateCurrentPath
|
||||
? undefined
|
||||
: pickAppText(locale, '先进入 uploads、outputs、shared 或 tasks', 'Open uploads, outputs, shared, or tasks first')
|
||||
}
|
||||
>
|
||||
<FolderPlus className="w-4 h-4 mr-1" />
|
||||
{pickAppText(locale, '新建文件夹', 'New folder')}
|
||||
@ -234,7 +266,12 @@ export default function FilesPage() {
|
||||
size="sm"
|
||||
className="h-11"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
disabled={uploading}
|
||||
disabled={uploading || !canMutateCurrentPath}
|
||||
title={
|
||||
canMutateCurrentPath
|
||||
? undefined
|
||||
: pickAppText(locale, '先进入 uploads、outputs、shared 或 tasks', 'Open uploads, outputs, shared, or tasks first')
|
||||
}
|
||||
>
|
||||
{uploading ? (
|
||||
<>
|
||||
@ -272,6 +309,15 @@ export default function FilesPage() {
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{!canMutateCurrentPath && !loading && (
|
||||
<p className="mb-4 rounded-md border border-[#E6E1DE] bg-muted/40 px-3 py-2 text-sm text-muted-foreground">
|
||||
{pickAppText(
|
||||
locale,
|
||||
'请选择 uploads、outputs、shared 或 tasks 后再上传或新建文件夹。',
|
||||
'Select uploads, outputs, shared, or tasks before uploading or creating folders.'
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Breadcrumbs */}
|
||||
<div className="flex items-center gap-1 mb-4 text-sm text-muted-foreground flex-wrap">
|
||||
|
||||
Reference in New Issue
Block a user