@godscene/visualizer 1.7.11

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 (221) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/es/component/blackboard/highlights.mjs +47 -0
  4. package/dist/es/component/blackboard/index.css +118 -0
  5. package/dist/es/component/blackboard/index.mjs +122 -0
  6. package/dist/es/component/config-selector/index.mjs +251 -0
  7. package/dist/es/component/context-preview/index.mjs +37 -0
  8. package/dist/es/component/env-config/index.mjs +237 -0
  9. package/dist/es/component/env-config-reminder/index.css +30 -0
  10. package/dist/es/component/env-config-reminder/index.mjs +27 -0
  11. package/dist/es/component/form-field/index.mjs +158 -0
  12. package/dist/es/component/history-selector/index.css +237 -0
  13. package/dist/es/component/history-selector/index.mjs +197 -0
  14. package/dist/es/component/index.mjs +1 -0
  15. package/dist/es/component/logo/index.css +19 -0
  16. package/dist/es/component/logo/index.mjs +20 -0
  17. package/dist/es/component/logo/logo.mjs +2 -0
  18. package/dist/es/component/misc/index.mjs +96 -0
  19. package/dist/es/component/nav-actions/index.mjs +14 -0
  20. package/dist/es/component/nav-actions/style.css +35 -0
  21. package/dist/es/component/player/index.css +296 -0
  22. package/dist/es/component/player/index.mjs +702 -0
  23. package/dist/es/component/player/playback-controls.mjs +4 -0
  24. package/dist/es/component/player/report-download.mjs +61 -0
  25. package/dist/es/component/player/scenes/StepScene.mjs +194 -0
  26. package/dist/es/component/player/scenes/derive-frame-state.mjs +229 -0
  27. package/dist/es/component/player/scenes/export-branded-video.mjs +360 -0
  28. package/dist/es/component/player/scenes/frame-calculator.mjs +149 -0
  29. package/dist/es/component/player/scenes/playback-frame.mjs +6 -0
  30. package/dist/es/component/player/scenes/playback-layout.mjs +12 -0
  31. package/dist/es/component/player/scenes/pointer-layout.mjs +36 -0
  32. package/dist/es/component/player/use-frame-player.mjs +87 -0
  33. package/dist/es/component/playground/index.css +930 -0
  34. package/dist/es/component/playground/playground-demo-ui-context.json +290 -0
  35. package/dist/es/component/playground-result/index.css +92 -0
  36. package/dist/es/component/playground-result/index.mjs +232 -0
  37. package/dist/es/component/prompt-input/index.css +832 -0
  38. package/dist/es/component/prompt-input/index.mjs +959 -0
  39. package/dist/es/component/screenshot-viewer/index.css +237 -0
  40. package/dist/es/component/screenshot-viewer/index.mjs +319 -0
  41. package/dist/es/component/service-mode-control/index.mjs +107 -0
  42. package/dist/es/component/shiny-text/index.css +107 -0
  43. package/dist/es/component/shiny-text/index.mjs +15 -0
  44. package/dist/es/component/universal-playground/empty-state.mjs +5 -0
  45. package/dist/es/component/universal-playground/index.css +619 -0
  46. package/dist/es/component/universal-playground/index.mjs +558 -0
  47. package/dist/es/component/universal-playground/providers/context-provider.mjs +90 -0
  48. package/dist/es/component/universal-playground/providers/indexeddb-storage-provider.mjs +280 -0
  49. package/dist/es/component/universal-playground/providers/storage-provider.mjs +279 -0
  50. package/dist/es/component/universal-playground/universal-playground-electron.mjs +668 -0
  51. package/dist/es/hooks/useMinimalTypeGate.mjs +47 -0
  52. package/dist/es/hooks/usePlaygroundExecution.mjs +435 -0
  53. package/dist/es/hooks/usePlaygroundState.mjs +278 -0
  54. package/dist/es/hooks/useSafeOverrideAIConfig.mjs +20 -0
  55. package/dist/es/hooks/useServerValid.mjs +55 -0
  56. package/dist/es/hooks/useTheme.mjs +25 -0
  57. package/dist/es/icons/action-chevron.mjs +61 -0
  58. package/dist/es/icons/avatar.mjs +70 -0
  59. package/dist/es/icons/close.mjs +61 -0
  60. package/dist/es/icons/global-perspective.mjs +58 -0
  61. package/dist/es/icons/history.mjs +72 -0
  62. package/dist/es/icons/magnifying-glass.mjs +81 -0
  63. package/dist/es/icons/player-setting.mjs +68 -0
  64. package/dist/es/icons/prompt-history.mjs +70 -0
  65. package/dist/es/icons/setting.mjs +62 -0
  66. package/dist/es/icons/show-marker.mjs +58 -0
  67. package/dist/es/index.mjs +26 -0
  68. package/dist/es/static/image/logo.png +0 -0
  69. package/dist/es/store/history.mjs +128 -0
  70. package/dist/es/store/store.mjs +277 -0
  71. package/dist/es/types.mjs +73 -0
  72. package/dist/es/utils/action-label.mjs +15 -0
  73. package/dist/es/utils/color.mjs +35 -0
  74. package/dist/es/utils/constants.mjs +99 -0
  75. package/dist/es/utils/device-capabilities.mjs +13 -0
  76. package/dist/es/utils/empty-state-scroll.mjs +8 -0
  77. package/dist/es/utils/highlight-element.mjs +62 -0
  78. package/dist/es/utils/index.mjs +13 -0
  79. package/dist/es/utils/playground-utils.mjs +43 -0
  80. package/dist/es/utils/progress-action-icon.mjs +30 -0
  81. package/dist/es/utils/prompt-input-utils.mjs +49 -0
  82. package/dist/es/utils/prompt-placeholder.mjs +19 -0
  83. package/dist/es/utils/replay-scripts.mjs +428 -0
  84. package/dist/lib/component/blackboard/highlights.js +84 -0
  85. package/dist/lib/component/blackboard/index.css +118 -0
  86. package/dist/lib/component/blackboard/index.js +169 -0
  87. package/dist/lib/component/config-selector/index.js +295 -0
  88. package/dist/lib/component/context-preview/index.js +82 -0
  89. package/dist/lib/component/env-config/index.js +271 -0
  90. package/dist/lib/component/env-config-reminder/index.css +30 -0
  91. package/dist/lib/component/env-config-reminder/index.js +61 -0
  92. package/dist/lib/component/form-field/index.js +204 -0
  93. package/dist/lib/component/history-selector/index.css +237 -0
  94. package/dist/lib/component/history-selector/index.js +243 -0
  95. package/dist/lib/component/index.js +58 -0
  96. package/dist/lib/component/logo/index.css +19 -0
  97. package/dist/lib/component/logo/index.js +67 -0
  98. package/dist/lib/component/logo/logo.js +24 -0
  99. package/dist/lib/component/misc/index.js +152 -0
  100. package/dist/lib/component/nav-actions/index.js +48 -0
  101. package/dist/lib/component/nav-actions/style.css +35 -0
  102. package/dist/lib/component/player/index.css +296 -0
  103. package/dist/lib/component/player/index.js +747 -0
  104. package/dist/lib/component/player/playback-controls.js +38 -0
  105. package/dist/lib/component/player/report-download.js +98 -0
  106. package/dist/lib/component/player/scenes/StepScene.js +228 -0
  107. package/dist/lib/component/player/scenes/derive-frame-state.js +266 -0
  108. package/dist/lib/component/player/scenes/export-branded-video.js +403 -0
  109. package/dist/lib/component/player/scenes/frame-calculator.js +186 -0
  110. package/dist/lib/component/player/scenes/playback-frame.js +40 -0
  111. package/dist/lib/component/player/scenes/playback-layout.js +46 -0
  112. package/dist/lib/component/player/scenes/pointer-layout.js +88 -0
  113. package/dist/lib/component/player/use-frame-player.js +121 -0
  114. package/dist/lib/component/playground/index.css +930 -0
  115. package/dist/lib/component/playground/playground-demo-ui-context.json +290 -0
  116. package/dist/lib/component/playground-result/index.css +92 -0
  117. package/dist/lib/component/playground-result/index.js +276 -0
  118. package/dist/lib/component/prompt-input/index.css +832 -0
  119. package/dist/lib/component/prompt-input/index.js +1005 -0
  120. package/dist/lib/component/screenshot-viewer/index.css +237 -0
  121. package/dist/lib/component/screenshot-viewer/index.js +353 -0
  122. package/dist/lib/component/service-mode-control/index.js +141 -0
  123. package/dist/lib/component/shiny-text/index.css +107 -0
  124. package/dist/lib/component/shiny-text/index.js +49 -0
  125. package/dist/lib/component/universal-playground/empty-state.js +39 -0
  126. package/dist/lib/component/universal-playground/index.css +619 -0
  127. package/dist/lib/component/universal-playground/index.js +607 -0
  128. package/dist/lib/component/universal-playground/providers/context-provider.js +133 -0
  129. package/dist/lib/component/universal-playground/providers/indexeddb-storage-provider.js +320 -0
  130. package/dist/lib/component/universal-playground/providers/storage-provider.js +337 -0
  131. package/dist/lib/component/universal-playground/universal-playground-electron.js +717 -0
  132. package/dist/lib/hooks/useMinimalTypeGate.js +81 -0
  133. package/dist/lib/hooks/usePlaygroundExecution.js +478 -0
  134. package/dist/lib/hooks/usePlaygroundState.js +312 -0
  135. package/dist/lib/hooks/useSafeOverrideAIConfig.js +57 -0
  136. package/dist/lib/hooks/useServerValid.js +89 -0
  137. package/dist/lib/hooks/useTheme.js +59 -0
  138. package/dist/lib/icons/action-chevron.js +95 -0
  139. package/dist/lib/icons/avatar.js +104 -0
  140. package/dist/lib/icons/close.js +95 -0
  141. package/dist/lib/icons/global-perspective.js +92 -0
  142. package/dist/lib/icons/history.js +106 -0
  143. package/dist/lib/icons/magnifying-glass.js +115 -0
  144. package/dist/lib/icons/player-setting.js +102 -0
  145. package/dist/lib/icons/prompt-history.js +104 -0
  146. package/dist/lib/icons/setting.js +96 -0
  147. package/dist/lib/icons/show-marker.js +92 -0
  148. package/dist/lib/index.js +204 -0
  149. package/dist/lib/static/image/logo.png +0 -0
  150. package/dist/lib/store/history.js +135 -0
  151. package/dist/lib/store/store.js +287 -0
  152. package/dist/lib/types.js +119 -0
  153. package/dist/lib/utils/action-label.js +52 -0
  154. package/dist/lib/utils/color.js +75 -0
  155. package/dist/lib/utils/constants.js +172 -0
  156. package/dist/lib/utils/device-capabilities.js +50 -0
  157. package/dist/lib/utils/empty-state-scroll.js +42 -0
  158. package/dist/lib/utils/highlight-element.js +99 -0
  159. package/dist/lib/utils/index.js +69 -0
  160. package/dist/lib/utils/playground-utils.js +86 -0
  161. package/dist/lib/utils/progress-action-icon.js +67 -0
  162. package/dist/lib/utils/prompt-input-utils.js +89 -0
  163. package/dist/lib/utils/prompt-placeholder.js +53 -0
  164. package/dist/lib/utils/replay-scripts.js +474 -0
  165. package/dist/types/component/blackboard/highlights.d.ts +11 -0
  166. package/dist/types/component/blackboard/index.d.ts +10 -0
  167. package/dist/types/component/config-selector/index.d.ts +15 -0
  168. package/dist/types/component/context-preview/index.d.ts +9 -0
  169. package/dist/types/component/env-config/index.d.ts +8 -0
  170. package/dist/types/component/env-config-reminder/index.d.ts +6 -0
  171. package/dist/types/component/form-field/index.d.ts +17 -0
  172. package/dist/types/component/history-selector/index.d.ts +13 -0
  173. package/dist/types/component/index.d.ts +1 -0
  174. package/dist/types/component/logo/index.d.ts +5 -0
  175. package/dist/types/component/misc/index.d.ts +6 -0
  176. package/dist/types/component/nav-actions/index.d.ts +12 -0
  177. package/dist/types/component/player/index.d.ts +15 -0
  178. package/dist/types/component/player/playback-controls.d.ts +1 -0
  179. package/dist/types/component/player/report-download.d.ts +32 -0
  180. package/dist/types/component/player/scenes/StepScene.d.ts +9 -0
  181. package/dist/types/component/player/scenes/derive-frame-state.d.ts +40 -0
  182. package/dist/types/component/player/scenes/export-branded-video.d.ts +33 -0
  183. package/dist/types/component/player/scenes/frame-calculator.d.ts +40 -0
  184. package/dist/types/component/player/scenes/playback-frame.d.ts +3 -0
  185. package/dist/types/component/player/scenes/playback-layout.d.ts +7 -0
  186. package/dist/types/component/player/scenes/pointer-layout.d.ts +20 -0
  187. package/dist/types/component/player/use-frame-player.d.ts +17 -0
  188. package/dist/types/component/playground-result/index.d.ts +22 -0
  189. package/dist/types/component/prompt-input/index.d.ts +23 -0
  190. package/dist/types/component/screenshot-viewer/index.d.ts +23 -0
  191. package/dist/types/component/service-mode-control/index.d.ts +6 -0
  192. package/dist/types/component/shiny-text/index.d.ts +12 -0
  193. package/dist/types/component/universal-playground/empty-state.d.ts +3 -0
  194. package/dist/types/component/universal-playground/index.d.ts +4 -0
  195. package/dist/types/component/universal-playground/providers/context-provider.d.ts +37 -0
  196. package/dist/types/component/universal-playground/providers/indexeddb-storage-provider.d.ts +71 -0
  197. package/dist/types/component/universal-playground/providers/storage-provider.d.ts +58 -0
  198. package/dist/types/component/universal-playground/universal-playground-electron.d.ts +4 -0
  199. package/dist/types/hooks/useMinimalTypeGate.d.ts +72 -0
  200. package/dist/types/hooks/usePlaygroundExecution.d.ts +40 -0
  201. package/dist/types/hooks/usePlaygroundState.d.ts +26 -0
  202. package/dist/types/hooks/useSafeOverrideAIConfig.d.ts +16 -0
  203. package/dist/types/hooks/useServerValid.d.ts +1 -0
  204. package/dist/types/hooks/useTheme.d.ts +7 -0
  205. package/dist/types/index.d.ts +29 -0
  206. package/dist/types/store/history.d.ts +16 -0
  207. package/dist/types/store/store.d.ts +57 -0
  208. package/dist/types/types.d.ts +278 -0
  209. package/dist/types/utils/action-label.d.ts +11 -0
  210. package/dist/types/utils/color.d.ts +4 -0
  211. package/dist/types/utils/constants.d.ts +80 -0
  212. package/dist/types/utils/device-capabilities.d.ts +9 -0
  213. package/dist/types/utils/empty-state-scroll.d.ts +11 -0
  214. package/dist/types/utils/highlight-element.d.ts +3 -0
  215. package/dist/types/utils/index.d.ts +5 -0
  216. package/dist/types/utils/playground-utils.d.ts +11 -0
  217. package/dist/types/utils/progress-action-icon.d.ts +12 -0
  218. package/dist/types/utils/prompt-input-utils.d.ts +24 -0
  219. package/dist/types/utils/prompt-placeholder.d.ts +1 -0
  220. package/dist/types/utils/replay-scripts.d.ts +50 -0
  221. package/package.json +82 -0
@@ -0,0 +1,558 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import icons, { ArrowDownOutlined, ClearOutlined, LoadingOutlined, UpOutlined } from "@ant-design/icons";
3
+ import { Alert, Button, Form, List, Typography, message } from "antd";
4
+ import { useCallback, useEffect, useMemo, useState } from "react";
5
+ import { usePlaygroundExecution } from "../../hooks/usePlaygroundExecution.mjs";
6
+ import { usePlaygroundState } from "../../hooks/usePlaygroundState.mjs";
7
+ import { useEnvConfig } from "../../store/store.mjs";
8
+ import { ContextPreview } from "../context-preview/index.mjs";
9
+ import { EnvConfigReminder } from "../env-config-reminder/index.mjs";
10
+ import { PlaygroundResultView } from "../playground-result/index.mjs";
11
+ import "./index.css";
12
+ import avatar from "../../icons/avatar.mjs";
13
+ import { defaultMainButtons } from "../../utils/constants.mjs";
14
+ import { calculateEmptyStatePromptScrollTop } from "../../utils/empty-state-scroll.mjs";
15
+ import { resolveProgressActionIcon } from "../../utils/progress-action-icon.mjs";
16
+ import { shouldOffsetEmptyStateForPromptInput } from "../../utils/prompt-input-utils.mjs";
17
+ import { PromptInput } from "../prompt-input/index.mjs";
18
+ import shiny_text from "../shiny-text/index.mjs";
19
+ import { shouldRenderCustomEmptyState } from "./empty-state.mjs";
20
+ import { createStorageProvider, detectBestStorageType } from "./providers/storage-provider.mjs";
21
+ import { commandMap } from "@godscene/shared/constants";
22
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
23
+ try {
24
+ var info = gen[key](arg);
25
+ var value = info.value;
26
+ } catch (error) {
27
+ reject(error);
28
+ return;
29
+ }
30
+ if (info.done) resolve(value);
31
+ else Promise.resolve(value).then(_next, _throw);
32
+ }
33
+ function _async_to_generator(fn) {
34
+ return function() {
35
+ var self = this, args = arguments;
36
+ return new Promise(function(resolve, reject) {
37
+ var gen = fn.apply(self, args);
38
+ function _next(value) {
39
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
40
+ }
41
+ function _throw(err) {
42
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
43
+ }
44
+ _next(void 0);
45
+ });
46
+ };
47
+ }
48
+ const { Text } = Typography;
49
+ function getSDKId(sdk) {
50
+ if (!sdk) return 'playground-default';
51
+ if (sdk.id && 'string' == typeof sdk.id) return `agent-${sdk.id}`;
52
+ return 'playground-default';
53
+ }
54
+ function ErrorMessage({ error }) {
55
+ if (!error) return null;
56
+ const cleanError = error.replace(/^(Error:\s*)+/, 'Error: ');
57
+ return /*#__PURE__*/ jsx(Alert, {
58
+ message: /*#__PURE__*/ jsx("span", {
59
+ style: {
60
+ color: '#ff4d4f'
61
+ },
62
+ children: cleanError
63
+ }),
64
+ type: "error",
65
+ showIcon: true
66
+ });
67
+ }
68
+ function UniversalPlayground({ playgroundSDK, storage, contextProvider, config: componentConfig = {}, branding = {}, className = '', dryMode = false, showContextPreview = true, showPromptInput = true, onHumanUse = ()=>{}, showHumanUse = false, defaultSelectedType }) {
69
+ var _componentConfig_executionFlow, _executionFlowConfig_label;
70
+ const [form] = Form.useForm();
71
+ const { config } = useEnvConfig();
72
+ const [sdkReady, setSdkReady] = useState(false);
73
+ useEffect(()=>{
74
+ form.setFieldsValue({
75
+ type: defaultMainButtons["0"]
76
+ });
77
+ }, [
78
+ form
79
+ ]);
80
+ useEffect(()=>{
81
+ const initializeSDK = ()=>_async_to_generator(function*() {
82
+ if (playgroundSDK && 'function' == typeof playgroundSDK.checkStatus) try {
83
+ yield playgroundSDK.checkStatus();
84
+ setSdkReady(true);
85
+ } catch (error) {
86
+ console.warn('Failed to initialize SDK, using default namespace:', error);
87
+ setSdkReady(true);
88
+ }
89
+ else setSdkReady(true);
90
+ })();
91
+ initializeSDK();
92
+ }, [
93
+ playgroundSDK
94
+ ]);
95
+ const effectiveStorage = useMemo(()=>{
96
+ if (storage) return storage;
97
+ if (!sdkReady) return null;
98
+ const namespace = componentConfig.storageNamespace || getSDKId(playgroundSDK);
99
+ const bestStorageType = detectBestStorageType();
100
+ console.log(`Using ${bestStorageType} storage for namespace: ${namespace}`);
101
+ return createStorageProvider(bestStorageType, namespace);
102
+ }, [
103
+ storage,
104
+ sdkReady,
105
+ componentConfig.storageNamespace,
106
+ playgroundSDK
107
+ ]);
108
+ const { loading, setLoading, infoList, setInfoList, actionSpace, actionSpaceLoading, uiContextPreview, setUiContextPreview, showScrollToBottomButton, verticalMode, replayCounter, setReplayCounter, infoListRef, currentRunningIdRef, interruptedFlagRef, clearInfoList, handleScrollToBottom } = usePlaygroundState(playgroundSDK, effectiveStorage, contextProvider, branding.targetName);
109
+ const { handleRun: executeAction, handleStop, canStop } = usePlaygroundExecution({
110
+ playgroundSDK,
111
+ storage: effectiveStorage,
112
+ actionSpace,
113
+ loading,
114
+ setLoading,
115
+ setInfoList,
116
+ replayCounter,
117
+ setReplayCounter,
118
+ verticalMode,
119
+ currentRunningIdRef,
120
+ interruptedFlagRef,
121
+ deviceType: componentConfig.deviceType
122
+ });
123
+ useEffect(()=>{
124
+ if ((null == playgroundSDK ? void 0 : playgroundSDK.overrideConfig) && config) playgroundSDK.overrideConfig(config).catch((error)=>{
125
+ console.error('Failed to override SDK config:', error);
126
+ const errorMsg = error instanceof Error ? error.message : String(error);
127
+ message.error(`Failed to apply AI configuration: ${errorMsg}`);
128
+ });
129
+ }, [
130
+ playgroundSDK,
131
+ config
132
+ ]);
133
+ const handleFormRun = useCallback(()=>_async_to_generator(function*() {
134
+ try {
135
+ const value = form.getFieldsValue();
136
+ yield executeAction(value);
137
+ } catch (error) {
138
+ message.error((null == error ? void 0 : error.message) || 'Execution failed');
139
+ }
140
+ })(), [
141
+ form,
142
+ executeAction
143
+ ]);
144
+ const configAlreadySet = Object.keys(config || {}).length >= 1;
145
+ const runButtonEnabled = componentConfig.serverMode || !dryMode && !actionSpaceLoading && configAlreadySet;
146
+ const watchedType = Form.useWatch('type', form);
147
+ const selectedType = watchedType || form.getFieldValue('type');
148
+ const serviceMode = useMemo(()=>{
149
+ if (!playgroundSDK || 'function' != typeof playgroundSDK.getServiceMode) return 'Server';
150
+ return playgroundSDK.getServiceMode();
151
+ }, [
152
+ playgroundSDK
153
+ ]);
154
+ const finalShowContextPreview = showContextPreview && false !== componentConfig.showContextPreview;
155
+ const layout = componentConfig.layout || 'vertical';
156
+ const showVersionInfo = false !== componentConfig.showVersionInfo;
157
+ const deviceType = componentConfig.deviceType;
158
+ const executionFlowConfig = null != (_componentConfig_executionFlow = componentConfig.executionFlow) ? _componentConfig_executionFlow : {};
159
+ const collapsibleProgressGroup = true === executionFlowConfig.collapsible;
160
+ const progressGroupLabel = null != (_executionFlowConfig_label = executionFlowConfig.label) ? _executionFlowConfig_label : 'Execution Flow';
161
+ const [collapsedProgressGroups, setCollapsedProgressGroups] = useState(()=>new Set());
162
+ const toggleProgressGroup = useCallback((groupId)=>{
163
+ setCollapsedProgressGroups((prev)=>{
164
+ const next = new Set(prev);
165
+ if (next.has(groupId)) next.delete(groupId);
166
+ else next.add(groupId);
167
+ return next;
168
+ });
169
+ }, []);
170
+ const { firstInProgressGroup, visibleInfoList } = useMemo(()=>{
171
+ const firstIds = new Set();
172
+ const visible = [];
173
+ let currentGroupFirstId = null;
174
+ const hideWelcome = infoList.length > 1;
175
+ for (const item of infoList)if (!hideWelcome || 'welcome' !== item.id) if ('progress' === item.type) {
176
+ if (null === currentGroupFirstId) {
177
+ currentGroupFirstId = item.id;
178
+ firstIds.add(item.id);
179
+ visible.push(item);
180
+ continue;
181
+ }
182
+ if (!collapsibleProgressGroup || !collapsedProgressGroups.has(currentGroupFirstId)) visible.push(item);
183
+ } else {
184
+ currentGroupFirstId = null;
185
+ visible.push(item);
186
+ }
187
+ return {
188
+ firstInProgressGroup: firstIds,
189
+ visibleInfoList: visible
190
+ };
191
+ }, [
192
+ collapsedProgressGroups,
193
+ collapsibleProgressGroup,
194
+ infoList
195
+ ]);
196
+ const latestProgressId = useMemo(()=>{
197
+ for(let i = infoList.length - 1; i >= 0; i--)if ('progress' === infoList[i].type) return infoList[i].id;
198
+ return null;
199
+ }, [
200
+ infoList
201
+ ]);
202
+ const renderCustomEmptyState = shouldRenderCustomEmptyState(visibleInfoList, componentConfig.emptyState);
203
+ const shouldOffsetEmptyStateForPrompt = useMemo(()=>renderCustomEmptyState && shouldOffsetEmptyStateForPromptInput(actionSpace, selectedType), [
204
+ actionSpace,
205
+ renderCustomEmptyState,
206
+ selectedType
207
+ ]);
208
+ useEffect(()=>{
209
+ if (!shouldOffsetEmptyStateForPrompt) return;
210
+ const adjustEmptyStateScroll = ()=>{
211
+ const container = infoListRef.current;
212
+ if (!container) return;
213
+ const wrapper = container.querySelector('.playground-empty-state-wrapper');
214
+ const contentStart = null == wrapper ? void 0 : wrapper.querySelector('[data-playground-empty-state-content-start]');
215
+ const contentEnd = null == wrapper ? void 0 : wrapper.querySelector('[data-playground-empty-state-content-end]');
216
+ if (!(contentStart instanceof HTMLElement) || !(contentEnd instanceof HTMLElement)) return;
217
+ const containerRect = container.getBoundingClientRect();
218
+ const startRect = contentStart.getBoundingClientRect();
219
+ const endRect = contentEnd.getBoundingClientRect();
220
+ const top = calculateEmptyStatePromptScrollTop({
221
+ currentScrollTop: container.scrollTop,
222
+ maxScrollTop: Math.max(0, container.scrollHeight - container.clientHeight),
223
+ containerTop: containerRect.top,
224
+ containerBottom: containerRect.bottom,
225
+ contentStartTop: startRect.top,
226
+ contentEndBottom: endRect.bottom
227
+ });
228
+ container.scrollTo({
229
+ top,
230
+ behavior: 'auto'
231
+ });
232
+ };
233
+ const animationFrameId = window.requestAnimationFrame(adjustEmptyStateScroll);
234
+ const timeoutId = window.setTimeout(adjustEmptyStateScroll, 160);
235
+ return ()=>{
236
+ window.cancelAnimationFrame(animationFrameId);
237
+ window.clearTimeout(timeoutId);
238
+ };
239
+ }, [
240
+ infoListRef,
241
+ selectedType,
242
+ shouldOffsetEmptyStateForPrompt
243
+ ]);
244
+ const emptyStateWrapperClassName = [
245
+ 'playground-empty-state-wrapper',
246
+ shouldOffsetEmptyStateForPrompt ? 'playground-empty-state-wrapper-offset-for-prompt' : ''
247
+ ].filter(Boolean).join(' ');
248
+ return /*#__PURE__*/ jsx("div", {
249
+ className: `playground-container ${layout}-mode ${className}`.trim(),
250
+ children: /*#__PURE__*/ jsxs(Form, {
251
+ form: form,
252
+ onFinish: handleFormRun,
253
+ className: "command-form",
254
+ children: [
255
+ finalShowContextPreview && /*#__PURE__*/ jsx("div", {
256
+ className: "context-preview-section",
257
+ children: /*#__PURE__*/ jsx(ContextPreview, {
258
+ uiContextPreview: uiContextPreview,
259
+ setUiContextPreview: setUiContextPreview,
260
+ showContextPreview: finalShowContextPreview
261
+ })
262
+ }),
263
+ /*#__PURE__*/ jsxs("div", {
264
+ className: "middle-dialog-area",
265
+ children: [
266
+ false !== componentConfig.showClearButton && infoList.length > 1 && /*#__PURE__*/ jsx("div", {
267
+ className: "clear-button-container",
268
+ children: /*#__PURE__*/ jsx(Button, {
269
+ size: "small",
270
+ icon: /*#__PURE__*/ jsx(ClearOutlined, {}),
271
+ onClick: clearInfoList,
272
+ type: "text",
273
+ className: "clear-button"
274
+ })
275
+ }),
276
+ /*#__PURE__*/ jsx("div", {
277
+ ref: infoListRef,
278
+ className: "info-list-container",
279
+ children: renderCustomEmptyState ? /*#__PURE__*/ jsx("div", {
280
+ className: emptyStateWrapperClassName,
281
+ children: componentConfig.emptyState
282
+ }) : /*#__PURE__*/ jsx(List, {
283
+ itemLayout: "vertical",
284
+ dataSource: visibleInfoList,
285
+ renderItem: (item)=>{
286
+ const isFirstInProgressGroup = collapsibleProgressGroup && firstInProgressGroup.has(item.id);
287
+ const isCollapsedHeader = isFirstInProgressGroup && collapsedProgressGroups.has(item.id);
288
+ return /*#__PURE__*/ jsxs(List.Item, {
289
+ className: "list-item",
290
+ children: [
291
+ isFirstInProgressGroup ? /*#__PURE__*/ jsxs("button", {
292
+ type: "button",
293
+ className: `progress-group-toggle ${collapsedProgressGroups.has(item.id) ? 'is-collapsed' : 'is-expanded'}`,
294
+ "aria-expanded": !collapsedProgressGroups.has(item.id),
295
+ onClick: ()=>toggleProgressGroup(item.id),
296
+ children: [
297
+ /*#__PURE__*/ jsx("span", {
298
+ className: "progress-group-toggle-label",
299
+ children: progressGroupLabel
300
+ }),
301
+ /*#__PURE__*/ jsx(UpOutlined, {
302
+ className: "progress-group-toggle-chevron"
303
+ })
304
+ ]
305
+ }) : null,
306
+ isCollapsedHeader ? null : 'user' === item.type ? /*#__PURE__*/ jsx("div", {
307
+ className: "user-message-container",
308
+ children: /*#__PURE__*/ jsx("div", {
309
+ className: "user-message-bubble",
310
+ children: item.content
311
+ })
312
+ }) : 'progress' === item.type ? /*#__PURE__*/ jsx("div", {
313
+ children: (()=>{
314
+ var _parts_, _item_result, _item_result1;
315
+ const parts = item.content.split(' - ');
316
+ const action = null == (_parts_ = parts[0]) ? void 0 : _parts_.trim();
317
+ const description = parts.slice(1).join(' - ').trim();
318
+ const isLatestProgress = item.id === latestProgressId;
319
+ const shouldShowLoading = loading && isLatestProgress;
320
+ const state = shouldShowLoading ? 'loading' : (null == (_item_result = item.result) ? void 0 : _item_result.error) ? 'error' : 'completed';
321
+ const domainIcon = 'completed' === state ? resolveProgressActionIcon(item.actionKind, executionFlowConfig.resolveActionIcon) : null;
322
+ return /*#__PURE__*/ jsxs(Fragment, {
323
+ children: [
324
+ action && /*#__PURE__*/ jsxs("span", {
325
+ className: "progress-action-item",
326
+ children: [
327
+ action,
328
+ /*#__PURE__*/ jsx("span", {
329
+ className: `progress-status-icon ${state}`,
330
+ children: 'loading' === state ? /*#__PURE__*/ jsx(LoadingOutlined, {
331
+ spin: true
332
+ }) : 'error' === state ? '✗' : null !== domainIcon ? domainIcon : '✓'
333
+ })
334
+ ]
335
+ }),
336
+ description && /*#__PURE__*/ jsx("div", {
337
+ children: /*#__PURE__*/ jsx(shiny_text, {
338
+ text: description,
339
+ className: "progress-description",
340
+ disabled: !shouldShowLoading
341
+ })
342
+ }),
343
+ (null == (_item_result1 = item.result) ? void 0 : _item_result1.error) && /*#__PURE__*/ jsx(ErrorMessage, {
344
+ error: item.result.error
345
+ })
346
+ ]
347
+ });
348
+ })()
349
+ }) : 'separator' === item.type ? /*#__PURE__*/ jsxs("div", {
350
+ className: "new-conversation-separator",
351
+ children: [
352
+ /*#__PURE__*/ jsx("div", {
353
+ className: "separator-line"
354
+ }),
355
+ /*#__PURE__*/ jsx("div", {
356
+ className: "separator-text-container",
357
+ children: /*#__PURE__*/ jsx(Text, {
358
+ type: "secondary",
359
+ className: "separator-text",
360
+ children: item.content
361
+ })
362
+ })
363
+ ]
364
+ }) : /*#__PURE__*/ jsxs("div", {
365
+ className: "system-message-container",
366
+ children: [
367
+ false !== componentConfig.showSystemMessageHeader && /*#__PURE__*/ jsxs("div", {
368
+ className: "system-message-header",
369
+ children: [
370
+ /*#__PURE__*/ jsx(icons, {
371
+ component: branding.icon || avatar,
372
+ style: {
373
+ fontSize: 20
374
+ }
375
+ }),
376
+ /*#__PURE__*/ jsx("span", {
377
+ className: "system-message-title",
378
+ children: branding.title || 'Playground'
379
+ })
380
+ ]
381
+ }),
382
+ (item.content || item.result) && /*#__PURE__*/ jsx("div", {
383
+ className: "system-message-content",
384
+ children: 'result' === item.type ? /*#__PURE__*/ jsx(PlaygroundResultView, {
385
+ result: item.result || null,
386
+ loading: item.loading || false,
387
+ serverValid: true,
388
+ serviceMode: serviceMode,
389
+ replayScriptsInfo: item.replayScriptsInfo || null,
390
+ replayCounter: item.replayCounter || 0,
391
+ loadingProgressText: item.loadingProgressText || '',
392
+ verticalMode: item.verticalMode || false,
393
+ fitMode: "width",
394
+ actionType: item.actionType,
395
+ onDownloadReport: componentConfig.onDownloadReport,
396
+ canDownloadReport: false
397
+ }) : /*#__PURE__*/ jsxs(Fragment, {
398
+ children: [
399
+ /*#__PURE__*/ jsx("div", {
400
+ className: "system-message-text",
401
+ children: item.content
402
+ }),
403
+ item.loading && item.loadingProgressText && /*#__PURE__*/ jsx("div", {
404
+ className: "loading-progress-text",
405
+ children: /*#__PURE__*/ jsx("span", {
406
+ children: item.loadingProgressText
407
+ })
408
+ })
409
+ ]
410
+ })
411
+ }),
412
+ (null == item ? void 0 : item.actionTasks) && (null == item ? void 0 : item.actionTasks.length) > 0 && /*#__PURE__*/ jsx("div", {
413
+ className: "system-message-content",
414
+ children: /*#__PURE__*/ jsxs(Fragment, {
415
+ children: [
416
+ /*#__PURE__*/ jsxs("div", {
417
+ className: "system-message-text",
418
+ children: [
419
+ /*#__PURE__*/ jsx("div", {
420
+ className: "action-result-title",
421
+ children: "此次生成如下命令,点击采用可插入到设计器"
422
+ }),
423
+ /*#__PURE__*/ jsx("ul", {
424
+ className: "action-result-list",
425
+ children: item.actionTasks.map((data, index)=>{
426
+ var _commandMap_data_subType, _data_param, _data_param1, _data_param2, _data_param3, _data_param4, _data_param_from, _data_param5, _data_param_to, _data_param6;
427
+ return /*#__PURE__*/ jsxs("li", {
428
+ title: data.locate,
429
+ children: [
430
+ /*#__PURE__*/ jsxs("div", {
431
+ className: "action-result-command",
432
+ children: [
433
+ "命令:",
434
+ (null == (_commandMap_data_subType = commandMap[data.subType]) ? void 0 : _commandMap_data_subType.DisplayName) || data.subType
435
+ ]
436
+ }),
437
+ (null == data ? void 0 : null == (_data_param = data.param) ? void 0 : _data_param.timeMs) && /*#__PURE__*/ jsxs("div", {
438
+ className: "action-result-command",
439
+ children: [
440
+ "暂停时间:",
441
+ data.param.timeMs
442
+ ]
443
+ }),
444
+ (null == data ? void 0 : null == (_data_param1 = data.param) ? void 0 : _data_param1.url) && /*#__PURE__*/ jsxs("div", {
445
+ className: "action-result-command",
446
+ children: [
447
+ "网址:",
448
+ data.param.url
449
+ ]
450
+ }),
451
+ (null == data ? void 0 : null == (_data_param2 = data.param) ? void 0 : _data_param2.keyName) && /*#__PURE__*/ jsxs("div", {
452
+ className: "action-result-command",
453
+ children: [
454
+ "按键:",
455
+ data.param.keyName
456
+ ]
457
+ }),
458
+ (null == data ? void 0 : null == (_data_param3 = data.param) ? void 0 : _data_param3.value) && /*#__PURE__*/ jsxs("div", {
459
+ className: "action-result-command",
460
+ children: [
461
+ "值:",
462
+ null == data ? void 0 : null == (_data_param4 = data.param) ? void 0 : _data_param4.value
463
+ ]
464
+ }),
465
+ (null == (_data_param5 = data.param) ? void 0 : null == (_data_param_from = _data_param5.from) ? void 0 : _data_param_from.locateDescription) && (null == (_data_param6 = data.param) ? void 0 : null == (_data_param_to = _data_param6.to) ? void 0 : _data_param_to.locateDescription) && /*#__PURE__*/ jsxs("div", {
466
+ className: "action-result-locate",
467
+ children: [
468
+ /*#__PURE__*/ jsx("span", {
469
+ children: "拖拽元素:"
470
+ }),
471
+ /*#__PURE__*/ jsx("span", {
472
+ children: data.param.from.locateDescription
473
+ }),
474
+ /*#__PURE__*/ jsx("span", {
475
+ children: "目标元素:"
476
+ }),
477
+ /*#__PURE__*/ jsx("span", {
478
+ children: data.param.to.locateDescription
479
+ })
480
+ ]
481
+ }),
482
+ data.locateDescription && /*#__PURE__*/ jsxs("div", {
483
+ className: "action-result-locate",
484
+ children: [
485
+ "元素:",
486
+ data.locateDescription
487
+ ]
488
+ })
489
+ ]
490
+ }, index);
491
+ })
492
+ })
493
+ ]
494
+ }),
495
+ /*#__PURE__*/ jsx("div", {
496
+ className: "action-result-btns",
497
+ children: /*#__PURE__*/ jsx(Button, {
498
+ type: "primary",
499
+ onClick: ()=>onHumanUse(item.actionTasks),
500
+ children: "采用"
501
+ })
502
+ })
503
+ ]
504
+ })
505
+ })
506
+ ]
507
+ })
508
+ ]
509
+ }, item.id);
510
+ }
511
+ })
512
+ }),
513
+ showScrollToBottomButton && false !== componentConfig.enableScrollToBottom && /*#__PURE__*/ jsx(Button, {
514
+ className: "scroll-to-bottom-button",
515
+ type: "primary",
516
+ shape: "circle",
517
+ icon: /*#__PURE__*/ jsx(ArrowDownOutlined, {}),
518
+ onClick: handleScrollToBottom,
519
+ size: "large"
520
+ })
521
+ ]
522
+ }),
523
+ /*#__PURE__*/ jsxs("div", {
524
+ className: "bottom-input-section",
525
+ children: [
526
+ componentConfig.showEnvConfigReminder ? /*#__PURE__*/ jsx(EnvConfigReminder, {}) : null,
527
+ /*#__PURE__*/ jsx(PromptInput, {
528
+ runButtonEnabled: runButtonEnabled,
529
+ form: form,
530
+ serviceMode: serviceMode,
531
+ selectedType: selectedType,
532
+ dryMode: dryMode,
533
+ stoppable: canStop,
534
+ loading: loading,
535
+ onRun: handleFormRun,
536
+ onStop: handleStop,
537
+ actionSpace: actionSpace,
538
+ chrome: componentConfig.promptInputChrome,
539
+ deviceType: deviceType
540
+ })
541
+ ]
542
+ }),
543
+ showVersionInfo && branding.version && /*#__PURE__*/ jsx("div", {
544
+ className: "version-info-section",
545
+ children: /*#__PURE__*/ jsxs("span", {
546
+ className: "version-text",
547
+ children: [
548
+ "version: ",
549
+ branding.version
550
+ ]
551
+ })
552
+ })
553
+ ]
554
+ })
555
+ });
556
+ }
557
+ const universal_playground = UniversalPlayground;
558
+ export { UniversalPlayground, universal_playground as default };
@@ -0,0 +1,90 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) resolve(value);
10
+ else Promise.resolve(value).then(_next, _throw);
11
+ }
12
+ function _async_to_generator(fn) {
13
+ return function() {
14
+ var self = this, args = arguments;
15
+ return new Promise(function(resolve, reject) {
16
+ var gen = fn.apply(self, args);
17
+ function _next(value) {
18
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
19
+ }
20
+ function _throw(err) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
22
+ }
23
+ _next(void 0);
24
+ });
25
+ };
26
+ }
27
+ function _define_property(obj, key, value) {
28
+ if (key in obj) Object.defineProperty(obj, key, {
29
+ value: value,
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true
33
+ });
34
+ else obj[key] = value;
35
+ return obj;
36
+ }
37
+ class BaseContextProvider {
38
+ refreshContext() {
39
+ return _async_to_generator(function*() {
40
+ this.cachedContext = void 0;
41
+ return yield this.getUIContext();
42
+ }).call(this);
43
+ }
44
+ constructor(){
45
+ _define_property(this, "cachedContext", void 0);
46
+ }
47
+ }
48
+ class AgentContextProvider extends BaseContextProvider {
49
+ getUIContext() {
50
+ return _async_to_generator(function*() {
51
+ if (this.cachedContext) return this.cachedContext;
52
+ const agent = this.getAgent();
53
+ if (!(null == agent ? void 0 : agent.getUIContext)) throw new Error('Agent does not support getUIContext');
54
+ const context = yield agent.getUIContext();
55
+ this.cachedContext = context;
56
+ return context;
57
+ }).call(this);
58
+ }
59
+ constructor(getAgent, options){
60
+ super(), _define_property(this, "getAgent", void 0), _define_property(this, "options", void 0), this.getAgent = getAgent, this.options = options;
61
+ }
62
+ }
63
+ class StaticContextProvider extends BaseContextProvider {
64
+ getUIContext() {
65
+ return _async_to_generator(function*() {
66
+ return this.context;
67
+ }).call(this);
68
+ }
69
+ refreshContext() {
70
+ return _async_to_generator(function*() {
71
+ return this.context;
72
+ }).call(this);
73
+ }
74
+ constructor(context){
75
+ super(), _define_property(this, "context", void 0), this.context = context;
76
+ }
77
+ }
78
+ class NoOpContextProvider {
79
+ getUIContext() {
80
+ return _async_to_generator(function*() {
81
+ throw new Error('Context preview is disabled');
82
+ })();
83
+ }
84
+ refreshContext() {
85
+ return _async_to_generator(function*() {
86
+ throw new Error('Context preview is disabled');
87
+ })();
88
+ }
89
+ }
90
+ export { AgentContextProvider, BaseContextProvider, NoOpContextProvider, StaticContextProvider };