@sqaitech/visualizer 0.30.10

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.
Files changed (148) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/es/component/blackboard/index.css +33 -0
  4. package/dist/es/component/blackboard/index.mjs +278 -0
  5. package/dist/es/component/config-selector/index.mjs +104 -0
  6. package/dist/es/component/context-preview/index.mjs +38 -0
  7. package/dist/es/component/env-config/index.mjs +112 -0
  8. package/dist/es/component/env-config-reminder/index.css +22 -0
  9. package/dist/es/component/env-config-reminder/index.mjs +28 -0
  10. package/dist/es/component/form-field/index.mjs +163 -0
  11. package/dist/es/component/history-selector/index.css +135 -0
  12. package/dist/es/component/history-selector/index.mjs +170 -0
  13. package/dist/es/component/index.mjs +1 -0
  14. package/dist/es/component/logo/index.css +13 -0
  15. package/dist/es/component/logo/index.mjs +20 -0
  16. package/dist/es/component/misc/index.mjs +94 -0
  17. package/dist/es/component/nav-actions/index.mjs +32 -0
  18. package/dist/es/component/nav-actions/style.css +35 -0
  19. package/dist/es/component/player/index.css +185 -0
  20. package/dist/es/component/player/index.mjs +856 -0
  21. package/dist/es/component/playground/index.css +431 -0
  22. package/dist/es/component/playground/index.mjs +8 -0
  23. package/dist/es/component/playground/playground-demo-ui-context.json +290 -0
  24. package/dist/es/component/playground-result/index.css +34 -0
  25. package/dist/es/component/playground-result/index.mjs +62 -0
  26. package/dist/es/component/prompt-input/index.css +391 -0
  27. package/dist/es/component/prompt-input/index.mjs +730 -0
  28. package/dist/es/component/service-mode-control/index.mjs +105 -0
  29. package/dist/es/component/shiny-text/index.css +75 -0
  30. package/dist/es/component/shiny-text/index.mjs +15 -0
  31. package/dist/es/component/universal-playground/index.css +341 -0
  32. package/dist/es/component/universal-playground/index.mjs +302 -0
  33. package/dist/es/component/universal-playground/providers/context-provider.mjs +52 -0
  34. package/dist/es/component/universal-playground/providers/indexeddb-storage-provider.mjs +207 -0
  35. package/dist/es/component/universal-playground/providers/storage-provider.mjs +210 -0
  36. package/dist/es/hooks/usePlaygroundExecution.mjs +180 -0
  37. package/dist/es/hooks/usePlaygroundState.mjs +203 -0
  38. package/dist/es/hooks/useSafeOverrideAIConfig.mjs +24 -0
  39. package/dist/es/hooks/useServerValid.mjs +30 -0
  40. package/dist/es/icons/avatar.mjs +28 -0
  41. package/dist/es/icons/close.mjs +19 -0
  42. package/dist/es/icons/global-perspective.mjs +16 -0
  43. package/dist/es/icons/history.mjs +30 -0
  44. package/dist/es/icons/magnifying-glass.mjs +39 -0
  45. package/dist/es/icons/player-setting.mjs +26 -0
  46. package/dist/es/icons/setting.mjs +20 -0
  47. package/dist/es/icons/show-marker.mjs +16 -0
  48. package/dist/es/index.mjs +25 -0
  49. package/dist/es/store/history.mjs +89 -0
  50. package/dist/es/store/store.mjs +186 -0
  51. package/dist/es/types.mjs +70 -0
  52. package/dist/es/utils/color.mjs +35 -0
  53. package/dist/es/utils/constants.mjs +99 -0
  54. package/dist/es/utils/index.mjs +10 -0
  55. package/dist/es/utils/pixi-loader.mjs +16 -0
  56. package/dist/es/utils/playground-utils.mjs +67 -0
  57. package/dist/es/utils/replay-scripts.mjs +312 -0
  58. package/dist/lib/component/blackboard/index.css +33 -0
  59. package/dist/lib/component/blackboard/index.js +321 -0
  60. package/dist/lib/component/config-selector/index.js +148 -0
  61. package/dist/lib/component/context-preview/index.js +83 -0
  62. package/dist/lib/component/env-config/index.js +146 -0
  63. package/dist/lib/component/env-config-reminder/index.css +22 -0
  64. package/dist/lib/component/env-config-reminder/index.js +62 -0
  65. package/dist/lib/component/form-field/index.js +209 -0
  66. package/dist/lib/component/history-selector/index.css +135 -0
  67. package/dist/lib/component/history-selector/index.js +216 -0
  68. package/dist/lib/component/index.js +60 -0
  69. package/dist/lib/component/logo/index.css +13 -0
  70. package/dist/lib/component/logo/index.js +57 -0
  71. package/dist/lib/component/misc/index.js +150 -0
  72. package/dist/lib/component/nav-actions/index.js +66 -0
  73. package/dist/lib/component/nav-actions/style.css +35 -0
  74. package/dist/lib/component/player/index.css +185 -0
  75. package/dist/lib/component/player/index.js +902 -0
  76. package/dist/lib/component/playground/index.css +431 -0
  77. package/dist/lib/component/playground/index.js +113 -0
  78. package/dist/lib/component/playground/playground-demo-ui-context.json +290 -0
  79. package/dist/lib/component/playground-result/index.css +34 -0
  80. package/dist/lib/component/playground-result/index.js +106 -0
  81. package/dist/lib/component/prompt-input/index.css +391 -0
  82. package/dist/lib/component/prompt-input/index.js +774 -0
  83. package/dist/lib/component/service-mode-control/index.js +139 -0
  84. package/dist/lib/component/shiny-text/index.css +75 -0
  85. package/dist/lib/component/shiny-text/index.js +49 -0
  86. package/dist/lib/component/universal-playground/index.css +341 -0
  87. package/dist/lib/component/universal-playground/index.js +350 -0
  88. package/dist/lib/component/universal-playground/providers/context-provider.js +95 -0
  89. package/dist/lib/component/universal-playground/providers/indexeddb-storage-provider.js +247 -0
  90. package/dist/lib/component/universal-playground/providers/storage-provider.js +268 -0
  91. package/dist/lib/hooks/usePlaygroundExecution.js +214 -0
  92. package/dist/lib/hooks/usePlaygroundState.js +237 -0
  93. package/dist/lib/hooks/useSafeOverrideAIConfig.js +61 -0
  94. package/dist/lib/hooks/useServerValid.js +64 -0
  95. package/dist/lib/icons/avatar.js +62 -0
  96. package/dist/lib/icons/close.js +53 -0
  97. package/dist/lib/icons/global-perspective.js +50 -0
  98. package/dist/lib/icons/history.js +64 -0
  99. package/dist/lib/icons/magnifying-glass.js +73 -0
  100. package/dist/lib/icons/player-setting.js +60 -0
  101. package/dist/lib/icons/setting.js +54 -0
  102. package/dist/lib/icons/show-marker.js +50 -0
  103. package/dist/lib/index.js +187 -0
  104. package/dist/lib/store/history.js +96 -0
  105. package/dist/lib/store/store.js +196 -0
  106. package/dist/lib/types.js +116 -0
  107. package/dist/lib/utils/color.js +75 -0
  108. package/dist/lib/utils/constants.js +154 -0
  109. package/dist/lib/utils/index.js +63 -0
  110. package/dist/lib/utils/pixi-loader.js +56 -0
  111. package/dist/lib/utils/playground-utils.js +110 -0
  112. package/dist/lib/utils/replay-scripts.js +355 -0
  113. package/dist/types/component/blackboard/index.d.ts +15 -0
  114. package/dist/types/component/config-selector/index.d.ts +9 -0
  115. package/dist/types/component/context-preview/index.d.ts +9 -0
  116. package/dist/types/component/env-config/index.d.ts +6 -0
  117. package/dist/types/component/env-config-reminder/index.d.ts +6 -0
  118. package/dist/types/component/form-field/index.d.ts +17 -0
  119. package/dist/types/component/history-selector/index.d.ts +10 -0
  120. package/dist/types/component/index.d.ts +1 -0
  121. package/dist/types/component/logo/index.d.ts +5 -0
  122. package/dist/types/component/misc/index.d.ts +6 -0
  123. package/dist/types/component/nav-actions/index.d.ts +10 -0
  124. package/dist/types/component/player/index.d.ts +13 -0
  125. package/dist/types/component/playground/index.d.ts +7 -0
  126. package/dist/types/component/playground-result/index.d.ts +20 -0
  127. package/dist/types/component/prompt-input/index.d.ts +22 -0
  128. package/dist/types/component/service-mode-control/index.d.ts +6 -0
  129. package/dist/types/component/shiny-text/index.d.ts +12 -0
  130. package/dist/types/component/universal-playground/index.d.ts +4 -0
  131. package/dist/types/component/universal-playground/providers/context-provider.d.ts +37 -0
  132. package/dist/types/component/universal-playground/providers/indexeddb-storage-provider.d.ts +71 -0
  133. package/dist/types/component/universal-playground/providers/storage-provider.d.ts +58 -0
  134. package/dist/types/hooks/usePlaygroundExecution.d.ts +10 -0
  135. package/dist/types/hooks/usePlaygroundState.d.ts +26 -0
  136. package/dist/types/hooks/useSafeOverrideAIConfig.d.ts +16 -0
  137. package/dist/types/hooks/useServerValid.d.ts +1 -0
  138. package/dist/types/index.d.ts +27 -0
  139. package/dist/types/store/history.d.ts +16 -0
  140. package/dist/types/store/store.d.ts +36 -0
  141. package/dist/types/types.d.ts +161 -0
  142. package/dist/types/utils/color.d.ts +4 -0
  143. package/dist/types/utils/constants.d.ts +74 -0
  144. package/dist/types/utils/index.d.ts +4 -0
  145. package/dist/types/utils/pixi-loader.d.ts +5 -0
  146. package/dist/types/utils/playground-utils.d.ts +6 -0
  147. package/dist/types/utils/replay-scripts.d.ts +34 -0
  148. package/package.json +85 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Documentation
2
+
3
+ An AI-powered automation SDK can control the page, perform assertions, and extract data in JSON format using natural language.
4
+
5
+ See https://SQAIjs.com/ for details.
6
+
7
+ ## License
8
+
9
+ SQAI is MIT licensed.
@@ -0,0 +1,33 @@
1
+ .blackboard .footer {
2
+ color: #aaa;
3
+ }
4
+
5
+ .blackboard ul {
6
+ padding-left: 0;
7
+ }
8
+
9
+ .blackboard li {
10
+ list-style: none;
11
+ }
12
+
13
+ .blackboard .bottom-tip {
14
+ height: 30px;
15
+ }
16
+
17
+ .blackboard .bottom-tip-item {
18
+ color: #aaa;
19
+ text-overflow: ellipsis;
20
+ word-wrap: break-word;
21
+ max-width: 500px;
22
+ }
23
+
24
+ .blackboard-filter {
25
+ margin: 10px 0;
26
+ }
27
+
28
+ .blackboard-main-content canvas {
29
+ box-sizing: border-box;
30
+ border: 1px solid #888;
31
+ width: 100%;
32
+ }
33
+
@@ -0,0 +1,278 @@
1
+ 'use client';
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import "pixi.js/unsafe-eval";
4
+ import { Checkbox } from "antd";
5
+ import { Application, Container, Graphics, Rectangle, Sprite, Text, Texture } from "pixi.js";
6
+ import { useEffect, useMemo, useRef, useState } from "react";
7
+ import { colorForName, highlightColorForType } from "../../utils/color.mjs";
8
+ import "./index.css";
9
+ import { treeToList } from "@sqaitech/shared/extractor";
10
+ import { DropShadowFilter } from "pixi-filters";
11
+ import { useBlackboardPreference } from "../../store/store.mjs";
12
+ const itemFillAlpha = 0.4;
13
+ const highlightAlpha = 0.4;
14
+ const pointRadius = 10;
15
+ const pointMarkForItem = (point, type)=>{
16
+ const [x, y] = point;
17
+ const themeColor = highlightColorForType('element');
18
+ const graphics = new Graphics();
19
+ graphics.beginFill(themeColor, itemFillAlpha);
20
+ graphics.drawCircle(x, y, pointRadius);
21
+ graphics.endFill();
22
+ return graphics;
23
+ };
24
+ const rectMarkForItem = (rect, name, type)=>{
25
+ const { left, top, width, height } = rect;
26
+ let themeColor;
27
+ themeColor = 'element' === type ? colorForName(name) : 'searchArea' === type ? highlightColorForType('searchArea') : highlightColorForType('element');
28
+ const alpha = 'highlight' === type ? highlightAlpha : itemFillAlpha;
29
+ const graphics = new Graphics();
30
+ graphics.beginFill(themeColor, alpha);
31
+ graphics.lineStyle(1, themeColor, 1);
32
+ graphics.drawRect(left, top, width, height);
33
+ graphics.endFill();
34
+ const dropShadowFilter = new DropShadowFilter({
35
+ blur: 2,
36
+ quality: 3,
37
+ alpha: 0.4,
38
+ offset: {
39
+ x: 4,
40
+ y: 4
41
+ },
42
+ color: 0x333333
43
+ });
44
+ graphics.filters = [
45
+ dropShadowFilter
46
+ ];
47
+ const nameFontSize = 18;
48
+ if (!name) return [
49
+ graphics
50
+ ];
51
+ const texts = new Text(name, {
52
+ fontSize: nameFontSize,
53
+ fill: 0x0
54
+ });
55
+ texts.x = left;
56
+ texts.y = Math.max(top - (nameFontSize + 4), 0);
57
+ return [
58
+ graphics,
59
+ texts
60
+ ];
61
+ };
62
+ const Blackboard = (props)=>{
63
+ const highlightElements = props.highlightElements || [];
64
+ const highlightIds = highlightElements.map((e)=>e.id);
65
+ const highlightRect = props.highlightRect;
66
+ const highlightPoints = props.highlightPoints;
67
+ const context = props.uiContext;
68
+ const { size, screenshotBase64 } = context;
69
+ const screenWidth = size.width;
70
+ const screenHeight = size.height;
71
+ const domRef = useRef(null);
72
+ const app = useMemo(()=>new Application(), []);
73
+ const [appInitialed, setAppInitialed] = useState(false);
74
+ const highlightContainer = useMemo(()=>new Container(), []);
75
+ const elementMarkContainer = useMemo(()=>new Container(), []);
76
+ const [hoverElement, setHoverElement] = useState(null);
77
+ const pixiBgRef = useRef(void 0);
78
+ const { backgroundVisible, setBackgroundVisible, elementsVisible, setElementsVisible } = useBlackboardPreference();
79
+ useEffect(()=>{
80
+ Promise.resolve((async ()=>{
81
+ if (!domRef.current || !screenWidth) return;
82
+ await app.init({
83
+ width: screenWidth,
84
+ height: screenHeight,
85
+ background: 0xffffff
86
+ });
87
+ const canvasEl = domRef.current;
88
+ domRef.current.appendChild(app.canvas);
89
+ const { clientWidth } = domRef.current.parentElement;
90
+ const targetHeight = 0.6 * window.innerHeight;
91
+ const viewportRatio = clientWidth / targetHeight;
92
+ if (screenWidth / screenHeight <= viewportRatio) {
93
+ const ratio = targetHeight / screenHeight;
94
+ canvasEl.style.width = `${Math.floor(screenWidth * ratio)}px`;
95
+ canvasEl.style.height = `${Math.floor(screenHeight * ratio)}px`;
96
+ }
97
+ app.stage.addChild(highlightContainer);
98
+ app.stage.addChild(elementMarkContainer);
99
+ setAppInitialed(true);
100
+ })());
101
+ return ()=>{
102
+ console.log('will destroy');
103
+ try {
104
+ app.destroy(true, {
105
+ children: true,
106
+ texture: true
107
+ });
108
+ } catch (e) {
109
+ console.warn('destroy failed', e);
110
+ }
111
+ };
112
+ }, [
113
+ app,
114
+ screenWidth,
115
+ screenHeight
116
+ ]);
117
+ useEffect(()=>{
118
+ if (!appInitialed) return;
119
+ app.stage.eventMode = 'static';
120
+ app.stage.hitArea = new Rectangle(0, 0, screenWidth, screenHeight);
121
+ const clickHandler = (event)=>{
122
+ var _props_onCanvasClick;
123
+ console.log('pixi click', event);
124
+ const { x, y } = event.data.global;
125
+ null == (_props_onCanvasClick = props.onCanvasClick) || _props_onCanvasClick.call(props, [
126
+ Math.round(x),
127
+ Math.round(y)
128
+ ]);
129
+ };
130
+ app.stage.on('click', clickHandler);
131
+ return ()=>{
132
+ var _app_stage;
133
+ null == app || null == (_app_stage = app.stage) || _app_stage.off('click');
134
+ };
135
+ }, [
136
+ appInitialed,
137
+ props.onCanvasClick,
138
+ screenWidth,
139
+ screenHeight
140
+ ]);
141
+ useEffect(()=>{
142
+ if (!appInitialed) return;
143
+ const img = new Image();
144
+ img.onload = ()=>{
145
+ if (!app.stage) return;
146
+ const screenshotTexture = Texture.from(img);
147
+ const backgroundSprite = new Sprite(screenshotTexture);
148
+ backgroundSprite.x = 0;
149
+ backgroundSprite.y = 0;
150
+ backgroundSprite.width = screenWidth;
151
+ backgroundSprite.height = screenHeight;
152
+ backgroundSprite.eventMode = 'passive';
153
+ app.stage.addChildAt(backgroundSprite, 0);
154
+ pixiBgRef.current = backgroundSprite;
155
+ backgroundSprite.visible = backgroundVisible;
156
+ };
157
+ img.onerror = (e)=>{
158
+ console.error('load screenshot failed', e);
159
+ };
160
+ img.src = screenshotBase64;
161
+ }, [
162
+ app.stage,
163
+ appInitialed,
164
+ screenWidth,
165
+ screenHeight
166
+ ]);
167
+ const { highlightElementRects } = useMemo(()=>{
168
+ const highlightElementRects = [];
169
+ highlightContainer.removeChildren();
170
+ elementMarkContainer.removeChildren();
171
+ highlightContainer.eventMode = 'passive';
172
+ elementMarkContainer.eventMode = 'passive';
173
+ if (highlightRect) {
174
+ const [graphics] = rectMarkForItem(highlightRect, 'Search Area', 'searchArea');
175
+ highlightContainer.addChild(graphics);
176
+ }
177
+ if (highlightElements.length) highlightElements.forEach((element)=>{
178
+ const { rect, content, id } = element;
179
+ const [graphics] = rectMarkForItem(rect, content, 'highlight');
180
+ highlightContainer.addChild(graphics);
181
+ });
182
+ if (null == highlightPoints ? void 0 : highlightPoints.length) highlightPoints.forEach((point)=>{
183
+ const graphics = pointMarkForItem(point, 'highlightPoint');
184
+ highlightContainer.addChild(graphics);
185
+ });
186
+ const elements = treeToList(context.tree);
187
+ elements.forEach((element)=>{
188
+ const { rect, content, id } = element;
189
+ const ifHighlight = highlightIds.includes(id) || (null == hoverElement ? void 0 : hoverElement.id) === id;
190
+ if (ifHighlight) return;
191
+ const [graphics] = rectMarkForItem(rect, content, 'element');
192
+ elementMarkContainer.addChild(graphics);
193
+ });
194
+ elementMarkContainer.visible = elementsVisible;
195
+ return {
196
+ highlightElementRects
197
+ };
198
+ }, [
199
+ app,
200
+ appInitialed,
201
+ highlightElements,
202
+ context.tree,
203
+ hoverElement,
204
+ highlightRect,
205
+ highlightPoints
206
+ ]);
207
+ const onSetBackgroundVisible = (e)=>{
208
+ setBackgroundVisible(e.target.checked);
209
+ if (pixiBgRef.current) pixiBgRef.current.visible = e.target.checked;
210
+ };
211
+ const onSetElementsVisible = (e)=>{
212
+ setElementsVisible(e.target.checked);
213
+ elementMarkContainer.visible = e.target.checked;
214
+ };
215
+ let bottomTipA = null;
216
+ if (1 === highlightElementRects.length) bottomTipA = /*#__PURE__*/ jsx("div", {
217
+ className: "bottom-tip",
218
+ children: /*#__PURE__*/ jsxs("div", {
219
+ className: "bottom-tip-item",
220
+ children: [
221
+ "Element: ",
222
+ JSON.stringify(highlightElementRects[0])
223
+ ]
224
+ })
225
+ });
226
+ else if (highlightElementRects.length > 1) bottomTipA = /*#__PURE__*/ jsx("div", {
227
+ className: "bottom-tip",
228
+ children: /*#__PURE__*/ jsxs("div", {
229
+ className: "bottom-tip-item",
230
+ children: [
231
+ "Element: ",
232
+ JSON.stringify(highlightElementRects)
233
+ ]
234
+ })
235
+ });
236
+ return /*#__PURE__*/ jsxs("div", {
237
+ className: "blackboard",
238
+ children: [
239
+ /*#__PURE__*/ jsx("div", {
240
+ className: "blackboard-main-content",
241
+ style: {
242
+ width: '100%'
243
+ },
244
+ ref: domRef
245
+ }),
246
+ /*#__PURE__*/ jsx("div", {
247
+ className: "blackboard-filter",
248
+ style: {
249
+ display: props.hideController ? 'none' : 'block'
250
+ },
251
+ children: /*#__PURE__*/ jsxs("div", {
252
+ className: "overlay-control",
253
+ children: [
254
+ /*#__PURE__*/ jsx(Checkbox, {
255
+ checked: backgroundVisible,
256
+ onChange: onSetBackgroundVisible,
257
+ children: "Background"
258
+ }),
259
+ /*#__PURE__*/ jsx(Checkbox, {
260
+ checked: elementsVisible,
261
+ onChange: onSetElementsVisible,
262
+ children: "Elements"
263
+ })
264
+ ]
265
+ })
266
+ }),
267
+ /*#__PURE__*/ jsx("div", {
268
+ className: "bottom-tip",
269
+ style: {
270
+ display: props.hideController ? 'none' : 'block'
271
+ },
272
+ children: bottomTipA
273
+ })
274
+ ]
275
+ });
276
+ };
277
+ const blackboard = Blackboard;
278
+ export { Blackboard, blackboard as default, pointMarkForItem, rectMarkForItem };
@@ -0,0 +1,104 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Checkbox, Dropdown, Radio } from "antd";
3
+ import setting from "../../icons/setting.mjs";
4
+ import { useEnvConfig } from "../../store/store.mjs";
5
+ import { deepThinkTip, domIncludedTip, screenshotIncludedTip, trackingTip } from "../../utils/constants.mjs";
6
+ const ConfigSelector = (param)=>{
7
+ let { showDeepThinkOption = false, enableTracking = false, showDataExtractionOptions = false, hideDomAndScreenshotOptions = false } = param;
8
+ const forceSameTabNavigation = useEnvConfig((state)=>state.forceSameTabNavigation);
9
+ const setForceSameTabNavigation = useEnvConfig((state)=>state.setForceSameTabNavigation);
10
+ const deepThink = useEnvConfig((state)=>state.deepThink);
11
+ const setDeepThink = useEnvConfig((state)=>state.setDeepThink);
12
+ const screenshotIncluded = useEnvConfig((state)=>state.screenshotIncluded);
13
+ const setScreenshotIncluded = useEnvConfig((state)=>state.setScreenshotIncluded);
14
+ const domIncluded = useEnvConfig((state)=>state.domIncluded);
15
+ const setDomIncluded = useEnvConfig((state)=>state.setDomIncluded);
16
+ if (!enableTracking && !showDeepThinkOption && !showDataExtractionOptions) return null;
17
+ const configItems = buildConfigItems();
18
+ return /*#__PURE__*/ jsx("div", {
19
+ className: "selector-trigger",
20
+ children: /*#__PURE__*/ jsx(Dropdown, {
21
+ menu: {
22
+ items: configItems
23
+ },
24
+ trigger: [
25
+ 'click'
26
+ ],
27
+ children: /*#__PURE__*/ jsx(setting, {
28
+ width: 24,
29
+ height: 24
30
+ })
31
+ })
32
+ });
33
+ function buildConfigItems() {
34
+ const items = [];
35
+ if (enableTracking) items.push({
36
+ label: /*#__PURE__*/ jsx(Checkbox, {
37
+ onChange: (e)=>setForceSameTabNavigation(e.target.checked),
38
+ checked: forceSameTabNavigation,
39
+ children: trackingTip
40
+ }),
41
+ key: 'track-config'
42
+ });
43
+ if (showDeepThinkOption) items.push({
44
+ label: /*#__PURE__*/ jsx(Checkbox, {
45
+ onChange: (e)=>{
46
+ setDeepThink(e.target.checked);
47
+ },
48
+ checked: deepThink,
49
+ children: deepThinkTip
50
+ }),
51
+ key: 'deep-think-config'
52
+ });
53
+ if (showDataExtractionOptions && !hideDomAndScreenshotOptions) {
54
+ items.push({
55
+ label: /*#__PURE__*/ jsx(Checkbox, {
56
+ onChange: (e)=>{
57
+ setScreenshotIncluded(e.target.checked);
58
+ },
59
+ checked: screenshotIncluded,
60
+ children: screenshotIncludedTip
61
+ }),
62
+ key: 'screenshot-included-config'
63
+ });
64
+ items.push({
65
+ label: /*#__PURE__*/ jsxs("div", {
66
+ style: {
67
+ padding: '4px 0'
68
+ },
69
+ children: [
70
+ /*#__PURE__*/ jsx("div", {
71
+ style: {
72
+ marginBottom: '4px',
73
+ fontSize: '14px'
74
+ },
75
+ children: domIncludedTip
76
+ }),
77
+ /*#__PURE__*/ jsxs(Radio.Group, {
78
+ size: "small",
79
+ value: domIncluded,
80
+ onChange: (e)=>setDomIncluded(e.target.value),
81
+ children: [
82
+ /*#__PURE__*/ jsx(Radio, {
83
+ value: false,
84
+ children: "Off"
85
+ }),
86
+ /*#__PURE__*/ jsx(Radio, {
87
+ value: true,
88
+ children: "All"
89
+ }),
90
+ /*#__PURE__*/ jsx(Radio, {
91
+ value: 'visible-only',
92
+ children: "Visible only"
93
+ })
94
+ ]
95
+ })
96
+ ]
97
+ }),
98
+ key: 'dom-included-config'
99
+ });
100
+ }
101
+ return items;
102
+ }
103
+ };
104
+ export { ConfigSelector };
@@ -0,0 +1,38 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Button } from "antd";
3
+ import blackboard from "../blackboard/index.mjs";
4
+ import { iconForStatus } from "../misc/index.mjs";
5
+ import playground_demo_ui_context from "../playground/playground-demo-ui-context.json";
6
+ const ContextPreview = (param)=>{
7
+ let { uiContextPreview, setUiContextPreview, showContextPreview } = param;
8
+ if (!showContextPreview) return null;
9
+ return /*#__PURE__*/ jsxs("div", {
10
+ className: "form-part context-panel",
11
+ children: [
12
+ /*#__PURE__*/ jsx("h3", {
13
+ children: "UI Context"
14
+ }),
15
+ uiContextPreview ? /*#__PURE__*/ jsx(blackboard, {
16
+ uiContext: uiContextPreview,
17
+ hideController: true
18
+ }) : /*#__PURE__*/ jsxs("div", {
19
+ children: [
20
+ iconForStatus('failed'),
21
+ " No UI context",
22
+ /*#__PURE__*/ jsx(Button, {
23
+ type: "link",
24
+ onClick: (e)=>{
25
+ e.preventDefault();
26
+ setUiContextPreview(playground_demo_ui_context);
27
+ },
28
+ children: "Load Demo"
29
+ }),
30
+ /*#__PURE__*/ jsx("div", {
31
+ children: "To load the UI context, you can either use the demo data above, or click the 'Send to Playground' in the report page."
32
+ })
33
+ ]
34
+ })
35
+ ]
36
+ });
37
+ };
38
+ export { ContextPreview };
@@ -0,0 +1,112 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { SettingOutlined } from "@ant-design/icons";
3
+ import { Input, Modal, Tooltip } from "antd";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { useEnvConfig } from "../../store/store.mjs";
6
+ function EnvConfig(param) {
7
+ let { showTooltipWhenEmpty = true, showModelName = true, tooltipPlacement = 'bottom', mode = 'icon' } = param;
8
+ const { config, configString, loadConfig, syncFromStorage } = useEnvConfig();
9
+ const [isModalOpen, setIsModalOpen] = useState(false);
10
+ const [tempConfigString, setTempConfigString] = useState(configString);
11
+ const midsceneModelName = config.MIDSCENE_MODEL_NAME;
12
+ const componentRef = useRef(null);
13
+ const showModal = (e)=>{
14
+ syncFromStorage();
15
+ setIsModalOpen(true);
16
+ e.preventDefault();
17
+ e.stopPropagation();
18
+ };
19
+ const handleOk = ()=>{
20
+ setIsModalOpen(false);
21
+ loadConfig(tempConfigString);
22
+ };
23
+ const handleCancel = ()=>{
24
+ setIsModalOpen(false);
25
+ };
26
+ useEffect(()=>{
27
+ if (isModalOpen) setTempConfigString(configString);
28
+ }, [
29
+ isModalOpen,
30
+ configString
31
+ ]);
32
+ return /*#__PURE__*/ jsxs("div", {
33
+ style: {
34
+ display: 'flex',
35
+ justifyContent: 'flex-end',
36
+ gap: '10px',
37
+ alignItems: 'center',
38
+ height: '100%',
39
+ minHeight: '32px'
40
+ },
41
+ ref: componentRef,
42
+ children: [
43
+ showModelName ? midsceneModelName : null,
44
+ /*#__PURE__*/ jsx(Tooltip, {
45
+ title: "Please set up your environment variables before using.",
46
+ placement: tooltipPlacement,
47
+ align: {
48
+ offset: [
49
+ -10,
50
+ 5
51
+ ]
52
+ },
53
+ getPopupContainer: ()=>componentRef.current,
54
+ open: isModalOpen ? false : showTooltipWhenEmpty ? 0 === Object.keys(config).length : void 0,
55
+ children: 'icon' === mode ? /*#__PURE__*/ jsx(SettingOutlined, {
56
+ onClick: showModal
57
+ }) : /*#__PURE__*/ jsx("span", {
58
+ onClick: showModal,
59
+ style: {
60
+ color: '#006AFF',
61
+ cursor: 'pointer'
62
+ },
63
+ children: "set up"
64
+ })
65
+ }),
66
+ /*#__PURE__*/ jsxs(Modal, {
67
+ title: "Model Env Config",
68
+ open: isModalOpen,
69
+ onOk: handleOk,
70
+ onCancel: handleCancel,
71
+ okText: "Save",
72
+ style: {
73
+ width: '800px',
74
+ height: '100%',
75
+ marginTop: '10%'
76
+ },
77
+ destroyOnClose: true,
78
+ maskClosable: true,
79
+ centered: true,
80
+ children: [
81
+ /*#__PURE__*/ jsx(Input.TextArea, {
82
+ rows: 7,
83
+ placeholder: 'OPENAI_API_KEY=sk-...\nMIDSCENE_MODEL_NAME=gpt-4o-2024-08-06\n...',
84
+ value: tempConfigString,
85
+ onChange: (e)=>setTempConfigString(e.target.value),
86
+ style: {
87
+ whiteSpace: 'nowrap',
88
+ wordWrap: 'break-word'
89
+ }
90
+ }),
91
+ /*#__PURE__*/ jsxs("div", {
92
+ children: [
93
+ /*#__PURE__*/ jsx("p", {
94
+ children: "The format is KEY=VALUE and separated by new lines."
95
+ }),
96
+ /*#__PURE__*/ jsxs("p", {
97
+ children: [
98
+ "These data will be saved ",
99
+ /*#__PURE__*/ jsx("strong", {
100
+ children: "locally in your browser"
101
+ }),
102
+ "."
103
+ ]
104
+ })
105
+ ]
106
+ })
107
+ ]
108
+ })
109
+ ]
110
+ });
111
+ }
112
+ export { EnvConfig };
@@ -0,0 +1,22 @@
1
+ .env-config-reminder {
2
+ background: #fff2e8;
3
+ border-radius: 12px;
4
+ align-items: center;
5
+ gap: 12px;
6
+ margin-bottom: 12px;
7
+ padding: 12px 16px;
8
+ display: flex;
9
+ }
10
+
11
+ .env-config-reminder .reminder-icon {
12
+ color: #fa541c;
13
+ width: 16px;
14
+ height: 16px;
15
+ }
16
+
17
+ .env-config-reminder .reminder-text {
18
+ color: #000;
19
+ flex: 1;
20
+ font-size: 14px;
21
+ }
22
+
@@ -0,0 +1,28 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { ExclamationCircleFilled } from "@ant-design/icons";
3
+ import { useEnvConfig } from "../../store/store.mjs";
4
+ import { EnvConfig } from "../env-config/index.mjs";
5
+ import "./index.css";
6
+ const EnvConfigReminder = (param)=>{
7
+ let { className = '' } = param;
8
+ const { config } = useEnvConfig();
9
+ const configAlreadySet = Object.keys(config || {}).length >= 1;
10
+ if (configAlreadySet) return null;
11
+ return /*#__PURE__*/ jsxs("div", {
12
+ className: `env-config-reminder ${className}`,
13
+ children: [
14
+ /*#__PURE__*/ jsx(ExclamationCircleFilled, {
15
+ className: "reminder-icon"
16
+ }),
17
+ /*#__PURE__*/ jsx("span", {
18
+ className: "reminder-text",
19
+ children: "Please set up your environment variables before using."
20
+ }),
21
+ /*#__PURE__*/ jsx(EnvConfig, {
22
+ mode: "text",
23
+ showTooltipWhenEmpty: false
24
+ })
25
+ ]
26
+ });
27
+ };
28
+ export { EnvConfigReminder };