htmlgen-mcp 0.2.2__tar.gz → 0.3.1__tar.gz
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-0.2.2/htmlgen_mcp.egg-info → htmlgen_mcp-0.3.1}/PKG-INFO +1 -1
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1}/pyproject.toml +5 -5
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/__init__.py +7 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/agents/ai_content_generator.py +328 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/agents/quick_generator.py +270 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/smart_web_agent.py +118 -12
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/__init__.py +16 -6
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/agents/web_tools/html_templates_improved.py +696 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/navigation.py +29 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/config.py +326 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp/sse_optimizations.py +195 -0
- {htmlgen_mcp-0.2.2/MCP → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/web_agent_server.py +39 -19
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp.egg-info}/PKG-INFO +1 -1
- htmlgen_mcp-0.3.1/src/htmlgen_mcp.egg-info/SOURCES.txt +34 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp.egg-info/entry_points.txt +2 -0
- htmlgen_mcp-0.3.1/src/htmlgen_mcp.egg-info/top_level.txt +1 -0
- htmlgen_mcp-0.2.2/MCP/__init__.py +0 -5
- htmlgen_mcp-0.2.2/htmlgen_mcp.egg-info/SOURCES.txt +0 -29
- htmlgen_mcp-0.2.2/htmlgen_mcp.egg-info/entry_points.txt +0 -2
- htmlgen_mcp-0.2.2/htmlgen_mcp.egg-info/top_level.txt +0 -2
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1}/README.md +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1}/setup.cfg +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/__init__.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/bootstrap.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/browser.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/colors.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/css.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/edgeone_deploy.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/html_templates.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/images.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/images_fixed.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/js.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/project.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/simple_builder.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/simple_css.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/simple_js.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/simple_templates.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src/htmlgen_mcp}/agents/web_tools/validation.py +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src}/htmlgen_mcp.egg-info/dependency_links.txt +0 -0
- {htmlgen_mcp-0.2.2 → htmlgen_mcp-0.3.1/src}/htmlgen_mcp.egg-info/requires.txt +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "htmlgen-mcp"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.1"
|
|
8
8
|
description = "AI-powered HTML website generator with auto-upload functionality via Model Context Protocol"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -48,7 +48,7 @@ dev = [
|
|
|
48
48
|
]
|
|
49
49
|
|
|
50
50
|
[project.scripts]
|
|
51
|
-
htmlgen-mcp = "
|
|
51
|
+
htmlgen-mcp = "htmlgen_mcp.web_agent_server:main"
|
|
52
52
|
|
|
53
53
|
[project.urls]
|
|
54
54
|
Homepage = "https://github.com/your-username/htmlgen-mcp"
|
|
@@ -57,11 +57,11 @@ Issues = "https://github.com/your-username/htmlgen-mcp/issues"
|
|
|
57
57
|
Documentation = "https://github.com/your-username/htmlgen-mcp/blob/main/README.md"
|
|
58
58
|
|
|
59
59
|
[tool.setuptools.packages.find]
|
|
60
|
-
where = ["
|
|
61
|
-
include = ["
|
|
60
|
+
where = ["src"]
|
|
61
|
+
include = ["htmlgen_mcp*", "agents*"]
|
|
62
62
|
|
|
63
63
|
[tool.setuptools.package-data]
|
|
64
|
-
|
|
64
|
+
htmlgen_mcp = ["*.json", "*.yaml", "*.yml"]
|
|
65
65
|
agents = ["*.json", "*.yaml", "*.yml"]
|
|
66
66
|
|
|
67
67
|
[dependency-groups]
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"""AI 内容生成辅助模块 - 为页面生成个性化内容"""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from typing import Dict, Any, Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AIContentGenerator:
|
|
9
|
+
"""AI 内容生成器 - 为各种页面生成个性化内容"""
|
|
10
|
+
|
|
11
|
+
def __init__(self, agent_instance):
|
|
12
|
+
"""初始化生成器
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
agent_instance: SmartWebAgent 实例
|
|
16
|
+
"""
|
|
17
|
+
self.agent = agent_instance
|
|
18
|
+
|
|
19
|
+
def generate_menu_content(
|
|
20
|
+
self,
|
|
21
|
+
project_name: str,
|
|
22
|
+
context: Dict[str, Any]
|
|
23
|
+
) -> Dict[str, Any]:
|
|
24
|
+
"""为菜单页面生成个性化内容"""
|
|
25
|
+
|
|
26
|
+
prompt = f"""你是一个专业的网页内容创作者。
|
|
27
|
+
为"{project_name}"生成一个详细的菜单内容。
|
|
28
|
+
|
|
29
|
+
项目信息:
|
|
30
|
+
- 名称:{project_name}
|
|
31
|
+
- 描述:{context.get('description', '')}
|
|
32
|
+
- 特色:{context.get('features', '')}
|
|
33
|
+
- 位置:{context.get('location', '')}
|
|
34
|
+
- 目标客户:{context.get('target_audience', '')}
|
|
35
|
+
|
|
36
|
+
请生成一个完整的菜单,包含:
|
|
37
|
+
1. 2-4个类别(如:热饮、冷饮、轻食、甜点)
|
|
38
|
+
2. 每个类别3-5个项目
|
|
39
|
+
3. 每个项目包含:
|
|
40
|
+
- name: 产品名称(有创意且符合品牌)
|
|
41
|
+
- price: 价格(符合定位,使用"¥"符号)
|
|
42
|
+
- description: 描述(简短吸引人,20字以内)
|
|
43
|
+
- image_topic: 图片主题描述(英文,用于生成图片)
|
|
44
|
+
|
|
45
|
+
返回 JSON 格式:
|
|
46
|
+
{{
|
|
47
|
+
"categories": [
|
|
48
|
+
{{
|
|
49
|
+
"name": "类别名称",
|
|
50
|
+
"items": [
|
|
51
|
+
{{
|
|
52
|
+
"name": "产品名称",
|
|
53
|
+
"price": "¥ XX",
|
|
54
|
+
"description": "产品描述",
|
|
55
|
+
"image_topic": "image description"
|
|
56
|
+
}}
|
|
57
|
+
]
|
|
58
|
+
}}
|
|
59
|
+
],
|
|
60
|
+
"description": "菜单页面的副标题描述"
|
|
61
|
+
}}
|
|
62
|
+
|
|
63
|
+
重要:
|
|
64
|
+
- 内容要符合项目的定位和风格
|
|
65
|
+
- 价格要合理且有梯度
|
|
66
|
+
- 描述要诱人且真实
|
|
67
|
+
- 直接返回 JSON,不要其他内容
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
response = self.agent.client.chat.completions.create(
|
|
72
|
+
model=self.agent.model,
|
|
73
|
+
messages=[
|
|
74
|
+
{"role": "system", "content": "你是一个专业的内容创作者,擅长为各类商业项目创作个性化内容。"},
|
|
75
|
+
{"role": "user", "content": prompt}
|
|
76
|
+
],
|
|
77
|
+
temperature=0.7,
|
|
78
|
+
max_tokens=2000
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
content = response.choices[0].message.content.strip()
|
|
82
|
+
# 清理可能的 markdown 代码块标记
|
|
83
|
+
if content.startswith("```"):
|
|
84
|
+
lines = content.split('\n')
|
|
85
|
+
content = '\n'.join(lines[1:-1] if lines[-1] == "```" else lines[1:])
|
|
86
|
+
|
|
87
|
+
return json.loads(content)
|
|
88
|
+
|
|
89
|
+
except Exception as e:
|
|
90
|
+
print(f"AI 生成菜单内容失败:{e}")
|
|
91
|
+
# 返回空内容,让页面使用默认值
|
|
92
|
+
return {}
|
|
93
|
+
|
|
94
|
+
def generate_about_content(
|
|
95
|
+
self,
|
|
96
|
+
project_name: str,
|
|
97
|
+
context: Dict[str, Any]
|
|
98
|
+
) -> Dict[str, Any]:
|
|
99
|
+
"""为关于页面生成个性化内容"""
|
|
100
|
+
|
|
101
|
+
prompt = f"""为"{project_name}"生成"关于我们"页面的内容。
|
|
102
|
+
|
|
103
|
+
项目信息:
|
|
104
|
+
- 名称:{project_name}
|
|
105
|
+
- 描述:{context.get('description', '')}
|
|
106
|
+
- 使命:{context.get('mission', '')}
|
|
107
|
+
- 特色:{context.get('features', '')}
|
|
108
|
+
- 创始年份:{context.get('year_founded', '2020')}
|
|
109
|
+
|
|
110
|
+
请生成以下内容(JSON格式):
|
|
111
|
+
{{
|
|
112
|
+
"headline": "页面主标题",
|
|
113
|
+
"subtitle": "副标题(一句话介绍)",
|
|
114
|
+
"story": {{
|
|
115
|
+
"title": "品牌故事标题",
|
|
116
|
+
"content": "品牌故事内容(100-150字)",
|
|
117
|
+
"image_topic": "story image description"
|
|
118
|
+
}},
|
|
119
|
+
"values": ["价值观1", "价值观2", "价值观3", "价值观4"],
|
|
120
|
+
"team": [
|
|
121
|
+
{{
|
|
122
|
+
"name": "团队成员姓名",
|
|
123
|
+
"role": "职位",
|
|
124
|
+
"description": "简介(20字以内)",
|
|
125
|
+
"image_topic": "team member photo description"
|
|
126
|
+
}}
|
|
127
|
+
],
|
|
128
|
+
"achievements": [
|
|
129
|
+
{{"value": "数值", "label": "标签"}},
|
|
130
|
+
{{"value": "数值", "label": "标签"}}
|
|
131
|
+
],
|
|
132
|
+
"cta_title": "行动号召标题",
|
|
133
|
+
"cta_text": "行动号召文字"
|
|
134
|
+
}}
|
|
135
|
+
|
|
136
|
+
要求:
|
|
137
|
+
- 内容真实可信,避免夸大
|
|
138
|
+
- 团队成员生成2-3个核心岗位即可
|
|
139
|
+
- 成就数据要合理
|
|
140
|
+
- 符合品牌调性
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
response = self.agent.client.chat.completions.create(
|
|
145
|
+
model=self.agent.model,
|
|
146
|
+
messages=[
|
|
147
|
+
{"role": "user", "content": prompt}
|
|
148
|
+
],
|
|
149
|
+
temperature=0.7,
|
|
150
|
+
max_tokens=1500
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
content = response.choices[0].message.content.strip()
|
|
154
|
+
if content.startswith("```"):
|
|
155
|
+
lines = content.split('\n')
|
|
156
|
+
content = '\n'.join(lines[1:-1] if lines[-1] == "```" else lines[1:])
|
|
157
|
+
|
|
158
|
+
return json.loads(content)
|
|
159
|
+
|
|
160
|
+
except Exception as e:
|
|
161
|
+
print(f"AI 生成关于内容失败:{e}")
|
|
162
|
+
return {}
|
|
163
|
+
|
|
164
|
+
def generate_contact_content(
|
|
165
|
+
self,
|
|
166
|
+
project_name: str,
|
|
167
|
+
context: Dict[str, Any]
|
|
168
|
+
) -> Dict[str, Any]:
|
|
169
|
+
"""为联系页面生成个性化文案"""
|
|
170
|
+
|
|
171
|
+
prompt = f"""为"{project_name}"生成联系页面的文案。
|
|
172
|
+
|
|
173
|
+
项目信息:
|
|
174
|
+
- 名称:{project_name}
|
|
175
|
+
- 类型:{context.get('type', '咖啡店')}
|
|
176
|
+
- 特色:{context.get('features', '')}
|
|
177
|
+
|
|
178
|
+
生成以下文案(JSON格式):
|
|
179
|
+
{{
|
|
180
|
+
"headline": "联系页面标题",
|
|
181
|
+
"subtitle": "副标题(欢迎语)",
|
|
182
|
+
"form_title": "表单标题",
|
|
183
|
+
"form_text": "表单说明文字",
|
|
184
|
+
"response_time": "响应时间承诺"
|
|
185
|
+
}}
|
|
186
|
+
|
|
187
|
+
要求文案:
|
|
188
|
+
- 友好亲切
|
|
189
|
+
- 专业可信
|
|
190
|
+
- 简洁明了
|
|
191
|
+
"""
|
|
192
|
+
|
|
193
|
+
try:
|
|
194
|
+
response = self.agent.client.chat.completions.create(
|
|
195
|
+
model=self.agent.model,
|
|
196
|
+
messages=[
|
|
197
|
+
{"role": "user", "content": prompt}
|
|
198
|
+
],
|
|
199
|
+
temperature=0.6,
|
|
200
|
+
max_tokens=500
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
content = response.choices[0].message.content.strip()
|
|
204
|
+
if content.startswith("```"):
|
|
205
|
+
lines = content.split('\n')
|
|
206
|
+
content = '\n'.join(lines[1:-1] if lines[-1] == "```" else lines[1:])
|
|
207
|
+
|
|
208
|
+
return json.loads(content)
|
|
209
|
+
|
|
210
|
+
except Exception as e:
|
|
211
|
+
print(f"AI 生成联系内容失败:{e}")
|
|
212
|
+
return {}
|
|
213
|
+
|
|
214
|
+
def enhance_project_context(
|
|
215
|
+
self,
|
|
216
|
+
project_name: str,
|
|
217
|
+
description: str
|
|
218
|
+
) -> Dict[str, Any]:
|
|
219
|
+
"""增强项目上下文信息,补充缺失的细节"""
|
|
220
|
+
|
|
221
|
+
prompt = f"""分析项目"{project_name}"并补充必要的商业信息。
|
|
222
|
+
|
|
223
|
+
项目描述:{description}
|
|
224
|
+
|
|
225
|
+
请推断并生成以下信息(JSON格式):
|
|
226
|
+
{{
|
|
227
|
+
"type": "项目类型(如:咖啡店、餐厅、科技公司等)",
|
|
228
|
+
"target_audience": "目标客户描述",
|
|
229
|
+
"features": "核心特色(3-5个关键词)",
|
|
230
|
+
"mission": "使命宣言(一句话)",
|
|
231
|
+
"address": "合理的示例地址",
|
|
232
|
+
"phone": "示例电话(使用 010-XXXX-XXXX 格式)",
|
|
233
|
+
"email": "示例邮箱",
|
|
234
|
+
"business_hours": "营业时间"
|
|
235
|
+
}}
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
try:
|
|
239
|
+
response = self.agent.client.chat.completions.create(
|
|
240
|
+
model=self.agent.model,
|
|
241
|
+
messages=[
|
|
242
|
+
{"role": "user", "content": prompt}
|
|
243
|
+
],
|
|
244
|
+
temperature=0.5,
|
|
245
|
+
max_tokens=500
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
content = response.choices[0].message.content.strip()
|
|
249
|
+
if content.startswith("```"):
|
|
250
|
+
lines = content.split('\n')
|
|
251
|
+
content = '\n'.join(lines[1:-1] if lines[-1] == "```" else lines[1:])
|
|
252
|
+
|
|
253
|
+
return json.loads(content)
|
|
254
|
+
|
|
255
|
+
except Exception as e:
|
|
256
|
+
print(f"增强上下文失败:{e}")
|
|
257
|
+
return {
|
|
258
|
+
"type": "商业",
|
|
259
|
+
"target_audience": "大众客户",
|
|
260
|
+
"features": "品质、服务、创新",
|
|
261
|
+
"mission": f"为客户提供优质的产品与服务",
|
|
262
|
+
"address": "北京市朝阳区示例路123号",
|
|
263
|
+
"phone": "010-8888-8888",
|
|
264
|
+
"email": f"info@{project_name.lower().replace(' ', '')}.com",
|
|
265
|
+
"business_hours": "周一至周五 9:00-18:00"
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def integrate_ai_generation(agent_instance, tool_name: str, params: Dict[str, Any]) -> Dict[str, Any]:
|
|
270
|
+
"""集成 AI 生成到工具调用中
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
agent_instance: SmartWebAgent 实例
|
|
274
|
+
tool_name: 工具名称
|
|
275
|
+
params: 工具参数
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
增强后的参数,包含 AI 生成的内容
|
|
279
|
+
"""
|
|
280
|
+
|
|
281
|
+
# 只处理特定的页面生成工具
|
|
282
|
+
if tool_name not in ["create_menu_page", "create_about_page", "create_contact_page"]:
|
|
283
|
+
return params
|
|
284
|
+
|
|
285
|
+
# 提取项目信息
|
|
286
|
+
project_name = params.get('project_name', '')
|
|
287
|
+
file_path = params.get('file_path', '')
|
|
288
|
+
|
|
289
|
+
# 获取或创建上下文
|
|
290
|
+
context = params.get('context', {})
|
|
291
|
+
if not context:
|
|
292
|
+
# 尝试从 agent 的执行历史中提取上下文
|
|
293
|
+
context = {
|
|
294
|
+
'description': agent_instance.latest_user_request or '',
|
|
295
|
+
'project_directory': agent_instance.project_directory
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
# 创建 AI 内容生成器
|
|
299
|
+
generator = AIContentGenerator(agent_instance)
|
|
300
|
+
|
|
301
|
+
# 根据工具类型生成相应内容
|
|
302
|
+
ai_content = {}
|
|
303
|
+
if tool_name == "create_menu_page":
|
|
304
|
+
ai_content = generator.generate_menu_content(project_name, context)
|
|
305
|
+
elif tool_name == "create_about_page":
|
|
306
|
+
ai_content = generator.generate_about_content(project_name, context)
|
|
307
|
+
elif tool_name == "create_contact_page":
|
|
308
|
+
ai_content = generator.generate_contact_content(project_name, context)
|
|
309
|
+
|
|
310
|
+
# 如果需要,增强上下文信息
|
|
311
|
+
if not context.get('address') or not context.get('phone'):
|
|
312
|
+
enhanced_context = generator.enhance_project_context(
|
|
313
|
+
project_name,
|
|
314
|
+
context.get('description', '')
|
|
315
|
+
)
|
|
316
|
+
context.update(enhanced_context)
|
|
317
|
+
|
|
318
|
+
# 更新参数
|
|
319
|
+
params['context'] = context
|
|
320
|
+
params['ai_content'] = ai_content
|
|
321
|
+
|
|
322
|
+
return params
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
__all__ = [
|
|
326
|
+
'AIContentGenerator',
|
|
327
|
+
'integrate_ai_generation'
|
|
328
|
+
]
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""快速单页网站生成器 - 优化生成速度"""
|
|
4
|
+
|
|
5
|
+
from typing import Dict, Any, Optional, List
|
|
6
|
+
import json
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class QuickSiteGenerator:
|
|
10
|
+
"""快速生成单页面网站的辅助类"""
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def create_single_page_plan(
|
|
14
|
+
project_name: str,
|
|
15
|
+
site_type: str,
|
|
16
|
+
description: str
|
|
17
|
+
) -> Dict[str, Any]:
|
|
18
|
+
"""创建单页面网站的简化计划
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
project_name: 项目名称
|
|
22
|
+
site_type: 网站类型(咖啡店、企业、作品集等)
|
|
23
|
+
description: 用户需求描述
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
简化的执行计划
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
# 基础步骤(所有类型通用)
|
|
30
|
+
base_steps = [
|
|
31
|
+
{
|
|
32
|
+
"step": 1,
|
|
33
|
+
"tool": "create_project_structure",
|
|
34
|
+
"params": {
|
|
35
|
+
"project_name": project_name,
|
|
36
|
+
"project_path": "."
|
|
37
|
+
},
|
|
38
|
+
"description": "创建项目目录结构",
|
|
39
|
+
"rationale": "建立规范的项目结构"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"step": 2,
|
|
43
|
+
"tool": "create_css_file",
|
|
44
|
+
"params": {
|
|
45
|
+
"file_path": "assets/css/style.css"
|
|
46
|
+
},
|
|
47
|
+
"description": "创建样式文件",
|
|
48
|
+
"rationale": "定义网站视觉风格"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"step": 3,
|
|
52
|
+
"tool": "create_js_file",
|
|
53
|
+
"params": {
|
|
54
|
+
"file_path": "assets/js/main.js"
|
|
55
|
+
},
|
|
56
|
+
"description": "创建交互脚本",
|
|
57
|
+
"rationale": "添加动态效果和交互"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"step": 4,
|
|
61
|
+
"tool": "create_html_file",
|
|
62
|
+
"params": {
|
|
63
|
+
"file_path": "index.html",
|
|
64
|
+
"title": f"{project_name} - 首页"
|
|
65
|
+
},
|
|
66
|
+
"description": "创建单页面网站主文件",
|
|
67
|
+
"rationale": "生成包含所有内容的单页面"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"step": 5,
|
|
71
|
+
"tool": "add_bootstrap",
|
|
72
|
+
"params": {
|
|
73
|
+
"project_path": "."
|
|
74
|
+
},
|
|
75
|
+
"description": "添加Bootstrap框架",
|
|
76
|
+
"rationale": "加速响应式开发"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"step": 6,
|
|
80
|
+
"tool": "create_responsive_navbar",
|
|
81
|
+
"params": {
|
|
82
|
+
"file_path": "index.html",
|
|
83
|
+
"brand_name": project_name,
|
|
84
|
+
"nav_items": QuickSiteGenerator._get_nav_items(site_type)
|
|
85
|
+
},
|
|
86
|
+
"description": "创建导航栏",
|
|
87
|
+
"rationale": "页面内导航锚点"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"step": 7,
|
|
91
|
+
"tool": "inject_images",
|
|
92
|
+
"params": {
|
|
93
|
+
"file_path": "index.html",
|
|
94
|
+
"provider": "pollinations",
|
|
95
|
+
"topics": QuickSiteGenerator._get_image_topics(site_type),
|
|
96
|
+
"size": "1920x1080",
|
|
97
|
+
"save": True
|
|
98
|
+
},
|
|
99
|
+
"description": "注入AI生成图片",
|
|
100
|
+
"rationale": "添加视觉内容"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"step": 8,
|
|
104
|
+
"tool": "open_in_browser",
|
|
105
|
+
"params": {
|
|
106
|
+
"file_path": "index.html"
|
|
107
|
+
},
|
|
108
|
+
"description": "浏览器预览",
|
|
109
|
+
"rationale": "查看最终效果"
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
# 根据网站类型定制配色
|
|
114
|
+
color_scheme = QuickSiteGenerator._get_color_scheme(site_type)
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
"task_analysis": f"快速生成{site_type}单页面网站",
|
|
118
|
+
"project_name": project_name,
|
|
119
|
+
"site_type": site_type,
|
|
120
|
+
"design_style": "现代简洁",
|
|
121
|
+
"color_scheme": color_scheme,
|
|
122
|
+
"estimated_time": "2-3分钟",
|
|
123
|
+
"tools_sequence": base_steps
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def _get_nav_items(site_type: str) -> List[Dict[str, str]]:
|
|
128
|
+
"""根据网站类型返回导航项(锚点链接)"""
|
|
129
|
+
|
|
130
|
+
nav_templates = {
|
|
131
|
+
"咖啡店": [
|
|
132
|
+
{"name": "首页", "link": "#hero"},
|
|
133
|
+
{"name": "菜单", "link": "#menu"},
|
|
134
|
+
{"name": "关于", "link": "#about"},
|
|
135
|
+
{"name": "联系", "link": "#contact"}
|
|
136
|
+
],
|
|
137
|
+
"企业": [
|
|
138
|
+
{"name": "首页", "link": "#hero"},
|
|
139
|
+
{"name": "服务", "link": "#services"},
|
|
140
|
+
{"name": "关于", "link": "#about"},
|
|
141
|
+
{"name": "联系", "link": "#contact"}
|
|
142
|
+
],
|
|
143
|
+
"作品集": [
|
|
144
|
+
{"name": "首页", "link": "#hero"},
|
|
145
|
+
{"name": "作品", "link": "#portfolio"},
|
|
146
|
+
{"name": "技能", "link": "#skills"},
|
|
147
|
+
{"name": "联系", "link": "#contact"}
|
|
148
|
+
],
|
|
149
|
+
"餐厅": [
|
|
150
|
+
{"name": "首页", "link": "#hero"},
|
|
151
|
+
{"name": "菜单", "link": "#menu"},
|
|
152
|
+
{"name": "预约", "link": "#booking"},
|
|
153
|
+
{"name": "位置", "link": "#location"}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# 默认导航
|
|
158
|
+
default = [
|
|
159
|
+
{"name": "首页", "link": "#hero"},
|
|
160
|
+
{"name": "介绍", "link": "#about"},
|
|
161
|
+
{"name": "服务", "link": "#services"},
|
|
162
|
+
{"name": "联系", "link": "#contact"}
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
# 查找最匹配的类型
|
|
166
|
+
for key in nav_templates:
|
|
167
|
+
if key in site_type:
|
|
168
|
+
return nav_templates[key]
|
|
169
|
+
|
|
170
|
+
return default
|
|
171
|
+
|
|
172
|
+
@staticmethod
|
|
173
|
+
def _get_image_topics(site_type: str) -> List[str]:
|
|
174
|
+
"""根据网站类型返回图片主题"""
|
|
175
|
+
|
|
176
|
+
topics_map = {
|
|
177
|
+
"咖啡": ["coffee shop interior modern", "latte art", "coffee beans", "cozy cafe"],
|
|
178
|
+
"餐厅": ["restaurant interior elegant", "gourmet food", "dining table", "chef cooking"],
|
|
179
|
+
"企业": ["modern office", "business team", "corporate building", "technology workspace"],
|
|
180
|
+
"作品集": ["creative workspace", "design portfolio", "artistic studio", "digital art"],
|
|
181
|
+
"电商": ["product showcase", "online shopping", "ecommerce", "shopping cart"],
|
|
182
|
+
"博客": ["writing desk", "laptop workspace", "books and coffee", "minimal desk setup"]
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
# 查找匹配的主题
|
|
186
|
+
for key, topics in topics_map.items():
|
|
187
|
+
if key in site_type:
|
|
188
|
+
return topics
|
|
189
|
+
|
|
190
|
+
# 默认主题
|
|
191
|
+
return ["modern website hero", "business concept", "technology background", "professional workspace"]
|
|
192
|
+
|
|
193
|
+
@staticmethod
|
|
194
|
+
def _get_color_scheme(site_type: str) -> Dict[str, str]:
|
|
195
|
+
"""根据网站类型返回配色方案"""
|
|
196
|
+
|
|
197
|
+
schemes = {
|
|
198
|
+
"咖啡": {
|
|
199
|
+
"primary": "#6F4E37", # 咖啡棕
|
|
200
|
+
"secondary": "#C8A882", # 奶泡色
|
|
201
|
+
"accent": "#D2691E" # 焦糖色
|
|
202
|
+
},
|
|
203
|
+
"餐厅": {
|
|
204
|
+
"primary": "#8B0000", # 深红
|
|
205
|
+
"secondary": "#FFD700", # 金色
|
|
206
|
+
"accent": "#228B22" # 森林绿
|
|
207
|
+
},
|
|
208
|
+
"企业": {
|
|
209
|
+
"primary": "#003366", # 企业蓝
|
|
210
|
+
"secondary": "#F0F0F0", # 浅灰
|
|
211
|
+
"accent": "#FF6B35" # 橙色
|
|
212
|
+
},
|
|
213
|
+
"作品集": {
|
|
214
|
+
"primary": "#2C3E50", # 深蓝灰
|
|
215
|
+
"secondary": "#ECF0F1", # 云白
|
|
216
|
+
"accent": "#E74C3C" # 红色
|
|
217
|
+
},
|
|
218
|
+
"电商": {
|
|
219
|
+
"primary": "#FF6B6B", # 珊瑚红
|
|
220
|
+
"secondary": "#4ECDC4", # 青绿
|
|
221
|
+
"accent": "#FFE66D" # 黄色
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
# 查找匹配的配色
|
|
226
|
+
for key, scheme in schemes.items():
|
|
227
|
+
if key in site_type:
|
|
228
|
+
return scheme
|
|
229
|
+
|
|
230
|
+
# 默认配色(现代通用)
|
|
231
|
+
return {
|
|
232
|
+
"primary": "#3B82F6", # 蓝色
|
|
233
|
+
"secondary": "#F3F4F6", # 浅灰
|
|
234
|
+
"accent": "#10B981" # 绿色
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@staticmethod
|
|
238
|
+
def optimize_for_speed(plan: Dict[str, Any]) -> Dict[str, Any]:
|
|
239
|
+
"""优化计划以提升生成速度
|
|
240
|
+
|
|
241
|
+
- 移除不必要的验证步骤
|
|
242
|
+
- 简化图片生成
|
|
243
|
+
- 减少工具调用次数
|
|
244
|
+
"""
|
|
245
|
+
optimized_steps = []
|
|
246
|
+
|
|
247
|
+
for step in plan.get("tools_sequence", []):
|
|
248
|
+
tool = step.get("tool", "")
|
|
249
|
+
|
|
250
|
+
# 跳过验证类工具(可选)
|
|
251
|
+
if tool in ["validate_html", "check_mobile_friendly"]:
|
|
252
|
+
continue
|
|
253
|
+
|
|
254
|
+
# 简化图片参数
|
|
255
|
+
if tool == "inject_images":
|
|
256
|
+
params = step.get("params", {})
|
|
257
|
+
# 限制图片数量
|
|
258
|
+
if "topics" in params and len(params["topics"]) > 3:
|
|
259
|
+
params["topics"] = params["topics"][:3]
|
|
260
|
+
# 使用较小的尺寸
|
|
261
|
+
if "size" in params:
|
|
262
|
+
params["size"] = "1280x720"
|
|
263
|
+
step["params"] = params
|
|
264
|
+
|
|
265
|
+
optimized_steps.append(step)
|
|
266
|
+
|
|
267
|
+
plan["tools_sequence"] = optimized_steps
|
|
268
|
+
plan["estimated_time"] = "1-2分钟"
|
|
269
|
+
|
|
270
|
+
return plan
|