@youwen/ai-design-system
Version:
Enterprise AI-driven design system with comprehensive design tokens
104 lines (103 loc) • 2.69 kB
TypeScript
/**
* AI组件生成引擎
* 负责从自然语言描述生成UI组件代码
*/
export interface AIGenerationRequest {
userInput: string;
context?: {
theme?: 'blue' | 'green' | 'purple' | 'amber';
mode?: 'light' | 'dark';
layout?: string;
previousComponents?: string[];
};
}
export interface AIGenerationResult {
success: boolean;
component?: {
type: string;
props: Record<string, any>;
code: {
jsx: string;
props: string;
imports: string[];
};
};
confidence: number;
reasoning: string[];
alternatives?: Array<{
type: string;
props: Record<string, any>;
confidence: number;
}>;
errors?: string[];
}
export interface ComponentTemplate {
type: string;
keywords: string[];
propMappings: Record<string, (input: string, context?: any) => any>;
codeTemplate: (props: Record<string, any>) => {
jsx: string;
props: string;
imports: string[];
};
}
export declare class SemanticAnalyzer {
/**
* 分析用户输入的语义意图
*/
analyzeIntent(input: string): {
componentType: string | null;
confidence: number;
keywords: string[];
parameters: Record<string, any>;
};
/**
* 从输入中提取参数
*/
private extractParameters;
}
export declare class ComponentGenerator {
private semanticAnalyzer;
/**
* 从模板生成组件
*/
generateFromTemplate(template: ComponentTemplate, input: string, context?: any): AIGenerationResult['component'];
/**
* 获取属性默认值
*/
private getDefaultValue;
/**
* 生成替代方案
*/
generateAlternatives(input: string, primaryComponent: AIGenerationResult['component']): AIGenerationResult['alternatives'];
}
export declare class AIComponentEngine {
private semanticAnalyzer;
private componentGenerator;
/**
* 从自然语言生成组件
*/
generateComponentFromText(request: AIGenerationRequest): Promise<AIGenerationResult>;
/**
* 批量生成组件
*/
batchGenerate(requests: AIGenerationRequest[]): Promise<AIGenerationResult[]>;
/**
* 获取支持的组件类型
*/
getSupportedComponents(): Array<{
type: string;
keywords: string[];
description: string;
}>;
private getComponentDescription;
/**
* 获取使用示例
*/
getUsageExamples(): Array<{
input: string;
expectedComponent: string;
description: string;
}>;
}
export declare const aiEngine: AIComponentEngine;