sloth-d2c-mcp 1.0.4-beta90 → 1.0.4-beta92

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.
@@ -164,7 +164,20 @@ export function buildComponentMappingPrompt(componentMappings, componentContexts
164
164
  }
165
165
  });
166
166
  prompt +=
167
- '**重要**:在最终写入代码时,请根据设计稿需求合理传递 props 参数。请按照项目路径规范合理引入组件。如果组件有继承关系,请注意父类的 props 和方法也可以使用。\n';
167
+ '**重要**:在最终写入代码时,请根据设计稿需求合理传递组件参数。请按照项目路径规范合理引入组件。如果组件有继承关系,请注意父类的参数和方法也可以使用。\n';
168
+ }
169
+ // 构建组件映射的设计稿代码(用于 AI 提取组件参数)
170
+ const mappingsWithCode = componentMappings.filter((m) => m.code);
171
+ if (mappingsWithCode.length > 0) {
172
+ prompt += '\n\n## 组件映射设计稿代码\n\n';
173
+ prompt += '以下是已映射组件对应的设计稿绝对定位代码,请根据这些代码提取信息,在使用组件时传入相应参数:\n\n';
174
+ mappingsWithCode.forEach((mapping) => {
175
+ prompt += `### ${mapping.groupName}\n\n`;
176
+ prompt += '```html\n';
177
+ prompt += mapping.code;
178
+ prompt += '\n```\n\n';
179
+ });
180
+ prompt += '**重要**:请从上述 HTML 代码中提取信息,作为对应组件的初始化参数。\n';
168
181
  }
169
182
  // 构建标记组件提示词
170
183
  if (markedComponents.length > 0) {
@@ -40,21 +40,33 @@ export function buildNestingStructure(groupsData) {
40
40
  return { childrenMap, rootGroups, groupMap, allChildIndices };
41
41
  }
42
42
  /**
43
- * 处理组件映射(如果已映射则跳过采样)
43
+ * 处理组件映射(生成 HTML 代码供 AI 提取 props)
44
44
  * @param group 分组数据
45
+ * @param nodeList 节点列表
45
46
  * @param componentMappings 组件映射数组
47
+ * @param imageMap 图片映射
48
+ * @param convertConfig 转换配置
46
49
  * @returns 采样结果或 null
47
50
  */
48
- export function handleComponentMapping(group, componentMappings) {
51
+ export async function handleComponentMapping(group, nodeList, componentMappings, imageMap, convertConfig) {
49
52
  if (group.componentMapping) {
50
53
  const componentName = group.componentMapping.name || `Group${group.groupIndex + 1}`;
51
54
  group.name = componentName;
55
+ // 生成带绝对定位的 HTML 代码,供 AI 提取 props 信息
56
+ const resetNodeList = resetNodeListPosition(nodeList);
57
+ const code = await getCode({
58
+ d2cNodeList: resetNodeList,
59
+ config: convertConfig,
60
+ });
61
+ const replacedCode = replaceImageSrc(code, imageMap);
52
62
  componentMappings.push({
53
63
  groupIndex: group.groupIndex,
54
64
  groupName: componentName,
55
65
  component: group.componentMapping,
66
+ code: replacedCode,
56
67
  });
57
- return { skipped: true, groupIndex: group.groupIndex, componentName };
68
+ Logger.log(`组 ${group.groupIndex} 已映射组件 ${componentName},生成 HTML 代码长度: ${replacedCode.length}`);
69
+ return { skipped: true, groupIndex: group.groupIndex, componentName, code: replacedCode };
58
70
  }
59
71
  return null;
60
72
  }
@@ -138,7 +150,7 @@ export async function sampleSingleGroup(group, nodeList, config) {
138
150
  const { d2cNodeList, imageMap, convertConfig, frameworkPrompt, chunkPrompt, mcpServer, componentMappings, codeSnippets, componentContexts, isSupportSampling } = config;
139
151
  Logger.log(`开始采样组 ${group.groupIndex}, 元素数量: ${group.elements.length}, nodeList 长度: ${nodeList.length}`);
140
152
  // 检查组件映射
141
- const mappingResult = handleComponentMapping(group, componentMappings);
153
+ const mappingResult = await handleComponentMapping(group, nodeList, componentMappings, imageMap, convertConfig);
142
154
  if (mappingResult) {
143
155
  Logger.log(`组 ${group.groupIndex} 已映射组件,跳过采样: ${mappingResult.componentName}`);
144
156
  return mappingResult;
@@ -17,7 +17,7 @@ function hasPnpm() {
17
17
  }
18
18
  // 获取包管理器命令
19
19
  function getPackageManager() {
20
- return hasPnpm() ? 'pnpm' : 'npm';
20
+ return /* hasPnpm() ? 'pnpm' : */ 'npm';
21
21
  }
22
22
  // 使用 env-paths 获取配置目录(与 config-manager 保持一致)
23
23
  const paths = envPaths('d2c-mcp');
@@ -1,5 +1,5 @@
1
1
  {
2
- "buildTime": "2026-01-07T02:01:53.150Z",
2
+ "buildTime": "2026-01-08T13:05:13.453Z",
3
3
  "mode": "build",
4
4
  "pages": {
5
5
  "main": {