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.
- package/dist/build/core/prompt-builder.js +14 -1
- package/dist/build/core/sampling.js +16 -4
- package/dist/build/plugin/loader.js +1 -1
- package/dist/interceptor-web/dist/build-report.json +1 -1
- package/dist/interceptor-web/dist/detail.html +1 -1
- package/dist/interceptor-web/dist/index.html +1 -1
- package/package.json +3 -3
|
@@ -164,7 +164,20 @@ export function buildComponentMappingPrompt(componentMappings, componentContexts
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
prompt +=
|
|
167
|
-
'
|
|
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
|
-
|
|
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;
|