@ant-design/agentic-ui 2.0.22 → 2.0.23
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/Components/GradientText/index.d.ts +2 -1
- package/dist/Components/GradientText/index.js +3 -2
- package/dist/Components/GradientText/style.js +3 -8
- package/dist/Components/TextAnimate/index.d.ts +1 -0
- package/dist/Components/TextAnimate/index.js +27 -16
- package/dist/Components/TypingAnimation/index.d.ts +1 -1
- package/dist/Components/TypingAnimation/index.js +9 -9
- package/dist/MarkdownEditor/editor/components/LazyElement/index.js +36 -4
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +4 -0
- package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +245 -344
- package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +74 -56
- package/dist/MarkdownEditor/editor/store.d.ts +36 -0
- package/dist/MarkdownEditor/editor/store.js +208 -76
- package/dist/Schema/SchemaRenderer/index.js +80 -55
- package/dist/Utils/proxySandbox/ProxySandbox.d.ts +32 -0
- package/dist/Utils/proxySandbox/ProxySandbox.js +176 -128
- package/dist/WelcomeMessage/index.d.ts +2 -2
- package/dist/WelcomeMessage/index.js +8 -5
- package/dist/WelcomeMessage/style.js +0 -1
- package/package.json +1 -1
|
@@ -117,6 +117,38 @@ export declare class ProxySandbox {
|
|
|
117
117
|
* 使用 Worker 执行代码以实现真正的超时控制
|
|
118
118
|
*/
|
|
119
119
|
private executeWithWorker;
|
|
120
|
+
/**
|
|
121
|
+
* 尝试序列化参数,失败则回退到同步执行
|
|
122
|
+
*/
|
|
123
|
+
private trySerializeParams;
|
|
124
|
+
/**
|
|
125
|
+
* 回退到同步执行
|
|
126
|
+
*/
|
|
127
|
+
private fallbackToSyncExecution;
|
|
128
|
+
/**
|
|
129
|
+
* 创建 Worker 实例
|
|
130
|
+
*/
|
|
131
|
+
private createWorkerInstance;
|
|
132
|
+
/**
|
|
133
|
+
* 生成 Worker 代码
|
|
134
|
+
*/
|
|
135
|
+
private generateWorkerCode;
|
|
136
|
+
/**
|
|
137
|
+
* 设置 Worker 超时
|
|
138
|
+
*/
|
|
139
|
+
private setupWorkerTimeout;
|
|
140
|
+
/**
|
|
141
|
+
* 设置 Worker 消息处理器
|
|
142
|
+
*/
|
|
143
|
+
private setupWorkerHandlers;
|
|
144
|
+
/**
|
|
145
|
+
* 处理控制台消息
|
|
146
|
+
*/
|
|
147
|
+
private handleConsoleMessage;
|
|
148
|
+
/**
|
|
149
|
+
* 清理 Worker 资源
|
|
150
|
+
*/
|
|
151
|
+
private cleanupWorker;
|
|
120
152
|
/**
|
|
121
153
|
* 执行代码的核心方法(同步版本)
|
|
122
154
|
*/
|
|
@@ -732,140 +732,188 @@ ${instrumented}`;
|
|
|
732
732
|
*/
|
|
733
733
|
executeWithWorker(code, injectedParams) {
|
|
734
734
|
return new Promise((resolve, reject) => {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
735
|
+
const serializableParams = this.trySerializeParams(
|
|
736
|
+
injectedParams,
|
|
737
|
+
code,
|
|
738
|
+
resolve,
|
|
739
|
+
reject
|
|
740
|
+
);
|
|
741
|
+
if (!serializableParams)
|
|
742
|
+
return;
|
|
743
|
+
const { worker, workerUrl, timeoutId } = this.createWorkerInstance(
|
|
744
|
+
code,
|
|
745
|
+
serializableParams,
|
|
746
|
+
resolve,
|
|
747
|
+
reject
|
|
748
|
+
);
|
|
749
|
+
if (!worker)
|
|
750
|
+
return;
|
|
751
|
+
this.setupWorkerHandlers(
|
|
752
|
+
worker,
|
|
753
|
+
workerUrl,
|
|
754
|
+
timeoutId,
|
|
755
|
+
resolve,
|
|
756
|
+
reject
|
|
757
|
+
);
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* 尝试序列化参数,失败则回退到同步执行
|
|
762
|
+
*/
|
|
763
|
+
trySerializeParams(injectedParams, code, resolve, reject) {
|
|
764
|
+
if (!injectedParams)
|
|
765
|
+
return {};
|
|
766
|
+
const serializableParams = {};
|
|
767
|
+
for (const [key, value] of Object.entries(injectedParams)) {
|
|
768
|
+
try {
|
|
769
|
+
JSON.stringify(value);
|
|
770
|
+
serializableParams[key] = value;
|
|
771
|
+
} catch (e) {
|
|
772
|
+
console.warn(`无法序列化注入参数 "${key}",回退到同步执行`);
|
|
773
|
+
this.fallbackToSyncExecution(code, injectedParams, resolve, reject);
|
|
774
|
+
return null;
|
|
758
775
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
776
|
+
}
|
|
777
|
+
return serializableParams;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* 回退到同步执行
|
|
781
|
+
*/
|
|
782
|
+
fallbackToSyncExecution(code, injectedParams, resolve, reject) {
|
|
783
|
+
try {
|
|
784
|
+
const result = this.executeCode(code, injectedParams);
|
|
785
|
+
resolve(result);
|
|
786
|
+
} catch (error) {
|
|
787
|
+
reject(error);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* 创建 Worker 实例
|
|
792
|
+
*/
|
|
793
|
+
createWorkerInstance(code, serializableParams, resolve, reject) {
|
|
794
|
+
const workerCode = this.generateWorkerCode();
|
|
795
|
+
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
796
|
+
const workerUrl = URL.createObjectURL(blob);
|
|
797
|
+
try {
|
|
798
|
+
const worker = new Worker(workerUrl);
|
|
799
|
+
const timeoutId = this.setupWorkerTimeout(worker, workerUrl, reject);
|
|
800
|
+
worker.postMessage({
|
|
801
|
+
code,
|
|
802
|
+
config: this.config,
|
|
803
|
+
injectedParams: serializableParams
|
|
804
|
+
});
|
|
805
|
+
return { worker, workerUrl, timeoutId };
|
|
806
|
+
} catch (error) {
|
|
807
|
+
URL.revokeObjectURL(workerUrl);
|
|
808
|
+
console.warn("Worker 创建失败,回退到同步执行");
|
|
809
|
+
this.fallbackToSyncExecution(code, serializableParams, resolve, reject);
|
|
810
|
+
return { worker: null, workerUrl, timeoutId: 0 };
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* 生成 Worker 代码
|
|
815
|
+
*/
|
|
816
|
+
generateWorkerCode() {
|
|
817
|
+
return `
|
|
818
|
+
self.onmessage = function(e) {
|
|
819
|
+
const { code, config, injectedParams } = e.data;
|
|
820
|
+
|
|
821
|
+
try {
|
|
822
|
+
// 创建安全的执行环境
|
|
823
|
+
const safeGlobals = {
|
|
824
|
+
Math, Date, JSON, parseInt, parseFloat, isNaN, isFinite,
|
|
825
|
+
encodeURIComponent, decodeURIComponent, encodeURI, decodeURI,
|
|
826
|
+
String, Number, Boolean, Array, Object, RegExp,
|
|
827
|
+
Error, TypeError, ReferenceError, SyntaxError
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// 添加自定义全局变量
|
|
831
|
+
Object.assign(safeGlobals, config.customGlobals || {});
|
|
832
|
+
|
|
833
|
+
// 添加注入的参数
|
|
834
|
+
Object.assign(safeGlobals, injectedParams || {});
|
|
762
835
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
836
|
+
// 添加 console(如果允许)
|
|
837
|
+
if (config.allowConsole) {
|
|
838
|
+
safeGlobals.console = {
|
|
839
|
+
log: (...args) => self.postMessage({ type: 'log', data: args }),
|
|
840
|
+
warn: (...args) => self.postMessage({ type: 'warn', data: args }),
|
|
841
|
+
error: (...args) => self.postMessage({ type: 'error', data: args }),
|
|
842
|
+
info: (...args) => self.postMessage({ type: 'info', data: args }),
|
|
843
|
+
debug: (...args) => self.postMessage({ type: 'debug', data: args })
|
|
770
844
|
};
|
|
771
|
-
|
|
772
|
-
// 添加自定义全局变量
|
|
773
|
-
Object.assign(safeGlobals, config.customGlobals || {});
|
|
774
|
-
|
|
775
|
-
// 添加注入的参数
|
|
776
|
-
Object.assign(safeGlobals, injectedParams || {});
|
|
777
|
-
|
|
778
|
-
// 添加 console(如果允许)
|
|
779
|
-
if (config.allowConsole) {
|
|
780
|
-
safeGlobals.console = {
|
|
781
|
-
log: (...args) => self.postMessage({ type: 'log', data: args }),
|
|
782
|
-
warn: (...args) => self.postMessage({ type: 'warn', data: args }),
|
|
783
|
-
error: (...args) => self.postMessage({ type: 'error', data: args }),
|
|
784
|
-
info: (...args) => self.postMessage({ type: 'info', data: args }),
|
|
785
|
-
debug: (...args) => self.postMessage({ type: 'debug', data: args })
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
// 创建执行函数
|
|
790
|
-
const wrappedCode = config.strictMode ? "'use strict';\\n" + code : code;
|
|
791
|
-
const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');
|
|
792
|
-
|
|
793
|
-
// 执行代码
|
|
794
|
-
const result = func(...Object.values(safeGlobals));
|
|
795
|
-
|
|
796
|
-
self.postMessage({ type: 'result', data: result });
|
|
797
|
-
} catch (error) {
|
|
798
|
-
self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
`;
|
|
802
|
-
const blob = new Blob([workerCode], { type: "application/javascript" });
|
|
803
|
-
const workerUrl = URL.createObjectURL(blob);
|
|
804
|
-
let worker;
|
|
805
|
-
let timeoutId;
|
|
806
|
-
try {
|
|
807
|
-
worker = new Worker(workerUrl);
|
|
808
|
-
timeoutId = window.setTimeout(() => {
|
|
809
|
-
if (worker) {
|
|
810
|
-
worker.terminate();
|
|
811
845
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
);
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
worker.terminate();
|
|
824
|
-
URL.revokeObjectURL(workerUrl);
|
|
825
|
-
resolve(data);
|
|
826
|
-
} else if (type === "error") {
|
|
827
|
-
if (timeoutId)
|
|
828
|
-
clearTimeout(timeoutId);
|
|
829
|
-
if (worker)
|
|
830
|
-
worker.terminate();
|
|
831
|
-
URL.revokeObjectURL(workerUrl);
|
|
832
|
-
reject(new Error(data.message));
|
|
833
|
-
} else if (type === "log" || type === "warn" || type === "error" || type === "info" || type === "debug") {
|
|
834
|
-
if (this.config.allowConsole) {
|
|
835
|
-
const consoleMethod = console[type];
|
|
836
|
-
if (typeof consoleMethod === "function") {
|
|
837
|
-
consoleMethod("[Sandbox]", ...data);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
worker.onerror = (error) => {
|
|
843
|
-
if (timeoutId)
|
|
844
|
-
clearTimeout(timeoutId);
|
|
845
|
-
if (worker)
|
|
846
|
-
worker.terminate();
|
|
847
|
-
URL.revokeObjectURL(workerUrl);
|
|
848
|
-
reject(new Error(`Worker error: ${error.message}`));
|
|
849
|
-
};
|
|
850
|
-
worker.postMessage({
|
|
851
|
-
code,
|
|
852
|
-
config: this.config,
|
|
853
|
-
injectedParams: serializableParams
|
|
854
|
-
});
|
|
855
|
-
} catch (error) {
|
|
856
|
-
if (timeoutId)
|
|
857
|
-
clearTimeout(timeoutId);
|
|
858
|
-
if (worker)
|
|
859
|
-
worker.terminate();
|
|
860
|
-
URL.revokeObjectURL(workerUrl);
|
|
861
|
-
try {
|
|
862
|
-
const result = this.executeCode(code, injectedParams);
|
|
863
|
-
resolve(result);
|
|
864
|
-
} catch (syncError) {
|
|
865
|
-
reject(syncError);
|
|
846
|
+
|
|
847
|
+
// 创建执行函数
|
|
848
|
+
const wrappedCode = config.strictMode ? "'use strict';\\n" + code : code;
|
|
849
|
+
const func = new Function(...Object.keys(safeGlobals), 'return (function() { ' + wrappedCode + ' })()');
|
|
850
|
+
|
|
851
|
+
// 执行代码
|
|
852
|
+
const result = func(...Object.values(safeGlobals));
|
|
853
|
+
|
|
854
|
+
self.postMessage({ type: 'result', data: result });
|
|
855
|
+
} catch (error) {
|
|
856
|
+
self.postMessage({ type: 'error', data: { message: error.message, stack: error.stack } });
|
|
866
857
|
}
|
|
858
|
+
};
|
|
859
|
+
`;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* 设置 Worker 超时
|
|
863
|
+
*/
|
|
864
|
+
setupWorkerTimeout(worker, workerUrl, reject) {
|
|
865
|
+
return window.setTimeout(() => {
|
|
866
|
+
worker.terminate();
|
|
867
|
+
URL.revokeObjectURL(workerUrl);
|
|
868
|
+
reject(
|
|
869
|
+
new Error(`Code execution timeout after ${this.config.timeout}ms`)
|
|
870
|
+
);
|
|
871
|
+
}, this.config.timeout);
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* 设置 Worker 消息处理器
|
|
875
|
+
*/
|
|
876
|
+
setupWorkerHandlers(worker, workerUrl, timeoutId, resolve, reject) {
|
|
877
|
+
worker.onmessage = (e) => {
|
|
878
|
+
const { type, data } = e.data;
|
|
879
|
+
if (type === "result") {
|
|
880
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
881
|
+
resolve(data);
|
|
882
|
+
return;
|
|
867
883
|
}
|
|
868
|
-
|
|
884
|
+
if (type === "error") {
|
|
885
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
886
|
+
reject(new Error(data.message));
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
this.handleConsoleMessage(type, data);
|
|
890
|
+
};
|
|
891
|
+
worker.onerror = (error) => {
|
|
892
|
+
this.cleanupWorker(worker, workerUrl, timeoutId);
|
|
893
|
+
reject(new Error(`Worker error: ${error.message}`));
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* 处理控制台消息
|
|
898
|
+
*/
|
|
899
|
+
handleConsoleMessage(type, data) {
|
|
900
|
+
if (!this.config.allowConsole)
|
|
901
|
+
return;
|
|
902
|
+
const consoleTypes = ["log", "warn", "error", "info", "debug"];
|
|
903
|
+
if (!consoleTypes.includes(type))
|
|
904
|
+
return;
|
|
905
|
+
const consoleMethod = console[type];
|
|
906
|
+
if (typeof consoleMethod === "function") {
|
|
907
|
+
consoleMethod("[Sandbox]", ...data);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
/**
|
|
911
|
+
* 清理 Worker 资源
|
|
912
|
+
*/
|
|
913
|
+
cleanupWorker(worker, workerUrl, timeoutId) {
|
|
914
|
+
clearTimeout(timeoutId);
|
|
915
|
+
worker.terminate();
|
|
916
|
+
URL.revokeObjectURL(workerUrl);
|
|
869
917
|
}
|
|
870
918
|
/**
|
|
871
919
|
* 执行代码的核心方法(同步版本)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TextAnimateProps } from '../Components/TextAnimate';
|
|
3
3
|
import { TypingAnimationProps } from '../Components/TypingAnimation';
|
|
4
|
-
export type WelcomeMessageTitleAnimateProps = Pick<
|
|
5
|
-
export type WelcomeMessageDescriptionAnimateProps = Pick<
|
|
4
|
+
export type WelcomeMessageTitleAnimateProps = Pick<TypingAnimationProps, 'duration' | 'typeSpeed' | 'deleteSpeed' | 'delay' | 'pauseDelay' | 'loop' | 'startOnView' | 'showCursor' | 'blinkCursor' | 'cursorStyle'>;
|
|
5
|
+
export type WelcomeMessageDescriptionAnimateProps = Pick<TextAnimateProps, 'delay' | 'duration' | 'variants' | 'by' | 'startOnView' | 'once' | 'animation'>;
|
|
6
6
|
/**
|
|
7
7
|
* WelcomeMessage 组件的属性接口
|
|
8
8
|
* @interface WelcomeMessageProps
|
|
@@ -41,18 +41,21 @@ var WelcomeMessage = ({
|
|
|
41
41
|
const { wrapSSR, hashId } = useStyle(prefixCls);
|
|
42
42
|
return wrapSSR(
|
|
43
43
|
/* @__PURE__ */ React.createElement("div", { className: classnames(prefixCls, hashId, rootClassName), style }, title && /* @__PURE__ */ React.createElement(
|
|
44
|
-
|
|
44
|
+
TypingAnimation,
|
|
45
45
|
__spreadProps(__spreadValues({
|
|
46
|
-
|
|
46
|
+
as: "div"
|
|
47
47
|
}, titleAnimateProps), {
|
|
48
|
-
as: "div",
|
|
49
48
|
className: classnames(`${prefixCls}-title`, classNames == null ? void 0 : classNames.title)
|
|
50
49
|
}),
|
|
51
50
|
title
|
|
52
51
|
), description && /* @__PURE__ */ React.createElement(
|
|
53
|
-
|
|
54
|
-
__spreadProps(__spreadValues({
|
|
52
|
+
TextAnimate,
|
|
53
|
+
__spreadProps(__spreadValues({
|
|
55
54
|
as: "div",
|
|
55
|
+
animation: "blurInUp",
|
|
56
|
+
by: "character",
|
|
57
|
+
once: true
|
|
58
|
+
}, descriptionAnimateProps), {
|
|
56
59
|
className: classnames(
|
|
57
60
|
`${prefixCls}-description`,
|
|
58
61
|
classNames == null ? void 0 : classNames.description
|