@mybricks/plugin-ai 0.0.2 → 0.0.3
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/_virtual/_rollupPluginBabelHelpers.js +164 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/dist/agents/app.js +335 -0
- package/dist/agents/app.js.map +1 -0
- package/dist/agents/common.js +483 -0
- package/dist/agents/common.js.map +1 -0
- package/dist/agents/custom.js +16 -0
- package/dist/agents/custom.js.map +1 -0
- package/dist/agents/index.js +38 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/knowledges/knowledge-base.js +579 -0
- package/dist/agents/knowledges/knowledge-base.js.map +1 -0
- package/dist/agents/knowledges/knowledge-node.js +228 -0
- package/dist/agents/knowledges/knowledge-node.js.map +1 -0
- package/dist/agents/knowledges/types.js +105 -0
- package/dist/agents/knowledges/types.js.map +1 -0
- package/dist/agents/utils/config.js +229 -0
- package/dist/agents/utils/config.js.map +1 -0
- package/dist/agents/workspace/coding-manager.js +20 -0
- package/dist/agents/workspace/coding-manager.js.map +1 -0
- package/dist/agents/workspace/components-manager.js +113 -0
- package/dist/agents/workspace/components-manager.js.map +1 -0
- package/dist/agents/workspace/outline-focus.js +167 -0
- package/dist/agents/workspace/outline-focus.js.map +1 -0
- package/dist/agents/workspace/outline-info.js +430 -0
- package/dist/agents/workspace/outline-info.js.map +1 -0
- package/dist/agents/workspace/page-tree-generator.js +70 -0
- package/dist/agents/workspace/page-tree-generator.js.map +1 -0
- package/dist/agents/workspace/workspace.js +251 -0
- package/dist/agents/workspace/workspace.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js +100 -0
- package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js +120 -0
- package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js +146 -0
- package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/test.js +242 -0
- package/dist/agents/workspace-by-knowledges/test.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/components-manager.js +132 -0
- package/dist/agents/workspace-by-knowledges/utils/components-manager.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-focus.js +167 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-focus.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-info.js +430 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-info.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/workspace.js +169 -0
- package/dist/agents/workspace-by-knowledges/workspace.js.map +1 -0
- package/dist/api/cloud-components.js +85 -0
- package/dist/api/cloud-components.js.map +1 -0
- package/dist/api-record-replay/manager.js +168 -0
- package/dist/api-record-replay/manager.js.map +1 -0
- package/{src/api-record-replay/recorder.ts → dist/api-record-replay/recorder.js} +22 -32
- package/dist/api-record-replay/recorder.js.map +1 -0
- package/dist/api-record-replay/replayer.js +136 -0
- package/dist/api-record-replay/replayer.js.map +1 -0
- package/dist/components/attachments/index.js +124 -0
- package/dist/components/attachments/index.js.map +1 -0
- package/dist/components/attachments/index.less.js +8 -0
- package/dist/components/attachments/index.less.js.map +1 -0
- package/dist/components/icons/index.js +112 -0
- package/dist/components/icons/index.js.map +1 -0
- package/dist/components/icons/index.less.js +8 -0
- package/dist/components/icons/index.less.js.map +1 -0
- package/dist/components/mention/index.js +19 -0
- package/dist/components/mention/index.js.map +1 -0
- package/dist/components/mention/index.less.js +8 -0
- package/dist/components/mention/index.less.js.map +1 -0
- package/dist/components/messages/index.js +429 -0
- package/dist/components/messages/index.js.map +1 -0
- package/dist/components/messages/index.less.js +8 -0
- package/dist/components/messages/index.less.js.map +1 -0
- package/dist/components/sender/index.js +244 -0
- package/dist/components/sender/index.js.map +1 -0
- package/dist/components/sender/index.less.js +8 -0
- package/dist/components/sender/index.less.js.map +1 -0
- package/dist/context/RequestStatusTracker.js +44 -0
- package/dist/context/RequestStatusTracker.js.map +1 -0
- package/dist/context/index.js +45 -0
- package/dist/context/index.js.map +1 -0
- package/dist/data.js +4 -0
- package/dist/data.js.map +1 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js +27 -0
- package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
- package/dist/plugin-ai/package.json.js +8 -0
- package/dist/plugin-ai/package.json.js.map +1 -0
- package/dist/plugin-ai/test/index.js +206 -0
- package/dist/plugin-ai/test/index.js.map +1 -0
- package/dist/preset/createTemplates.js +29 -0
- package/dist/preset/createTemplates.js.map +1 -0
- package/dist/preset/index.js +13 -0
- package/dist/preset/index.js.map +1 -0
- package/dist/preset/prompts.js +34 -0
- package/dist/preset/prompts.js.map +1 -0
- package/{src/preset/user.ts → dist/preset/user.js} +4 -3
- package/dist/preset/user.js.map +1 -0
- package/dist/requestAsStream.js +269 -0
- package/dist/requestAsStream.js.map +1 -0
- package/dist/rxai/node_modules/idb/build/index.js +277 -0
- package/dist/rxai/node_modules/idb/build/index.js.map +1 -0
- package/dist/rxai/src/agent/base.js +16 -0
- package/dist/rxai/src/agent/base.js.map +1 -0
- package/dist/rxai/src/agent/planning.js +1076 -0
- package/dist/rxai/src/agent/planning.js.map +1 -0
- package/dist/rxai/src/agent/rxai.js +254 -0
- package/dist/rxai/src/agent/rxai.js.map +1 -0
- package/dist/rxai/src/error/base.js +39 -0
- package/dist/rxai/src/error/base.js.map +1 -0
- package/dist/rxai/src/prompt/base.js +11 -0
- package/dist/rxai/src/prompt/base.js.map +1 -0
- package/dist/rxai/src/prompt/planning.js +23 -0
- package/dist/rxai/src/prompt/planning.js.map +1 -0
- package/dist/rxai/src/prompt/tool.js +14 -0
- package/dist/rxai/src/prompt/tool.js.map +1 -0
- package/dist/rxai/src/request/request.js +123 -0
- package/dist/rxai/src/request/request.js.map +1 -0
- package/dist/rxai/src/tool/getHistoryRecords.js +65 -0
- package/dist/rxai/src/tool/getHistoryRecords.js.map +1 -0
- package/dist/rxai/src/tool/util.js +424 -0
- package/dist/rxai/src/tool/util.js.map +1 -0
- package/dist/rxai/src/utils/events.js +43 -0
- package/dist/rxai/src/utils/events.js.map +1 -0
- package/dist/rxai/src/utils/idb.js +240 -0
- package/dist/rxai/src/utils/idb.js.map +1 -0
- package/dist/rxai/src/utils/retry.js +32 -0
- package/dist/rxai/src/utils/retry.js.map +1 -0
- package/dist/rxai/src/utils/uuid.js +7 -0
- package/dist/rxai/src/utils/uuid.js.map +1 -0
- package/dist/startView/components/header/header.js +12 -0
- package/dist/startView/components/header/header.js.map +1 -0
- package/dist/startView/components/header/header.less.js +8 -0
- package/dist/startView/components/header/header.less.js.map +1 -0
- package/dist/startView/index.js +62 -0
- package/dist/startView/index.js.map +1 -0
- package/dist/startView/index.less.js +8 -0
- package/dist/startView/index.less.js.map +1 -0
- package/dist/tools/analyze-and-expand-prd.js +116 -0
- package/dist/tools/analyze-and-expand-prd.js.map +1 -0
- package/dist/tools/analyze-requirement-and-components.js +208 -0
- package/dist/tools/analyze-requirement-and-components.js.map +1 -0
- package/dist/tools/answer.js +33 -0
- package/dist/tools/answer.js.map +1 -0
- package/dist/tools/build-process.js +550 -0
- package/dist/tools/build-process.js.map +1 -0
- package/dist/tools/coding-subagent-as-tool.js +101 -0
- package/dist/tools/coding-subagent-as-tool.js.map +1 -0
- package/dist/tools/generate-ui-content.js +528 -0
- package/dist/tools/generate-ui-content.js.map +1 -0
- package/dist/tools/index.js +31 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/open-dsl.js +49 -0
- package/dist/tools/open-dsl.js.map +1 -0
- package/dist/tools/refactor-ui-content.js +292 -0
- package/dist/tools/refactor-ui-content.js.map +1 -0
- package/dist/tools/utils.js +832 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/view/components/header/header.js +59 -0
- package/dist/view/components/header/header.js.map +1 -0
- package/dist/view/components/header/header.less.js +8 -0
- package/dist/view/components/header/header.less.js.map +1 -0
- package/dist/view/index.js +184 -0
- package/dist/view/index.js.map +1 -0
- package/dist/view/index.less.js +8 -0
- package/dist/view/index.less.js.map +1 -0
- package/package.json +28 -6
- package/src/agents/app.ts +0 -301
- package/src/agents/common.ts +0 -471
- package/src/agents/custom.ts +0 -14
- package/src/agents/index.ts +0 -37
- package/src/agents/knowledges/README.md +0 -614
- package/src/agents/knowledges/SUMMARY.md +0 -527
- package/src/agents/knowledges/index.ts +0 -8
- package/src/agents/knowledges/knowledge-base.ts +0 -565
- package/src/agents/knowledges/knowledge-node.ts +0 -266
- package/src/agents/knowledges/types.ts +0 -208
- package/src/agents/utils/config.ts +0 -427
- package/src/agents/workspace/coding-manager.ts +0 -31
- package/src/agents/workspace/components-manager.ts +0 -124
- package/src/agents/workspace/outline-focus.ts +0 -188
- package/src/agents/workspace/outline-info.ts +0 -520
- package/src/agents/workspace/page-tree-generator.ts +0 -83
- package/src/agents/workspace/workspace.ts +0 -319
- package/src/agents/workspace-by-knowledges/MIGRATION.md +0 -568
- package/src/agents/workspace-by-knowledges/README.md +0 -521
- package/src/agents/workspace-by-knowledges/index.ts +0 -11
- package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +0 -92
- package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +0 -131
- package/src/agents/workspace-by-knowledges/providers/index.ts +0 -8
- package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +0 -151
- package/src/agents/workspace-by-knowledges/test.ts +0 -240
- package/src/agents/workspace-by-knowledges/types.ts +0 -56
- package/src/agents/workspace-by-knowledges/utils/components-manager.ts +0 -145
- package/src/agents/workspace-by-knowledges/utils/index.ts +0 -8
- package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +0 -178
- package/src/agents/workspace-by-knowledges/utils/outline-info.ts +0 -521
- package/src/agents/workspace-by-knowledges/workspace.ts +0 -166
- package/src/api/cloud-components.ts +0 -129
- package/src/api-record-replay/README.md +0 -187
- package/src/api-record-replay/index.ts +0 -11
- package/src/api-record-replay/manager.ts +0 -168
- package/src/api-record-replay/replayer.ts +0 -148
- package/src/components/attachments/index.less +0 -117
- package/src/components/attachments/index.tsx +0 -136
- package/src/components/icons/index.less +0 -8
- package/src/components/icons/index.tsx +0 -44
- package/src/components/index.less +0 -34
- package/src/components/mention/index.less +0 -23
- package/src/components/mention/index.tsx +0 -19
- package/src/components/messages/index.less +0 -1013
- package/src/components/messages/index.tsx +0 -519
- package/src/components/sender/index.less +0 -203
- package/src/components/sender/index.tsx +0 -298
- package/src/components/types.ts +0 -31
- package/src/constants/index.ts +0 -8
- package/src/context/RequestStatusTracker.ts +0 -50
- package/src/context/index.ts +0 -83
- package/src/data.ts +0 -5
- package/src/global.d.ts +0 -100
- package/src/index.tsx +0 -264
- package/src/mock.ts +0 -1267
- package/src/preset/agents.ts +0 -380
- package/src/preset/createTemplates.ts +0 -25
- package/src/preset/index.ts +0 -12
- package/src/preset/prompts.ts +0 -235
- package/src/preset/requestAsStream.ts +0 -246
- package/src/startView/components/header/header.less +0 -17
- package/src/startView/components/header/header.tsx +0 -15
- package/src/startView/components/index.ts +0 -1
- package/src/startView/index.less +0 -34
- package/src/startView/index.tsx +0 -61
- package/src/tools/analyze-and-expand-prd.ts +0 -272
- package/src/tools/analyze-requirement-and-components.ts +0 -589
- package/src/tools/answer.ts +0 -59
- package/src/tools/build-process.ts +0 -1174
- package/src/tools/coding-subagent-as-tool.ts +0 -119
- package/src/tools/generate-ui-content.ts +0 -1083
- package/src/tools/index.ts +0 -28
- package/src/tools/open-dsl.ts +0 -69
- package/src/tools/refactor-ui-content.ts +0 -801
- package/src/tools/type.d.ts +0 -12
- package/src/tools/utils.ts +0 -914
- package/src/types/index.ts +0 -4
- package/src/view/components/header/header.less +0 -51
- package/src/view/components/header/header.tsx +0 -60
- package/src/view/components/index.ts +0 -1
- package/src/view/index.less +0 -5
- package/src/view/index.tsx +0 -168
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { jsonSafeParse } from "./../tools/utils";
|
|
2
|
-
import { context } from "../context";
|
|
3
|
-
|
|
4
|
-
export interface CloudComponentMeta {
|
|
5
|
-
summary?: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
[key: string]: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface CloudComponent {
|
|
11
|
-
namespace: string;
|
|
12
|
-
title?: string;
|
|
13
|
-
meta?: string;
|
|
14
|
-
summary?: string;
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface CloudComponentsApiResponse {
|
|
19
|
-
data?: {
|
|
20
|
-
list?: CloudComponent[];
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
};
|
|
23
|
-
list?: CloudComponent[];
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 查询云组件列表(固定 URL)
|
|
29
|
-
*/
|
|
30
|
-
export async function fetchCloudComponents(): Promise<CloudComponent[]> {
|
|
31
|
-
const url = `/api/material/list?type=component&tags=${encodeURIComponent('含提示词')}&page=1&pageSize=50`;
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const res = await fetch(url, { method: "GET" });
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
throw new Error(`Request failed with status ${res.status}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const json = (await res.json()) as CloudComponentsApiResponse;
|
|
40
|
-
|
|
41
|
-
console.log('json', json);
|
|
42
|
-
const list =
|
|
43
|
-
(json && json.data && Array.isArray(json.data.list) && json.data.list) ||
|
|
44
|
-
(Array.isArray(json.list) ? json.list : []) ||
|
|
45
|
-
[];
|
|
46
|
-
|
|
47
|
-
return list;
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error("[plugin-ai] fetchCloudComponents error:", error);
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 将云组件列表转为「允许使用的组件」的 XML 片段
|
|
56
|
-
* 约定:
|
|
57
|
-
* - namespace 必填
|
|
58
|
-
* - meta.summary 作为 description 使用(若无则尝试其它字段)
|
|
59
|
-
* - 云组件统一视为 UI 组件
|
|
60
|
-
*/
|
|
61
|
-
export function buildCloudComponentsPrompts(
|
|
62
|
-
components: CloudComponent[]
|
|
63
|
-
): string {
|
|
64
|
-
if (!Array.isArray(components) || !components.length) {
|
|
65
|
-
return "";
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return `<可以使用的MyBricks复合组件>
|
|
69
|
-
复合组件是封装好的MyBricks组件,通常比普通组件的功能更强大,但是没那么灵活,因此在使用时,需要根据具体需求选择合适的组件。
|
|
70
|
-
${components.filter((item) => !!item?.namespace).map((item) => {
|
|
71
|
-
|
|
72
|
-
const meta = jsonSafeParse(item.meta as string || "{}");
|
|
73
|
-
|
|
74
|
-
return `<component>
|
|
75
|
-
<namespace>${item.namespace}</namespace>
|
|
76
|
-
<title>${item.title || ""}</title>
|
|
77
|
-
<description>${meta?.ai?.prompts?.summary || ""}</description>
|
|
78
|
-
${meta?.ai?.prompts?.usage || ""}
|
|
79
|
-
</component>
|
|
80
|
-
`}).join("\n")}
|
|
81
|
-
</可以使用的MyBricks复合组件>
|
|
82
|
-
`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 创建 getAllComDefPrompts 方法,返回原有组件信息 + 云组件信息
|
|
87
|
-
*/
|
|
88
|
-
export function createGetAllComDefPrompts(
|
|
89
|
-
getAllComDefPrompts: (() => string) | undefined
|
|
90
|
-
): () => string {
|
|
91
|
-
// 若未启用云组件,则直接返回原有的 getAllComDefPrompts(不请求云组件)
|
|
92
|
-
if (!context.useCloudComponents) {
|
|
93
|
-
return (): string => {
|
|
94
|
-
return getAllComDefPrompts?.() ?? "";
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let cloudPrompts = "";
|
|
99
|
-
fetchCloudComponents()
|
|
100
|
-
.then((list) => {
|
|
101
|
-
cloudPrompts = buildCloudComponentsPrompts(list);
|
|
102
|
-
})
|
|
103
|
-
.catch((error) => {
|
|
104
|
-
console.error(
|
|
105
|
-
"[plugin-ai] createGetAllComDefPrompts fetchCloudComponents error:",
|
|
106
|
-
error
|
|
107
|
-
);
|
|
108
|
-
// 失败就保持 cloudPrompts 为空,只使用原有组件定义
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return (): string => {
|
|
112
|
-
const base = getAllComDefPrompts?.() ?? "";
|
|
113
|
-
|
|
114
|
-
console.log('cloudPrompts', cloudPrompts);
|
|
115
|
-
|
|
116
|
-
if (!cloudPrompts) {
|
|
117
|
-
// 若云组件尚未加载完成,则只返回原有组件定义,避免影响正常使用
|
|
118
|
-
return base;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!base) {
|
|
122
|
-
return cloudPrompts;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return `${cloudPrompts}\n${base}\n`;
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
# API 收集和回放功能
|
|
2
|
-
|
|
3
|
-
## 概述
|
|
4
|
-
|
|
5
|
-
该模块提供了对 `createPage`、`createCanvas`、`updatePage`、`updateUiCom`、`updateLogicCom` 这些 API 的收集和回放功能。
|
|
6
|
-
|
|
7
|
-
## 使用方式
|
|
8
|
-
|
|
9
|
-
### 在浏览器控制台中使用
|
|
10
|
-
|
|
11
|
-
所有功能都通过 `window.APIRecordReplay` 对象提供:
|
|
12
|
-
|
|
13
|
-
#### 1. 开始录制
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
16
|
-
// 开始录制 API 调用
|
|
17
|
-
window.APIRecordReplay.start();
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
#### 2. 执行操作
|
|
21
|
-
|
|
22
|
-
录制开始后,所有对 `createPage`、`createCanvas`、`updatePage`、`updateUiCom`、`updateLogicCom` 的调用都会被自动记录。
|
|
23
|
-
|
|
24
|
-
#### 3. 停止录制
|
|
25
|
-
|
|
26
|
-
```javascript
|
|
27
|
-
// 停止录制
|
|
28
|
-
window.APIRecordReplay.stop();
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
#### 4. 导出记录
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
// 导出为 JSON 字符串
|
|
35
|
-
const jsonString = window.APIRecordReplay.dump();
|
|
36
|
-
console.log(jsonString);
|
|
37
|
-
|
|
38
|
-
// 或者获取记录数组
|
|
39
|
-
const records = window.APIRecordReplay.getRecords();
|
|
40
|
-
console.log(records);
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
#### 5. 回放记录
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
// 回放当前录制的记录
|
|
47
|
-
await window.APIRecordReplay.replay();
|
|
48
|
-
|
|
49
|
-
// 或者从 JSON 字符串回放
|
|
50
|
-
const jsonString = '[...]'; // 之前导出的 JSON
|
|
51
|
-
await window.APIRecordReplay.replayFromJSON(jsonString);
|
|
52
|
-
|
|
53
|
-
// 或者回放指定的记录数组
|
|
54
|
-
const records = window.APIRecordReplay.getRecords();
|
|
55
|
-
await window.APIRecordReplay.replay(records);
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
#### 6. 回放选项
|
|
59
|
-
|
|
60
|
-
```javascript
|
|
61
|
-
// 带选项的回放
|
|
62
|
-
await window.APIRecordReplay.replay(undefined, {
|
|
63
|
-
// 忽略时间间隔,立即执行
|
|
64
|
-
ignoreDelay: false,
|
|
65
|
-
|
|
66
|
-
// 时间间隔倍数(1.0 = 正常速度,2.0 = 2倍速,0.5 = 0.5倍速)
|
|
67
|
-
delayMultiplier: 1.0,
|
|
68
|
-
|
|
69
|
-
// 每个操作执行前的回调
|
|
70
|
-
onBeforeAction: (action, index) => {
|
|
71
|
-
console.log(`准备执行操作 ${index}: ${action.type}`);
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
// 每个操作执行后的回调
|
|
75
|
-
onAfterAction: (action, index, result) => {
|
|
76
|
-
console.log(`操作 ${index} 完成:`, result);
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
// 回放完成后的回调
|
|
80
|
-
onComplete: () => {
|
|
81
|
-
console.log('回放完成');
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
// 回放出错时的回调
|
|
85
|
-
onError: (error, action, index) => {
|
|
86
|
-
console.error(`操作 ${index} 出错:`, error);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
#### 7. 其他操作
|
|
92
|
-
|
|
93
|
-
```javascript
|
|
94
|
-
// 检查是否正在录制
|
|
95
|
-
const isRecording = window.APIRecordReplay.isRecording();
|
|
96
|
-
console.log('正在录制:', isRecording);
|
|
97
|
-
|
|
98
|
-
// 清空记录
|
|
99
|
-
window.APIRecordReplay.clear();
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 完整示例
|
|
103
|
-
|
|
104
|
-
```javascript
|
|
105
|
-
// 1. 开始录制
|
|
106
|
-
window.APIRecordReplay.start();
|
|
107
|
-
|
|
108
|
-
// 2. 执行一些操作(这些操作会被自动记录)
|
|
109
|
-
// await context.designer.createPage('canvas-id', 'Page Title');
|
|
110
|
-
// await context.designer.createCanvas();
|
|
111
|
-
// await context.designer.updatePage(...args);
|
|
112
|
-
// await context.designer.updateUiCom(...args);
|
|
113
|
-
// await context.designer.updateLogicCom(...args);
|
|
114
|
-
|
|
115
|
-
// 3. 停止录制
|
|
116
|
-
window.APIRecordReplay.stop();
|
|
117
|
-
|
|
118
|
-
// 4. 导出记录
|
|
119
|
-
const jsonString = window.APIRecordReplay.dump();
|
|
120
|
-
console.log('导出的 JSON:', jsonString);
|
|
121
|
-
|
|
122
|
-
// 5. 保存到文件或复制到剪贴板
|
|
123
|
-
// copy(jsonString); // 如果浏览器支持
|
|
124
|
-
|
|
125
|
-
// 6. 回放记录
|
|
126
|
-
await window.APIRecordReplay.replay({
|
|
127
|
-
onBeforeAction: (action, index) => {
|
|
128
|
-
console.log(`执行操作 ${index + 1}: ${action.type}`);
|
|
129
|
-
},
|
|
130
|
-
onComplete: () => {
|
|
131
|
-
console.log('回放完成');
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## 记录格式
|
|
137
|
-
|
|
138
|
-
记录的 JSON 格式如下:
|
|
139
|
-
|
|
140
|
-
```json
|
|
141
|
-
[
|
|
142
|
-
{
|
|
143
|
-
"type": "createPage",
|
|
144
|
-
"params": ["canvas-id", "Page Title", { "config": "value" }],
|
|
145
|
-
"delay": 0,
|
|
146
|
-
"timestamp": 1234567890123
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
"type": "createCanvas",
|
|
150
|
-
"params": [],
|
|
151
|
-
"delay": 100,
|
|
152
|
-
"timestamp": 1234567890223
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
"type": "updatePage",
|
|
156
|
-
"params": [["action1"], "ing"],
|
|
157
|
-
"delay": 50,
|
|
158
|
-
"timestamp": 1234567890273
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
"type": "updateUiCom",
|
|
162
|
-
"params": ["comId", ["action1"], "ing"],
|
|
163
|
-
"delay": 30,
|
|
164
|
-
"timestamp": 1234567890303
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
"type": "updateLogicCom",
|
|
168
|
-
"params": ["comId", ["action1"], "ing"],
|
|
169
|
-
"delay": 30,
|
|
170
|
-
"timestamp": 1234567890333
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
- `type`: 操作类型('createPage' | 'createCanvas' | 'updatePage' | 'updateUiCom' | 'updateLogicCom')
|
|
176
|
-
- `params`: 调用参数数组
|
|
177
|
-
- `delay`: 距离上一次调用的时间间隔(毫秒)
|
|
178
|
-
- `timestamp`: 时间戳(可选,用于调试)
|
|
179
|
-
|
|
180
|
-
## 注意事项
|
|
181
|
-
|
|
182
|
-
1. 录制功能会自动在 API 调用时记录,无需手动调用记录方法
|
|
183
|
-
2. 函数参数会被序列化为特殊标记,无法完全还原
|
|
184
|
-
3. 回放时会按照原始时间间隔执行,确保使用 `await` 等待完成
|
|
185
|
-
4. 如果 API 调用失败,默认会继续执行后续操作,错误会通过 `onError` 回调通知
|
|
186
|
-
5. 回放使用的是当前上下文中的 API,确保 API 可用
|
|
187
|
-
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 收集和回放统一导出
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { apiRecorder, RecordedAction, RecordedActionType } from './recorder';
|
|
6
|
-
import { replay, replayFromJSON, ReplayAPI, ReplayOptions } from './replayer';
|
|
7
|
-
import { APIRecordReplayManager } from './manager';
|
|
8
|
-
|
|
9
|
-
export { apiRecorder, replay, replayFromJSON, APIRecordReplayManager };
|
|
10
|
-
export type { RecordedAction, RecordedActionType, ReplayAPI, ReplayOptions };
|
|
11
|
-
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 记录和回放管理器
|
|
3
|
-
* 提供录制、dump 和回放功能
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { apiRecorder, RecordedAction } from './recorder';
|
|
7
|
-
import { replay, replayFromJSON, ReplayAPI, ReplayOptions } from './replayer';
|
|
8
|
-
import { context } from '../context';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 获取 API 实例的辅助函数
|
|
12
|
-
* 从 context.designer 获取 API
|
|
13
|
-
*/
|
|
14
|
-
function getAPI() {
|
|
15
|
-
return context.designer;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* API 记录和回放管理器
|
|
20
|
-
* 提供录制、dump 和回放功能
|
|
21
|
-
*/
|
|
22
|
-
export class APIRecordReplayManager {
|
|
23
|
-
/**
|
|
24
|
-
* 开始录制 API 调用
|
|
25
|
-
*/
|
|
26
|
-
start() {
|
|
27
|
-
apiRecorder.start();
|
|
28
|
-
console.log('[APIRecordReplay] 开始录制');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 停止录制
|
|
33
|
-
*/
|
|
34
|
-
stop() {
|
|
35
|
-
apiRecorder.stop();
|
|
36
|
-
console.log('[APIRecordReplay] 停止录制');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 导出录制的 JSON 字符串
|
|
41
|
-
* @returns JSON 字符串
|
|
42
|
-
*/
|
|
43
|
-
dump(): string {
|
|
44
|
-
const json = apiRecorder.dump();
|
|
45
|
-
console.log('[APIRecordReplay] 导出记录:', json);
|
|
46
|
-
return json;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 获取记录数组
|
|
51
|
-
* @returns 记录数组
|
|
52
|
-
*/
|
|
53
|
-
getRecords(): RecordedAction[] {
|
|
54
|
-
return apiRecorder.getRecords();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 清空记录
|
|
59
|
-
*/
|
|
60
|
-
clear() {
|
|
61
|
-
apiRecorder.clear();
|
|
62
|
-
console.log('[APIRecordReplay] 已清空记录');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 检查是否正在录制
|
|
67
|
-
* @returns 是否正在录制
|
|
68
|
-
*/
|
|
69
|
-
isRecording(): boolean {
|
|
70
|
-
return apiRecorder.getRecording();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 回放记录的 API 调用
|
|
75
|
-
* @param records 记录数组(可选,如果不提供则使用当前录制的记录)
|
|
76
|
-
* @param options 回放选项(可选)
|
|
77
|
-
*/
|
|
78
|
-
async replay(records?: RecordedAction[], options?: ReplayOptions) {
|
|
79
|
-
const api = getAPI();
|
|
80
|
-
if (!api) {
|
|
81
|
-
console.error('[APIRecordReplay] API 不可用');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const replayAPI: ReplayAPI = {
|
|
86
|
-
createPage: api.createPage!.bind(api),
|
|
87
|
-
createCanvas: api.createCanvas!.bind(api),
|
|
88
|
-
updatePage: api.updatePage!.bind(api),
|
|
89
|
-
updateUiCom: api.updateUiCom!.bind(api),
|
|
90
|
-
updateLogicCom: api.updateLogicCom!.bind(api),
|
|
91
|
-
createDiagram: api.createDiagram!.bind(api),
|
|
92
|
-
updateDiagram: api.updateDiagram!.bind(api)
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const recordsToReplay = records || apiRecorder.getRecords();
|
|
96
|
-
|
|
97
|
-
if (recordsToReplay.length === 0) {
|
|
98
|
-
console.warn('[APIRecordReplay] 没有可回放的记录');
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
console.log(`[APIRecordReplay] 开始回放 ${recordsToReplay.length} 条记录`);
|
|
103
|
-
|
|
104
|
-
await replay(recordsToReplay, replayAPI, {
|
|
105
|
-
onBeforeAction: (action, index) => {
|
|
106
|
-
console.log(`[APIRecordReplay] 执行操作 ${index + 1}/${recordsToReplay.length}: ${action.type}`);
|
|
107
|
-
options?.onBeforeAction?.(action, index);
|
|
108
|
-
},
|
|
109
|
-
onAfterAction: (action, index, result) => {
|
|
110
|
-
options?.onAfterAction?.(action, index, result);
|
|
111
|
-
},
|
|
112
|
-
onComplete: () => {
|
|
113
|
-
console.log('[APIRecordReplay] 回放完成');
|
|
114
|
-
options?.onComplete?.();
|
|
115
|
-
},
|
|
116
|
-
onError: (error, action, index) => {
|
|
117
|
-
console.error(`[APIRecordReplay] 回放出错:`, error);
|
|
118
|
-
options?.onError?.(error, action, index);
|
|
119
|
-
},
|
|
120
|
-
...options
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 从 JSON 字符串回放
|
|
126
|
-
* @param jsonString JSON 字符串
|
|
127
|
-
* @param options 回放选项(可选)
|
|
128
|
-
*/
|
|
129
|
-
async replayFromJSON(jsonString: string, options?: ReplayOptions) {
|
|
130
|
-
const api = getAPI();
|
|
131
|
-
if (!api) {
|
|
132
|
-
console.error('[APIRecordReplay] API 不可用');
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const replayAPI: ReplayAPI = {
|
|
137
|
-
createPage: api.createPage!.bind(api),
|
|
138
|
-
createCanvas: api.createCanvas!.bind(api),
|
|
139
|
-
updatePage: api.updatePage!.bind(api),
|
|
140
|
-
updateUiCom: api.updateUiCom!.bind(api),
|
|
141
|
-
updateLogicCom: api.updateLogicCom!.bind(api),
|
|
142
|
-
createDiagram: api.createDiagram!.bind(api),
|
|
143
|
-
updateDiagram: api.updateDiagram!.bind(api)
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
console.log('[APIRecordReplay] 从 JSON 开始回放');
|
|
147
|
-
|
|
148
|
-
await replayFromJSON(jsonString, replayAPI, {
|
|
149
|
-
onBeforeAction: (action, index) => {
|
|
150
|
-
console.log(`[APIRecordReplay] 执行操作 ${index + 1}: ${action.type}`);
|
|
151
|
-
options?.onBeforeAction?.(action, index);
|
|
152
|
-
},
|
|
153
|
-
onAfterAction: (action, index, result) => {
|
|
154
|
-
options?.onAfterAction?.(action, index, result);
|
|
155
|
-
},
|
|
156
|
-
onComplete: () => {
|
|
157
|
-
console.log('[APIRecordReplay] 回放完成');
|
|
158
|
-
options?.onComplete?.();
|
|
159
|
-
},
|
|
160
|
-
onError: (error, action, index) => {
|
|
161
|
-
console.error(`[APIRecordReplay] 回放出错:`, error);
|
|
162
|
-
options?.onError?.(error, action, index);
|
|
163
|
-
},
|
|
164
|
-
...options
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API 调用回放模块
|
|
3
|
-
* 根据记录的 JSON 序列执行回放
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { RecordedAction, RecordedActionType } from './recorder';
|
|
7
|
-
|
|
8
|
-
export interface ReplayOptions {
|
|
9
|
-
/** 是否忽略时间间隔,立即执行 */
|
|
10
|
-
ignoreDelay?: boolean;
|
|
11
|
-
/** 时间间隔的倍数(用于加速或减速回放) */
|
|
12
|
-
delayMultiplier?: number;
|
|
13
|
-
/** 每个操作执行前的回调 */
|
|
14
|
-
onBeforeAction?: (action: RecordedAction, index: number) => void;
|
|
15
|
-
/** 每个操作执行后的回调 */
|
|
16
|
-
onAfterAction?: (action: RecordedAction, index: number, result: any) => void;
|
|
17
|
-
/** 回放完成后的回调 */
|
|
18
|
-
onComplete?: () => void;
|
|
19
|
-
/** 回放出错时的回调 */
|
|
20
|
-
onError?: (error: Error, action: RecordedAction, index: number) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ReplayAPI {
|
|
24
|
-
createPage: (id: string, title: string, config?: any) => Promise<{ id: string; onProgress: Function; }>;
|
|
25
|
-
createCanvas: () => Promise<{ id: string; title: string; }>;
|
|
26
|
-
updatePage: (...params: any[]) => Promise<void>;
|
|
27
|
-
updateUiCom: (...params: any[]) => Promise<void>;
|
|
28
|
-
updateLogicCom: (...params: any[]) => Promise<void>;
|
|
29
|
-
createDiagram: (...params: any[]) => Promise<any>;
|
|
30
|
-
updateDiagram: (...params: any[]) => Promise<any>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 回放记录的 API 调用
|
|
35
|
-
* @param records 记录的 API 调用序列
|
|
36
|
-
* @param api API 实现对象
|
|
37
|
-
* @param options 回放选项
|
|
38
|
-
*/
|
|
39
|
-
export async function replay(
|
|
40
|
-
records: RecordedAction[],
|
|
41
|
-
api: ReplayAPI,
|
|
42
|
-
options: ReplayOptions = {}
|
|
43
|
-
): Promise<void> {
|
|
44
|
-
const {
|
|
45
|
-
ignoreDelay = false,
|
|
46
|
-
delayMultiplier = 1,
|
|
47
|
-
onBeforeAction,
|
|
48
|
-
onAfterAction,
|
|
49
|
-
onComplete,
|
|
50
|
-
onError,
|
|
51
|
-
} = options;
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < records.length; i++) {
|
|
54
|
-
const action = records[i];
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
// 执行前回调
|
|
58
|
-
onBeforeAction?.(action, i);
|
|
59
|
-
|
|
60
|
-
// 等待时间间隔
|
|
61
|
-
if (!ignoreDelay && action.delay > 0) {
|
|
62
|
-
const delay = action.delay * delayMultiplier;
|
|
63
|
-
await sleep(delay);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 执行 API 调用
|
|
67
|
-
let result: any;
|
|
68
|
-
switch (action.type) {
|
|
69
|
-
case 'createPage': {
|
|
70
|
-
const [id, title, config] = action.params;
|
|
71
|
-
result = await api.createPage(id, title, config);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
case 'createCanvas': {
|
|
75
|
-
result = await api.createCanvas();
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case 'updatePage': {
|
|
79
|
-
// updatePage 的参数是展开的,需要展开传递
|
|
80
|
-
result = await api.updatePage(...action.params);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
case 'updateUiCom': {
|
|
84
|
-
// updateUiCom 的参数是展开的,需要展开传递
|
|
85
|
-
result = await api.updateUiCom(...action.params);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case 'updateLogicCom': {
|
|
89
|
-
// updateLogicCom 的参数是展开的,需要展开传递
|
|
90
|
-
result = await api.updateLogicCom(...action.params);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
case 'createDiagram': {
|
|
94
|
-
// createDiagram 的参数是展开的,需要展开传递
|
|
95
|
-
result = await api.createDiagram(...action.params);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case 'updateDiagram': {
|
|
99
|
-
// updateDiagram 的参数是展开的,需要展开传递
|
|
100
|
-
result = await api.updateDiagram(...action.params);
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
default:
|
|
104
|
-
throw new Error(`Unknown action type: ${(action as any).type}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 执行后回调
|
|
108
|
-
onAfterAction?.(action, i, result);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
111
|
-
onError?.(err, action, i);
|
|
112
|
-
|
|
113
|
-
// 根据选项决定是否继续执行
|
|
114
|
-
// 默认继续执行,只记录错误
|
|
115
|
-
console.error(`Replay error at action ${i} (${action.type}):`, err);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// 完成回调
|
|
120
|
-
onComplete?.();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 从 JSON 字符串加载并回放
|
|
125
|
-
* @param jsonString JSON 字符串
|
|
126
|
-
* @param api API 实现对象
|
|
127
|
-
* @param options 回放选项
|
|
128
|
-
*/
|
|
129
|
-
export async function replayFromJSON(
|
|
130
|
-
jsonString: string,
|
|
131
|
-
api: ReplayAPI,
|
|
132
|
-
options: ReplayOptions = {}
|
|
133
|
-
): Promise<void> {
|
|
134
|
-
try {
|
|
135
|
-
const records: RecordedAction[] = JSON.parse(jsonString);
|
|
136
|
-
await replay(records, api, options);
|
|
137
|
-
} catch (error) {
|
|
138
|
-
throw new Error(`Failed to parse replay JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 睡眠函数
|
|
144
|
-
*/
|
|
145
|
-
function sleep(ms: number): Promise<void> {
|
|
146
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
147
|
-
}
|
|
148
|
-
|