116 lines
2.9 KiB
TypeScript
116 lines
2.9 KiB
TypeScript
import type { LucideIcon } from 'lucide-react';
|
|
import { Bot, Code2, Paintbrush } from 'lucide-react';
|
|
import type { ModuleAccess, ModuleAccessKey } from '../../shared/module-access';
|
|
|
|
export const AI_MODULE_SELECTION_PATH = '/module-select';
|
|
|
|
export type AiModuleId = 'programming' | 'painting' | 'robot';
|
|
|
|
export type AiModuleDefinition = {
|
|
id: AiModuleId;
|
|
title: string;
|
|
subtitle: string;
|
|
description: string;
|
|
route: string | null;
|
|
enabled: boolean;
|
|
Icon: LucideIcon;
|
|
switcherLabel?: string;
|
|
};
|
|
|
|
export const aiModules: readonly AiModuleDefinition[] = [
|
|
{
|
|
id: 'programming',
|
|
title: 'Makelore Code',
|
|
subtitle: 'AI 编程',
|
|
description: '把创意编程变成可运行的产品、游戏或工具',
|
|
route: '/chat',
|
|
enabled: true,
|
|
Icon: Code2,
|
|
},
|
|
{
|
|
id: 'painting',
|
|
title: 'Makelore Canvas',
|
|
subtitle: 'AI 绘画',
|
|
description: '用灵感描绘色彩缤纷的世界',
|
|
route: '/image-canvas',
|
|
enabled: true,
|
|
Icon: Paintbrush,
|
|
},
|
|
{
|
|
id: 'robot',
|
|
title: 'Makelore Robot',
|
|
subtitle: 'AI 机器',
|
|
description: '制作你的第一个机器人小伙伴',
|
|
route: '/ai-hardware',
|
|
enabled: true,
|
|
Icon: Bot,
|
|
switcherLabel: 'Robot 机器',
|
|
},
|
|
];
|
|
|
|
const moduleAccessKeyById: Record<AiModuleId, ModuleAccessKey> = {
|
|
programming: 'programming',
|
|
painting: 'design',
|
|
robot: 'robot',
|
|
};
|
|
|
|
const PROGRAMMING_ROUTE_PREFIXES = [
|
|
'/plugins',
|
|
'/plugin-marketplace',
|
|
'/my-plugins',
|
|
'/project-config',
|
|
'/project-plugins',
|
|
'/makelore-home',
|
|
'/kangaroo',
|
|
'/subagents',
|
|
'/chat',
|
|
'/deliverables',
|
|
'/workbench',
|
|
'/models',
|
|
] as const;
|
|
|
|
const PROGRAMMING_PROVIDER_ROUTE_PREFIXES = [
|
|
'/project-config',
|
|
'/makelore-home',
|
|
'/kangaroo',
|
|
'/subagents',
|
|
'/chat',
|
|
'/deliverables',
|
|
'/workbench',
|
|
'/models',
|
|
'/settings',
|
|
] as const;
|
|
|
|
function matchesRoute(pathname: string, route: string): boolean {
|
|
return pathname === route || pathname.startsWith(`${route}/`);
|
|
}
|
|
|
|
export function isAiModuleAllowed(moduleId: AiModuleId, access: ModuleAccess): boolean {
|
|
return access[moduleAccessKeyById[moduleId]];
|
|
}
|
|
|
|
export function isProgrammingProviderRoute(pathname: string): boolean {
|
|
if (matchesRoute(pathname, '/project-config/plugins')) return false;
|
|
return PROGRAMMING_PROVIDER_ROUTE_PREFIXES.some((route) => matchesRoute(pathname, route));
|
|
}
|
|
|
|
export function getGuardedAiModuleForPath(pathname: string): AiModuleId | null {
|
|
if (pathname === '/image-canvas'
|
|
|| pathname.startsWith('/image-canvas/')
|
|
|| pathname === '/image-prompts'
|
|
|| pathname.startsWith('/image-prompts/')) {
|
|
return 'painting';
|
|
}
|
|
if (pathname === '/ai-hardware' || pathname.startsWith('/ai-hardware/')) {
|
|
return 'robot';
|
|
}
|
|
if (PROGRAMMING_ROUTE_PREFIXES.some((route) => matchesRoute(pathname, route))) {
|
|
return 'programming';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getAiModuleForPath(pathname: string): AiModuleId {
|
|
return getGuardedAiModuleForPath(pathname) ?? 'programming';
|
|
}
|