@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,298 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState, useImperativeHandle, PropsWithoutRef, forwardRef } from "react"
|
|
2
|
-
import classNames from "classnames";
|
|
3
|
-
import { message } from "antd";
|
|
4
|
-
import { Attachment, Loading, Send, Code } from "../icons";
|
|
5
|
-
import { MentionTag } from "../mention";
|
|
6
|
-
import { AttachmentsList } from "../attachments";
|
|
7
|
-
import { Mention, Attachments } from "../types";
|
|
8
|
-
import css from "./index.less"
|
|
9
|
-
|
|
10
|
-
const readFileToBase64 = (file: File): Promise<string> => {
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const reader = new FileReader();
|
|
13
|
-
reader.onload = function (event) {
|
|
14
|
-
if (event.target) {
|
|
15
|
-
const base64 = event.target.result as string;
|
|
16
|
-
resolve(base64);
|
|
17
|
-
} else {
|
|
18
|
-
reject(event);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
reader.onerror = function (event) {
|
|
22
|
-
reject(event);
|
|
23
|
-
};
|
|
24
|
-
reader.readAsDataURL(file);
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface SenderProps {
|
|
29
|
-
onSend: (message: {
|
|
30
|
-
message: string;
|
|
31
|
-
attachments: Attachments;
|
|
32
|
-
mentions: Mention[];
|
|
33
|
-
[key: string]: any;
|
|
34
|
-
}) => void;
|
|
35
|
-
onMentionClick?: (mention: Mention) => void;
|
|
36
|
-
loading?: boolean;
|
|
37
|
-
placeholder?: string;
|
|
38
|
-
attachmentsPrompt?: string;
|
|
39
|
-
disabled?: boolean;
|
|
40
|
-
onBlur?: () => void;
|
|
41
|
-
mode?: "mention"
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface SenderRef {
|
|
45
|
-
focus: () => void;
|
|
46
|
-
// TODO: 目前仅展示聚焦组件且单个比较简单直接set即可,后续可通过输入框@唤起选择多个
|
|
47
|
-
setMentions: (mentions: Mention[]) => void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const Sender = forwardRef<SenderRef, SenderProps>((props, ref) => {
|
|
51
|
-
const { loading, placeholder = "请输入", disabled, onMentionClick, onBlur, attachmentsPrompt, mode } = props;
|
|
52
|
-
const inputEditorRef = useRef<HTMLDivElement>(null);
|
|
53
|
-
const [isComposing, setIsComposing] = useState(false);
|
|
54
|
-
const [inputContent, setInputContent] = useState<string | null>(null);
|
|
55
|
-
const [attachments, setAttachments] = useState<Attachments>([]);
|
|
56
|
-
const [mentions, setMentions] = useState<Mention[]>([]);
|
|
57
|
-
const [vibeCoding, setVibeCoding] = useState(false);
|
|
58
|
-
|
|
59
|
-
useImperativeHandle(ref, () => {
|
|
60
|
-
return {
|
|
61
|
-
focus: () => {
|
|
62
|
-
inputEditorRef.current!.focus()
|
|
63
|
-
},
|
|
64
|
-
setMentions: (mentions) => {
|
|
65
|
-
setMentions(mentions)
|
|
66
|
-
setVibeCoding(mentions[0]?.vibeCoding || false);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
|
|
71
|
-
const send = () => {
|
|
72
|
-
const inputContent = inputEditorRef.current!.textContent;
|
|
73
|
-
if (inputContent && !loading && !disabled) {
|
|
74
|
-
props.onSend({
|
|
75
|
-
message: inputContent,
|
|
76
|
-
attachments,
|
|
77
|
-
mentions,
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
setAttachments([]);
|
|
81
|
-
setInputContent("");
|
|
82
|
-
inputEditorRef.current!.textContent = "";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const onInput = () => {
|
|
87
|
-
setInputContent(inputEditorRef.current!.textContent)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
91
|
-
if (event.key === "Enter") {
|
|
92
|
-
if (isComposing) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (event.shiftKey) {
|
|
97
|
-
|
|
98
|
-
} else {
|
|
99
|
-
event.preventDefault();
|
|
100
|
-
send();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const onCompositionStart = () => {
|
|
106
|
-
setIsComposing(true);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const onCompositionEnd = () => {
|
|
110
|
-
setIsComposing(false);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** 检查附件数量是否超出限制,超出返回 true */
|
|
114
|
-
const checkAttachmentsLimit = () => {
|
|
115
|
-
if (attachments.length > 1) {
|
|
116
|
-
message.info("当前只能上传两张图片");
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const updateAttachmentsByFile = (file: File) => {
|
|
123
|
-
if (file.size > 5000 * 1024) {
|
|
124
|
-
message.info(`当前文件大小 ${(file.size / 1024).toFixed(2)}K,超过了5000K,建议您截取页面中的某个区域作为附件`)
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
readFileToBase64(file)
|
|
128
|
-
.then((base64) => {
|
|
129
|
-
setAttachments((attachments) => {
|
|
130
|
-
return [...attachments, { type: "image", content: base64 }]
|
|
131
|
-
})
|
|
132
|
-
if (!inputContent && attachmentsPrompt) {
|
|
133
|
-
setInputContent(attachmentsPrompt);
|
|
134
|
-
const selection = window.getSelection();
|
|
135
|
-
|
|
136
|
-
if (!selection?.rangeCount) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const range = selection.getRangeAt(0);
|
|
141
|
-
const textNode = document.createTextNode(attachmentsPrompt);
|
|
142
|
-
range.insertNode(textNode);
|
|
143
|
-
range.setStartAfter(textNode);
|
|
144
|
-
range.setEndAfter(textNode);
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
.catch((event) => {
|
|
148
|
-
console.error("[@mybricks/plugin-ai - 上传附件失败]", event);
|
|
149
|
-
message.error("[@mybricks/plugin-ai - 上传附件失败]");
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const uploadAttachment = () => {
|
|
154
|
-
if (loading || disabled) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
if (checkAttachmentsLimit()) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const fileInput = document.createElement('input');
|
|
161
|
-
fileInput.type = 'file';
|
|
162
|
-
fileInput.accept = 'image/*';
|
|
163
|
-
|
|
164
|
-
fileInput.addEventListener('change', function (e) {
|
|
165
|
-
const target = e.target as HTMLInputElement;
|
|
166
|
-
if (!target) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
const file = target.files?.[0];
|
|
170
|
-
|
|
171
|
-
if (file) {
|
|
172
|
-
if (!file.type.startsWith('image/')) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
updateAttachmentsByFile(file);
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
fileInput.click();
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const onPaste = (event: React.ClipboardEvent<HTMLDivElement>) => {
|
|
184
|
-
event.preventDefault();
|
|
185
|
-
if (loading || disabled) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const file = event.clipboardData.files[0];
|
|
189
|
-
if (file?.type.startsWith('image/')) {
|
|
190
|
-
if (checkAttachmentsLimit()) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
updateAttachmentsByFile(file);
|
|
194
|
-
} else {
|
|
195
|
-
const content = event.clipboardData.getData('text/plain');
|
|
196
|
-
|
|
197
|
-
if (!content) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const selection = window.getSelection();
|
|
202
|
-
|
|
203
|
-
if (!selection?.rangeCount) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const range = selection.getRangeAt(0);
|
|
208
|
-
range.deleteContents();
|
|
209
|
-
const textNode = document.createTextNode(content);
|
|
210
|
-
range.insertNode(textNode);
|
|
211
|
-
range.setStartAfter(textNode);
|
|
212
|
-
range.setEndAfter(textNode);
|
|
213
|
-
|
|
214
|
-
setInputContent(inputEditorRef.current!.textContent)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const onAttachmentsDelete = (index: number) => {
|
|
219
|
-
setAttachments((attachments) => {
|
|
220
|
-
attachments.splice(index, 1)
|
|
221
|
-
return [...attachments]
|
|
222
|
-
})
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return (
|
|
226
|
-
<div className={css.container}>
|
|
227
|
-
<div className={classNames(css.editor, {
|
|
228
|
-
[css.noMentions]: mode === "mention" && !mentions.length
|
|
229
|
-
})}>
|
|
230
|
-
{attachments.length ? (
|
|
231
|
-
<div className={css.topArea}>
|
|
232
|
-
<AttachmentsList attachments={attachments} onDelete={onAttachmentsDelete}/>
|
|
233
|
-
</div>
|
|
234
|
-
) : null}
|
|
235
|
-
{mentions.length ? (
|
|
236
|
-
<div className={css.mentions}>
|
|
237
|
-
<span>对于</span>
|
|
238
|
-
<MentionTag mention={mentions[0]} onClick={onMentionClick} />
|
|
239
|
-
<span>{(mentions[0].type === "page" ? "页面" : "组件") + (mentions[0].focusArea ? "的" : "")}</span>
|
|
240
|
-
{mentions[0].focusArea ? (
|
|
241
|
-
<span className={css.focusarea}>
|
|
242
|
-
{mentions[0].focusArea.title || "区域"}
|
|
243
|
-
</span>
|
|
244
|
-
) : null}
|
|
245
|
-
{/* {vibeCoding ? <span className={css.vibeCoding}>(开发中)</span> : null} */}
|
|
246
|
-
{/* {mentions.map((mention) => {
|
|
247
|
-
return <MentionTag key={mention.id} mention={mention} onClick={onMentionClick} />
|
|
248
|
-
})} */}
|
|
249
|
-
</div>
|
|
250
|
-
) : null}
|
|
251
|
-
<div className={css.input}>
|
|
252
|
-
<div className={css.inputEditorContainer}>
|
|
253
|
-
<div
|
|
254
|
-
ref={inputEditorRef}
|
|
255
|
-
className={css.inputEditor}
|
|
256
|
-
contentEditable={disabled ? false : true}
|
|
257
|
-
onKeyDown={onKeyDown}
|
|
258
|
-
onCompositionStart={onCompositionStart}
|
|
259
|
-
onCompositionEnd={onCompositionEnd}
|
|
260
|
-
onInput={onInput}
|
|
261
|
-
onPaste={onPaste}
|
|
262
|
-
onBlur={onBlur}
|
|
263
|
-
></div>
|
|
264
|
-
{!inputContent && <div className={css.inputPlaceholder}>
|
|
265
|
-
{placeholder}
|
|
266
|
-
</div>}
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
<div className={css.editorAction}>
|
|
270
|
-
<div className={classNames(css.leftArea, {
|
|
271
|
-
[css.disabled]: loading || disabled
|
|
272
|
-
})}>
|
|
273
|
-
<div className={css.attachmentButton} onClick={uploadAttachment}>
|
|
274
|
-
<Attachment />
|
|
275
|
-
</div>
|
|
276
|
-
{/* {attachments.length ? (
|
|
277
|
-
<AttachmentsList attachments={attachments} onDelete={onAttachmentsDelete}/>
|
|
278
|
-
) : null} */}
|
|
279
|
-
</div>
|
|
280
|
-
<div className={css.rightArea}>
|
|
281
|
-
<div className={classNames(css.sendButtonContainer, {
|
|
282
|
-
[css.disabled]: !inputContent || loading || disabled
|
|
283
|
-
})} onClick={send}>
|
|
284
|
-
<div className={classNames(css.sendButton, {
|
|
285
|
-
[css.loadingButton]: loading
|
|
286
|
-
})}>
|
|
287
|
-
{loading ? <Loading /> : <Send />}
|
|
288
|
-
</div>
|
|
289
|
-
</div>
|
|
290
|
-
</div>
|
|
291
|
-
</div>
|
|
292
|
-
</div>
|
|
293
|
-
</div>
|
|
294
|
-
)
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
export { Sender }
|
|
298
|
-
export type { SenderRef, SenderProps }
|
package/src/components/types.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
interface Mention {
|
|
2
|
-
/** 唯一ID */
|
|
3
|
-
id?: string;
|
|
4
|
-
/** 展示用 */
|
|
5
|
-
name?: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** 区域才会有 */
|
|
9
|
-
focusArea?: {
|
|
10
|
-
selector: string;
|
|
11
|
-
title: string;
|
|
12
|
-
}
|
|
13
|
-
comId: string;
|
|
14
|
-
pageId: string;
|
|
15
|
-
title: string;
|
|
16
|
-
/** 类型,组件、页面 */
|
|
17
|
-
type: "page" | "uiCom";
|
|
18
|
-
/** 是否为 vibeCoding 状态(代码编辑模式) */
|
|
19
|
-
vibeCoding?: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface Extension {
|
|
23
|
-
mentions: Mention[]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
type Attachments = {
|
|
27
|
-
type: "image";
|
|
28
|
-
content: string;
|
|
29
|
-
}[]
|
|
30
|
-
|
|
31
|
-
export type { Mention, Extension, Attachments }
|
package/src/constants/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Events } from "@mybricks/rxai"
|
|
2
|
-
|
|
3
|
-
interface RequestStatus {
|
|
4
|
-
state: "pending" | "fulfilled" | "rejected";
|
|
5
|
-
result: any;
|
|
6
|
-
}
|
|
7
|
-
class RequestStatusTracker {
|
|
8
|
-
private requests = new Map<string, RequestStatus>();
|
|
9
|
-
events = new Events<{promise: {
|
|
10
|
-
id: string;
|
|
11
|
-
status: RequestStatus
|
|
12
|
-
}}>();
|
|
13
|
-
constructor() {}
|
|
14
|
-
|
|
15
|
-
track(id: string, promise: Promise<any>) {
|
|
16
|
-
const status: RequestStatus = {
|
|
17
|
-
state: "pending",
|
|
18
|
-
result: null,
|
|
19
|
-
}
|
|
20
|
-
this.events.emit("promise", {
|
|
21
|
-
id,
|
|
22
|
-
status,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
promise.then((result) => {
|
|
26
|
-
status.state = "fulfilled";
|
|
27
|
-
status.result = result
|
|
28
|
-
}).catch((error) => {
|
|
29
|
-
status.state = "rejected";
|
|
30
|
-
status.result = error
|
|
31
|
-
console.error(error);
|
|
32
|
-
}).finally(() => {
|
|
33
|
-
this.events.emit("promise", {
|
|
34
|
-
id,
|
|
35
|
-
status,
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
this.requests.set(id, status);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getStatus(id: string) {
|
|
43
|
-
return this.requests.get(id) || {
|
|
44
|
-
state: "fulfilled",
|
|
45
|
-
result: null
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { RequestStatusTracker };
|
package/src/context/index.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Rxai, Events, IDB } from "@mybricks/rxai"
|
|
2
|
-
import { RequestStatusTracker } from "./RequestStatusTracker";
|
|
3
|
-
import { DeviceType } from './../types';
|
|
4
|
-
import type { AgentConfigParams } from '../agents/utils/config';
|
|
5
|
-
|
|
6
|
-
class Context {
|
|
7
|
-
|
|
8
|
-
/** UI展示名称 */
|
|
9
|
-
name!: string
|
|
10
|
-
|
|
11
|
-
rxai!: Rxai
|
|
12
|
-
globalRxai!: Rxai
|
|
13
|
-
currentFocus?: AiServiceFocusParams;
|
|
14
|
-
api!: AiServiceAPI;
|
|
15
|
-
aiViewAPI!: AiViewApi;
|
|
16
|
-
|
|
17
|
-
/** 设计器 API(带记录功能) */
|
|
18
|
-
designer?: {
|
|
19
|
-
createPage?: (id: string, title: string, config?: any) => Promise<{ id: string; onProgress: Function; }>;
|
|
20
|
-
createCanvas?: () => Promise<{ id: string; title: string; }>;
|
|
21
|
-
updatePage?: (...params: any[]) => Promise<void>;
|
|
22
|
-
updateUiCom?: (...params: any[]) => Promise<void>;
|
|
23
|
-
updateLogicCom?: (...params: any[]) => Promise<void>;
|
|
24
|
-
createDiagram?: (...params: any[]) => Promise<{ id: string; title: string }>;
|
|
25
|
-
updateDiagram?: (...params: any[]) => Promise<void>;
|
|
26
|
-
getDiagramInfo?: (...params: any[]) => any;
|
|
27
|
-
getDiagramInfoByVarId?: (...params: any[]) => any;
|
|
28
|
-
getDiagramInfoByListenerInfo?: (...params: any[]) => any;
|
|
29
|
-
getAllComDefPrompts: () => string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/** Agent 配置 */
|
|
33
|
-
agents: AgentConfigParams[] = [];
|
|
34
|
-
|
|
35
|
-
/** 是否多画布 */
|
|
36
|
-
isMutiCanvas: boolean = true
|
|
37
|
-
|
|
38
|
-
userConfig?: {
|
|
39
|
-
useCloudComponents: boolean;
|
|
40
|
-
enabledActionTags: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get useCloudComponents() {
|
|
44
|
-
return this.userConfig?.useCloudComponents ?? false;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get enabledActionTags() {
|
|
48
|
-
return this.userConfig?.enabledActionTags ?? true;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
deviceType: DeviceType = DeviceType.Mobile
|
|
52
|
-
|
|
53
|
-
/** 应用传入的创建页面模板 */
|
|
54
|
-
createTemplates?: {
|
|
55
|
-
page: any
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
events = new Events<{
|
|
59
|
-
aiViewDisplay: boolean;
|
|
60
|
-
focus: AiServiceFocusParams | undefined;
|
|
61
|
-
}>();
|
|
62
|
-
|
|
63
|
-
createRxai(options: ConstructorParameters<typeof Rxai>[0] & { key: number }) {
|
|
64
|
-
if (!this.rxai) {
|
|
65
|
-
this.rxai = new Rxai({
|
|
66
|
-
...options,
|
|
67
|
-
idb: options.key ? new IDB({
|
|
68
|
-
dbName: "@mybricks/plugin-ai/messages",
|
|
69
|
-
key: options.key
|
|
70
|
-
}) : undefined
|
|
71
|
-
})
|
|
72
|
-
this.globalRxai = new Rxai(options)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
requestStatusTracker = new RequestStatusTracker();
|
|
77
|
-
|
|
78
|
-
pluginParams: any = {};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const context = new Context();
|
|
82
|
-
|
|
83
|
-
export { context };
|
package/src/data.ts
DELETED
package/src/global.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
interface AiServiceAPI {
|
|
2
|
-
global: {
|
|
3
|
-
title: string;
|
|
4
|
-
api: {
|
|
5
|
-
getAllPageInfo: () => {pageAry: any[]}[];
|
|
6
|
-
getAllComDefPrompts: () => string;
|
|
7
|
-
getComEditorPrompts: (...params: any) => string;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
page: {
|
|
11
|
-
title: string;
|
|
12
|
-
params: stirng[];
|
|
13
|
-
api: {
|
|
14
|
-
updatePage: (...params: any) => void;
|
|
15
|
-
getPageDSLPrompts: (...params: any) => string;
|
|
16
|
-
getPageContainerPrompts: (...params: any) => string;
|
|
17
|
-
clearPageContent: (pageId: string) => void
|
|
18
|
-
getOutlineInfo: (...params: any) => any
|
|
19
|
-
createCanvas: () => { id: string; title: string; }
|
|
20
|
-
createPage: (id: string, title: string, config?: any) => { id: string; onProgress: Function; }
|
|
21
|
-
getPageOnProcess: (...params: any) => any;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
uiCom: {
|
|
25
|
-
title: string;
|
|
26
|
-
api: {
|
|
27
|
-
updateCom: (...params: any) => void;
|
|
28
|
-
getComPrompts: (...params: any) => string;
|
|
29
|
-
getComDSLPrompts: (...params: any) => string;
|
|
30
|
-
/** @deprecated 废弃 */
|
|
31
|
-
getComEditorPrompts: (...params: any) => string;
|
|
32
|
-
getOutlineInfo: (...params: any) => any
|
|
33
|
-
getComOnProcess: (...params: any) => any;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
diagram: {
|
|
37
|
-
title: string;
|
|
38
|
-
api: {
|
|
39
|
-
createDiagram: (...args: any) => { id: string; title: string }
|
|
40
|
-
updateDiagram: (...args: any) => void;
|
|
41
|
-
getDiagramInfo: (...args: any) => any;
|
|
42
|
-
getDiagramInfoByVarId: (...args: any) => any;
|
|
43
|
-
getDiagramInfoByListenerInfo: (...args: any) => any;
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
logicCom: {
|
|
47
|
-
title: string;
|
|
48
|
-
api: {
|
|
49
|
-
getOutlineInfo: (...params: any) => any;
|
|
50
|
-
updateCom: (...params: any) => any;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type AiServiceFocusParams = {
|
|
56
|
-
onProgress: (status: "start" | "ing" | "complete") => void;
|
|
57
|
-
/** 区域才会有 */
|
|
58
|
-
focusArea?: {
|
|
59
|
-
selector: string;
|
|
60
|
-
title: string;
|
|
61
|
-
}
|
|
62
|
-
comId: string;
|
|
63
|
-
pageId: string;
|
|
64
|
-
title: string;
|
|
65
|
-
/** 类型,组件、页面,或自定义类型 */
|
|
66
|
-
type: "page" | "uiCom" | "section" | "logicCom" | string;
|
|
67
|
-
vibeCoding?: boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
type AiServiceRequestParams = {
|
|
71
|
-
type: "uiCom";
|
|
72
|
-
message: string;
|
|
73
|
-
comId: string;
|
|
74
|
-
attachments: {
|
|
75
|
-
type: "image";
|
|
76
|
-
content: string;
|
|
77
|
-
title?: string;
|
|
78
|
-
size?: number;
|
|
79
|
-
}[];
|
|
80
|
-
onProgress: (status: string) => void;
|
|
81
|
-
} | {
|
|
82
|
-
type: "page";
|
|
83
|
-
message: string;
|
|
84
|
-
pageId: string;
|
|
85
|
-
attachments: {
|
|
86
|
-
type: "image";
|
|
87
|
-
content: string;
|
|
88
|
-
title?: string;
|
|
89
|
-
size?: number;
|
|
90
|
-
}[];
|
|
91
|
-
onProgress: (status: "start" | "ing" | "complete") => void;
|
|
92
|
-
}
|
|
93
|
-
interface AiViewApi {
|
|
94
|
-
focusPage: (pageId: string) => void;
|
|
95
|
-
focusCom: (comId: string) => void;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
interface AiStartViewApi {
|
|
99
|
-
onProgress: (state: "start" | "ing") => void;
|
|
100
|
-
}
|