htmlgen-mcp 0.2.5__py3-none-any.whl → 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of htmlgen-mcp might be problematic. Click here for more details.
- htmlgen_mcp/__init__.py +1 -1
- htmlgen_mcp/agents/ai_content_generator.py +328 -0
- htmlgen_mcp/agents/quick_generator.py +270 -0
- htmlgen_mcp/agents/smart_web_agent.py +118 -12
- htmlgen_mcp/agents/web_tools/__init__.py +16 -6
- htmlgen_mcp/agents/web_tools/html_templates_improved.py +696 -0
- htmlgen_mcp/agents/web_tools/navigation.py +29 -0
- htmlgen_mcp/config.py +326 -0
- htmlgen_mcp/sse_optimizations.py +195 -0
- htmlgen_mcp/web_agent_server.py +35 -16
- {htmlgen_mcp-0.2.5.dist-info → htmlgen_mcp-0.3.1.dist-info}/METADATA +1 -1
- {htmlgen_mcp-0.2.5.dist-info → htmlgen_mcp-0.3.1.dist-info}/RECORD +15 -10
- {htmlgen_mcp-0.2.5.dist-info → htmlgen_mcp-0.3.1.dist-info}/WHEEL +0 -0
- {htmlgen_mcp-0.2.5.dist-info → htmlgen_mcp-0.3.1.dist-info}/entry_points.txt +0 -0
- {htmlgen_mcp-0.2.5.dist-info → htmlgen_mcp-0.3.1.dist-info}/top_level.txt +0 -0
|
@@ -32,6 +32,7 @@ else:
|
|
|
32
32
|
|
|
33
33
|
# 导入工具函数
|
|
34
34
|
from .web_tools import *
|
|
35
|
+
from .quick_generator import QuickSiteGenerator
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
class SmartWebAgent:
|
|
@@ -440,6 +441,24 @@ class SmartWebAgent:
|
|
|
440
441
|
self, user_input: str, max_retries: int = 3
|
|
441
442
|
) -> Optional[dict]:
|
|
442
443
|
"""获取执行计划,带重试机制"""
|
|
444
|
+
|
|
445
|
+
# 判断是否使用快速模式
|
|
446
|
+
if self._should_use_quick_mode(user_input):
|
|
447
|
+
print("⚡ 启用快速模式:生成单页面网站")
|
|
448
|
+
site_type = self._extract_site_type(user_input)
|
|
449
|
+
project_name = self._extract_project_name(user_input, site_type)
|
|
450
|
+
|
|
451
|
+
plan = QuickSiteGenerator.create_single_page_plan(
|
|
452
|
+
project_name=project_name,
|
|
453
|
+
site_type=site_type,
|
|
454
|
+
description=user_input
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
# 进一步优化速度
|
|
458
|
+
plan = QuickSiteGenerator.optimize_for_speed(plan)
|
|
459
|
+
self.current_plan = plan
|
|
460
|
+
return plan
|
|
461
|
+
|
|
443
462
|
# 若无客户端,直接走离线计划
|
|
444
463
|
if self.client is None:
|
|
445
464
|
plan = self._build_fallback_plan(user_input)
|
|
@@ -480,12 +499,16 @@ class SmartWebAgent:
|
|
|
480
499
|
planning_prompt_template = """你是一个专业的网页设计与前端开发专家,精通现代Web技术、设计系统和用户体验。
|
|
481
500
|
请分析用户需求并制定执行计划,创建高质量、现代化、专业的网站。
|
|
482
501
|
|
|
483
|
-
|
|
502
|
+
🎨 核心设计理念:
|
|
484
503
|
• 现代美观:采用当前流行的设计趋势(如新拟态、毛玻璃、渐变、3D效果)
|
|
485
504
|
• 用户体验:移动优先、快速加载、流畅交互、无障碍访问
|
|
486
505
|
• 视觉层次:合理的留白、清晰的信息架构、引导性的视觉流
|
|
487
506
|
• 品牌一致:统一的设计语言、配色方案、字体系统
|
|
488
|
-
|
|
507
|
+
|
|
508
|
+
📊 **页面生成策略**:
|
|
509
|
+
• 快速模式(默认):仅生成一个完整的首页,包含所有核心内容部分
|
|
510
|
+
• 多页面模式:仅当用户明确提到"多页面"、"多个页面"、"分别创建"或列出具体页面名称时启用
|
|
511
|
+
• 判断规则:如果用户只说"咖啡店网站"、"企业官网"等,默认使用单页面滚动式设计
|
|
489
512
|
|
|
490
513
|
用户需求:<<USER_INPUT>>
|
|
491
514
|
工作目录:<<PROJECT_DIR>>
|
|
@@ -531,7 +554,9 @@ class SmartWebAgent:
|
|
|
531
554
|
|
|
532
555
|
📋 执行规范:
|
|
533
556
|
|
|
534
|
-
|
|
557
|
+
⚠️ **重要提示**:优先速度!除非用户明确要求,否则只生成一个页面。
|
|
558
|
+
|
|
559
|
+
1. **项目结构**(简化流程):
|
|
535
560
|
- 第1步:create_project_structure - 创建完整目录结构
|
|
536
561
|
- 第2步:create_css_file - 创建样式文件(assets/css/style.css)
|
|
537
562
|
- 第3步:create_js_file - 创建脚本文件(assets/js/main.js)
|
|
@@ -539,9 +564,9 @@ class SmartWebAgent:
|
|
|
539
564
|
- 第5步:add_bootstrap - 添加框架支持
|
|
540
565
|
- 第6步:create_responsive_navbar - 创建导航组件
|
|
541
566
|
- 🎨 **第7步:inject_images - 智能图片注入(必须包含!)**
|
|
542
|
-
- 第8
|
|
543
|
-
- 第
|
|
544
|
-
-
|
|
567
|
+
- 第8步:验证HTML(可选)
|
|
568
|
+
- 第9步:open_in_browser - 预览效果
|
|
569
|
+
- 仅在用户明确要求多页面时,才为每个页面单独安排步骤
|
|
545
570
|
|
|
546
571
|
⚠️ **重要:第7步图片注入是必需的!**
|
|
547
572
|
使用 inject_images 为网站添加美观的AI生成图片:
|
|
@@ -572,12 +597,12 @@ class SmartWebAgent:
|
|
|
572
597
|
- 团队介绍:人员卡片+职位信息
|
|
573
598
|
- 合作伙伴:Logo墙+滚动动画
|
|
574
599
|
|
|
575
|
-
🍔 **餐厅网站 /
|
|
576
|
-
- Hero
|
|
577
|
-
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
600
|
+
🍔 **餐厅网站 / 咖啡店**:
|
|
601
|
+
- 默认生成单页面版本:Hero区+菜单展示+营业信息+联系方式(全部在首页)
|
|
602
|
+
- 多页面版本(仅在用户要求时):
|
|
603
|
+
* 菜单页:使用 create_menu_page
|
|
604
|
+
* 关于页:使用 create_about_page
|
|
605
|
+
* 联系页:使用 create_contact_page
|
|
581
606
|
|
|
582
607
|
🛍️ **电商着陆页**:
|
|
583
608
|
- Hero区:产品大图+限时优惠倒计时
|
|
@@ -753,6 +778,87 @@ class SmartWebAgent:
|
|
|
753
778
|
s = "".join(slug).strip("-")
|
|
754
779
|
return s[:32] or default
|
|
755
780
|
|
|
781
|
+
def _should_use_quick_mode(self, user_input: str) -> bool:
|
|
782
|
+
"""判断是否应该使用快速模式
|
|
783
|
+
|
|
784
|
+
快速模式条件:
|
|
785
|
+
1. 用户未明确要求多页面
|
|
786
|
+
2. 用户未列出具体的页面名称
|
|
787
|
+
3. 用户未要求复杂的功能
|
|
788
|
+
"""
|
|
789
|
+
lower_input = user_input.lower()
|
|
790
|
+
|
|
791
|
+
# 检查是否明确要求多页面
|
|
792
|
+
multi_page_keywords = [
|
|
793
|
+
"多页面", "多个页面", "分别创建", "分别生成",
|
|
794
|
+
"菜单页", "关于页", "联系页", "产品页",
|
|
795
|
+
"multiple pages", "separate pages", "menu page", "about page"
|
|
796
|
+
]
|
|
797
|
+
|
|
798
|
+
for keyword in multi_page_keywords:
|
|
799
|
+
if keyword in lower_input:
|
|
800
|
+
return False
|
|
801
|
+
|
|
802
|
+
# 检查是否有复杂功能要求
|
|
803
|
+
complex_keywords = [
|
|
804
|
+
"复杂", "详细", "完整", "全面", "多功能",
|
|
805
|
+
"complex", "detailed", "complete", "comprehensive"
|
|
806
|
+
]
|
|
807
|
+
|
|
808
|
+
for keyword in complex_keywords:
|
|
809
|
+
if keyword in lower_input:
|
|
810
|
+
return False
|
|
811
|
+
|
|
812
|
+
# 默认使用快速模式
|
|
813
|
+
return True
|
|
814
|
+
|
|
815
|
+
def _extract_site_type(self, user_input: str) -> str:
|
|
816
|
+
"""从用户输入中提取网站类型"""
|
|
817
|
+
lower_input = user_input.lower()
|
|
818
|
+
|
|
819
|
+
type_keywords = {
|
|
820
|
+
"咖啡店": ["咖啡", "coffee", "cafe"],
|
|
821
|
+
"餐厅": ["餐厅", "餐饮", "美食", "restaurant", "dining"],
|
|
822
|
+
"企业": ["企业", "公司", "商业", "company", "corporate", "business"],
|
|
823
|
+
"作品集": ["作品集", "个人", "portfolio", "personal"],
|
|
824
|
+
"电商": ["电商", "商店", "购物", "shop", "store", "ecommerce"],
|
|
825
|
+
"博客": ["博客", "文章", "内容", "blog", "article"]
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
for site_type, keywords in type_keywords.items():
|
|
829
|
+
for keyword in keywords:
|
|
830
|
+
if keyword in lower_input:
|
|
831
|
+
return site_type
|
|
832
|
+
|
|
833
|
+
return "通用网站"
|
|
834
|
+
|
|
835
|
+
def _extract_project_name(self, user_input: str, site_type: str) -> str:
|
|
836
|
+
"""从用户输入提取或生成项目名称"""
|
|
837
|
+
# 尝试提取引号中的名称
|
|
838
|
+
import re
|
|
839
|
+
match = re.search(r'[“"「]([\w\s\u4e00-\u9fa5]+)[”"」]', user_input)
|
|
840
|
+
if match:
|
|
841
|
+
name = match.group(1)
|
|
842
|
+
# 转换为英文项目名
|
|
843
|
+
name = name.replace(' ', '-').lower()
|
|
844
|
+
# 如果是中文,使用类型作为前缀
|
|
845
|
+
if any(ord(c) > 127 for c in name):
|
|
846
|
+
return f"{site_type.replace('网站', '').lower()}-site"
|
|
847
|
+
return name
|
|
848
|
+
|
|
849
|
+
# 默认项目名
|
|
850
|
+
type_to_name = {
|
|
851
|
+
"咖啡店": "coffee-shop",
|
|
852
|
+
"餐厅": "restaurant",
|
|
853
|
+
"企业": "corporate",
|
|
854
|
+
"作品集": "portfolio",
|
|
855
|
+
"电商": "ecommerce",
|
|
856
|
+
"博客": "blog",
|
|
857
|
+
"通用网站": "modern-site"
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
return type_to_name.get(site_type, "website")
|
|
861
|
+
|
|
756
862
|
def _build_fallback_plan(self, user_input: str) -> dict:
|
|
757
863
|
"""在无网络/无密钥时的本地执行计划:生成一个现代化的基础站点骨架"""
|
|
758
864
|
project_name = self._slugify(user_input)
|
|
@@ -4,12 +4,22 @@ from __future__ import annotations
|
|
|
4
4
|
from .bootstrap import add_bootstrap
|
|
5
5
|
from .browser import open_in_browser, start_live_server
|
|
6
6
|
from .css import create_css_file
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
# 使用改进版的页面生成工具
|
|
8
|
+
try:
|
|
9
|
+
from .html_templates_improved import (
|
|
10
|
+
create_html_file,
|
|
11
|
+
create_menu_page,
|
|
12
|
+
create_about_page,
|
|
13
|
+
create_contact_page,
|
|
14
|
+
)
|
|
15
|
+
except ImportError:
|
|
16
|
+
# 如果改进版不存在,回退到原版
|
|
17
|
+
from .html_templates import (
|
|
18
|
+
create_html_file,
|
|
19
|
+
create_menu_page,
|
|
20
|
+
create_about_page,
|
|
21
|
+
create_contact_page,
|
|
22
|
+
)
|
|
13
23
|
from .images import fetch_generated_images, inject_images
|
|
14
24
|
from .js import create_js_file
|
|
15
25
|
from .navigation import create_responsive_navbar
|