@midscene/visualizer 0.26.2 → 0.26.3-beta-20250813021342.0

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 (124) hide show
  1. package/dist/es/blank_polyfill.mjs +2 -0
  2. package/dist/es/component/blackboard.css +12 -5
  3. package/dist/es/component/blackboard.mjs +266 -0
  4. package/dist/es/component/color.mjs +35 -0
  5. package/dist/es/component/describer.css +9 -5
  6. package/dist/es/component/describer.mjs +128 -0
  7. package/dist/es/component/env-config.mjs +112 -0
  8. package/dist/es/component/github-star.css +1 -0
  9. package/dist/es/component/github-star.mjs +20 -0
  10. package/dist/es/component/logo.css +5 -3
  11. package/dist/es/component/logo.mjs +20 -0
  12. package/dist/es/component/misc.mjs +54 -0
  13. package/dist/es/component/pixi-loader.mjs +16 -0
  14. package/dist/es/component/player.css +88 -70
  15. package/dist/es/component/player.mjs +628 -0
  16. package/dist/es/component/playground/ConfigSelector.mjs +53 -0
  17. package/dist/es/component/playground/ContextPreview.mjs +39 -0
  18. package/dist/es/component/playground/HistorySelector.mjs +193 -0
  19. package/dist/es/component/playground/PlaygroundResult.mjs +60 -0
  20. package/dist/es/component/playground/PromptInput.mjs +225 -0
  21. package/dist/es/component/playground/ServiceModeControl.mjs +100 -0
  22. package/dist/es/component/playground/index.css +140 -98
  23. package/dist/es/component/playground/playground-constants.mjs +45 -0
  24. package/dist/es/component/playground/playground-utils.mjs +89 -0
  25. package/dist/es/component/playground/useServerValid.mjs +27 -0
  26. package/dist/es/component/playground/useStaticPageAgent.mjs +12 -0
  27. package/dist/es/component/replay-scripts.mjs +271 -0
  28. package/dist/es/component/shiny-text.css +33 -22
  29. package/dist/es/component/shiny-text.mjs +15 -0
  30. package/dist/es/component/store/history.mjs +55 -0
  31. package/dist/es/component/store/store.mjs +128 -0
  32. package/dist/es/icons/close.mjs +19 -0
  33. package/dist/es/icons/history.mjs +30 -0
  34. package/dist/es/icons/magnifying-glass.mjs +39 -0
  35. package/dist/es/icons/setting.mjs +20 -0
  36. package/dist/es/index.mjs +21 -0
  37. package/dist/es/init.mjs +10 -0
  38. package/dist/es/{utils.js → utils.mjs} +51 -75
  39. package/dist/lib/blank_polyfill.js +34 -38
  40. package/dist/lib/component/blackboard.css +12 -5
  41. package/dist/lib/component/blackboard.js +293 -306
  42. package/dist/lib/component/color.js +64 -74
  43. package/dist/lib/component/describer.css +9 -5
  44. package/dist/lib/component/describer.js +158 -198
  45. package/dist/lib/component/env-config.js +142 -147
  46. package/dist/lib/component/github-star.css +1 -0
  47. package/dist/lib/component/github-star.js +51 -62
  48. package/dist/lib/component/logo.css +5 -3
  49. package/dist/lib/component/logo.js +53 -56
  50. package/dist/lib/component/misc.js +85 -84
  51. package/dist/lib/component/pixi-loader.js +49 -80
  52. package/dist/lib/component/player.css +88 -70
  53. package/dist/lib/component/player.js +627 -738
  54. package/dist/lib/component/playground/ConfigSelector.js +91 -92
  55. package/dist/lib/component/playground/ContextPreview.js +80 -72
  56. package/dist/lib/component/playground/HistorySelector.js +234 -197
  57. package/dist/lib/component/playground/PlaygroundResult.js +100 -103
  58. package/dist/lib/component/playground/PromptInput.js +250 -237
  59. package/dist/lib/component/playground/ServiceModeControl.js +124 -124
  60. package/dist/lib/component/playground/index.css +140 -98
  61. package/dist/lib/component/playground/playground-constants.js +97 -73
  62. package/dist/lib/component/playground/playground-types.js +17 -31
  63. package/dist/lib/component/playground/playground-utils.js +140 -168
  64. package/dist/lib/component/playground/useServerValid.js +55 -86
  65. package/dist/lib/component/playground/useStaticPageAgent.js +45 -51
  66. package/dist/lib/component/replay-scripts.js +291 -373
  67. package/dist/lib/component/shiny-text.css +33 -22
  68. package/dist/lib/component/shiny-text.js +46 -57
  69. package/dist/lib/component/store/history.js +58 -64
  70. package/dist/lib/component/store/store.js +132 -128
  71. package/dist/lib/icons/close.js +53 -0
  72. package/dist/lib/icons/history.js +64 -0
  73. package/dist/lib/icons/magnifying-glass.js +73 -0
  74. package/dist/lib/icons/setting.js +54 -0
  75. package/dist/lib/index.js +158 -124
  76. package/dist/lib/init.js +39 -46
  77. package/dist/lib/utils.js +105 -109
  78. package/dist/types/blank_polyfill.d.ts +2 -2
  79. package/dist/types/component/playground/ConfigSelector.d.ts +1 -0
  80. package/dist/types/component/playground/ContextPreview.d.ts +1 -0
  81. package/dist/types/component/playground/HistorySelector.d.ts +1 -0
  82. package/dist/types/component/playground/PlaygroundResult.d.ts +1 -0
  83. package/dist/types/component/playground/PromptInput.d.ts +1 -0
  84. package/dist/types/component/playground/ServiceModeControl.d.ts +1 -0
  85. package/package.json +16 -18
  86. package/dist/es/assets/close.909351c0.svg +0 -4
  87. package/dist/es/assets/history.164a4eab.svg +0 -4
  88. package/dist/es/assets/magnifying-glass.9498e70e.svg +0 -12
  89. package/dist/es/assets/setting.80ab7285.svg +0 -11
  90. package/dist/es/blank_polyfill.js +0 -10
  91. package/dist/es/component/blackboard.js +0 -286
  92. package/dist/es/component/color.js +0 -49
  93. package/dist/es/component/describer.js +0 -173
  94. package/dist/es/component/env-config.js +0 -117
  95. package/dist/es/component/github-star.js +0 -31
  96. package/dist/es/component/logo.js +0 -25
  97. package/dist/es/component/misc.js +0 -63
  98. package/dist/es/component/pixi-loader.js +0 -51
  99. package/dist/es/component/player.js +0 -746
  100. package/dist/es/component/playground/ConfigSelector.js +0 -64
  101. package/dist/es/component/playground/ContextPreview.js +0 -42
  102. package/dist/es/component/playground/HistorySelector.js +0 -168
  103. package/dist/es/component/playground/PlaygroundResult.js +0 -73
  104. package/dist/es/component/playground/PromptInput.js +0 -212
  105. package/dist/es/component/playground/ServiceModeControl.js +0 -100
  106. package/dist/es/component/playground/playground-constants.js +0 -39
  107. package/dist/es/component/playground/playground-types.js +0 -6
  108. package/dist/es/component/playground/playground-utils.js +0 -141
  109. package/dist/es/component/playground/useServerValid.js +0 -58
  110. package/dist/es/component/playground/useStaticPageAgent.js +0 -20
  111. package/dist/es/component/replay-scripts.js +0 -361
  112. package/dist/es/component/shiny-text.js +0 -30
  113. package/dist/es/component/store/history.js +0 -34
  114. package/dist/es/component/store/store.js +0 -99
  115. package/dist/es/index.js +0 -79
  116. package/dist/es/init.js +0 -17
  117. package/dist/index.css +0 -595
  118. package/dist/index.js +0 -1
  119. package/dist/lib/assets/close.909351c0.svg +0 -4
  120. package/dist/lib/assets/history.164a4eab.svg +0 -4
  121. package/dist/lib/assets/magnifying-glass.9498e70e.svg +0 -12
  122. package/dist/lib/assets/setting.80ab7285.svg +0 -11
  123. package/dist/lib/component/common.css +0 -0
  124. /package/dist/es/component/{common.css → playground/playground-types.mjs} +0 -0
@@ -1,39 +0,0 @@
1
- import Buffer from "buffer";
2
- import processBrowser from "process/browser";
3
- import console from "console-browserify";
4
- var buffer = {
5
- Buffer
6
- };
7
- import { jsx, jsxs } from "react/jsx-runtime";
8
- import { Alert } from "antd";
9
- import ShinyText from "../shiny-text";
10
- import "./index.css";
11
- const errorMessageServerNotReady = /* @__PURE__ */ jsxs("span", { children: [
12
- "Don't worry, just one more step to launch the playground server.",
13
- /* @__PURE__ */ jsx("br", {}),
14
- "Please run one of the commands under the midscene project directory:",
15
- /* @__PURE__ */ jsx("br", {}),
16
- "a. ",
17
- /* @__PURE__ */ jsx("strong", { children: "npx midscene-playground" }),
18
- /* @__PURE__ */ jsx("br", {}),
19
- "b. ",
20
- /* @__PURE__ */ jsx("strong", { children: "npx --yes @midscene/web" })
21
- ] });
22
- const serverLaunchTip = (notReadyMessage = errorMessageServerNotReady) => /* @__PURE__ */ jsx("div", { className: "server-tip", children: /* @__PURE__ */ jsx(
23
- Alert,
24
- {
25
- message: "Playground Server Not Ready",
26
- description: notReadyMessage,
27
- type: "warning"
28
- }
29
- ) });
30
- const emptyResultTip = /* @__PURE__ */ jsx("div", { className: "result-empty-tip", style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(ShinyText, { disabled: true, text: "The result will be shown here" }) });
31
- const trackingTip = "limit popup to current tab";
32
- const deepThinkTip = "deep think";
33
- export {
34
- deepThinkTip,
35
- emptyResultTip,
36
- errorMessageServerNotReady,
37
- serverLaunchTip,
38
- trackingTip
39
- };
@@ -1,6 +0,0 @@
1
- import Buffer from "buffer";
2
- import processBrowser from "process/browser";
3
- import console from "console-browserify";
4
- var buffer = {
5
- Buffer
6
- };
@@ -1,141 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import Buffer2 from "buffer";
22
- import processBrowser from "process/browser";
23
- import console from "console-browserify";
24
- var buffer = {
25
- Buffer: Buffer2
26
- };
27
- import { PLAYGROUND_SERVER_PORT } from "@midscene/shared/constants";
28
- import {
29
- ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED,
30
- StaticPage,
31
- StaticPageAgent
32
- } from "@midscene/web/playground";
33
- const serverBase = `http://localhost:${PLAYGROUND_SERVER_PORT}`;
34
- const checkServerStatus = () => __async(void 0, null, function* () {
35
- try {
36
- const res = yield fetch(`${serverBase}/status`);
37
- return res.status === 200;
38
- } catch (e) {
39
- return false;
40
- }
41
- });
42
- const requestPlaygroundServer = (_0, _1, _2, ..._3) => __async(void 0, [_0, _1, _2, ..._3], function* (context, type, prompt, {
43
- requestId,
44
- deepThink
45
- } = {}) {
46
- const payload = { context, type, prompt };
47
- if (requestId) {
48
- payload.requestId = requestId;
49
- }
50
- if (deepThink) {
51
- payload.deepThink = deepThink;
52
- }
53
- const res = yield fetch(`${serverBase}/execute`, {
54
- method: "POST",
55
- headers: {
56
- "Content-Type": "application/json"
57
- },
58
- body: JSON.stringify(payload)
59
- });
60
- return res.json();
61
- });
62
- const overrideServerConfig = (aiConfig) => __async(void 0, null, function* () {
63
- return fetch(`${serverBase}/config`, {
64
- method: "POST",
65
- headers: {
66
- "Content-Type": "application/json"
67
- },
68
- body: JSON.stringify({ aiConfig })
69
- });
70
- });
71
- const cancelTask = (requestId) => __async(void 0, null, function* () {
72
- try {
73
- const res = yield fetch(`${serverBase}/cancel/${requestId}`);
74
- return res.json();
75
- } catch (error) {
76
- console.error("Failed to cancel task:", error);
77
- return { error: "Failed to cancel task" };
78
- }
79
- });
80
- const getTaskProgress = (requestId) => __async(void 0, null, function* () {
81
- try {
82
- const response = yield fetch(`${serverBase}/task-progress/${requestId}`);
83
- return yield response.json();
84
- } catch (error) {
85
- console.error("Failed to poll task progress:", error);
86
- return { tip: null };
87
- }
88
- });
89
- const actionNameForType = (type) => {
90
- if (type === "aiAction")
91
- return "Action";
92
- if (type === "aiQuery")
93
- return "Query";
94
- if (type === "aiAssert")
95
- return "Assert";
96
- if (type === "aiTap")
97
- return "Tap";
98
- return type;
99
- };
100
- const staticAgentFromContext = (context) => {
101
- const page = new StaticPage(context);
102
- return new StaticPageAgent(page);
103
- };
104
- const formatErrorMessage = (e) => {
105
- const errorMessage = (e == null ? void 0 : e.message) || "";
106
- if (errorMessage.includes("of different extension")) {
107
- return "Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq";
108
- }
109
- if (!(errorMessage == null ? void 0 : errorMessage.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED))) {
110
- return errorMessage;
111
- }
112
- return "Unknown error";
113
- };
114
- const getPlaceholderForType = (type) => {
115
- if (type === "aiQuery") {
116
- return "What do you want to query?";
117
- }
118
- if (type === "aiAssert") {
119
- return "What do you want to assert?";
120
- }
121
- return "What do you want to do?";
122
- };
123
- const blankResult = {
124
- result: null,
125
- dump: null,
126
- reportHTML: null,
127
- error: null
128
- };
129
- export {
130
- actionNameForType,
131
- blankResult,
132
- cancelTask,
133
- checkServerStatus,
134
- formatErrorMessage,
135
- getPlaceholderForType,
136
- getTaskProgress,
137
- overrideServerConfig,
138
- requestPlaygroundServer,
139
- serverBase,
140
- staticAgentFromContext
141
- };
@@ -1,58 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import Buffer2 from "buffer";
22
- import processBrowser from "process/browser";
23
- import console from "console-browserify";
24
- var buffer = {
25
- Buffer: Buffer2
26
- };
27
- import { useEffect, useState } from "react";
28
- import { useEnvConfig } from "../store/store";
29
- import { checkServerStatus } from "./playground-utils";
30
- const useServerValid = (shouldRun = true) => {
31
- const [serverValid, setServerValid] = useState(true);
32
- const { serviceMode } = useEnvConfig();
33
- useEffect(() => {
34
- let interruptFlag = false;
35
- if (!shouldRun)
36
- return;
37
- Promise.resolve(
38
- (() => __async(void 0, null, function* () {
39
- while (!interruptFlag) {
40
- const status = yield checkServerStatus();
41
- if (status) {
42
- setServerValid(true);
43
- } else {
44
- setServerValid(false);
45
- }
46
- yield new Promise((resolve) => setTimeout(resolve, 1e3));
47
- }
48
- }))()
49
- );
50
- return () => {
51
- interruptFlag = true;
52
- };
53
- }, [serviceMode, shouldRun]);
54
- return serverValid;
55
- };
56
- export {
57
- useServerValid
58
- };
@@ -1,20 +0,0 @@
1
- import Buffer from "buffer";
2
- import processBrowser from "process/browser";
3
- import console from "console-browserify";
4
- var buffer = {
5
- Buffer
6
- };
7
- import { useMemo } from "react";
8
- import { staticAgentFromContext } from "./playground-utils";
9
- const useStaticPageAgent = (context) => {
10
- const agent = useMemo(() => {
11
- if (!context)
12
- return null;
13
- return staticAgentFromContext(context);
14
- }, [context]);
15
- return agent;
16
- };
17
- export {
18
- staticAgentFromContext,
19
- useStaticPageAgent
20
- };
@@ -1,361 +0,0 @@
1
- "use client";
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- import Buffer2 from "buffer";
22
- import processBrowser from "process/browser";
23
- import console from "console-browserify";
24
- var buffer = {
25
- Buffer: Buffer2
26
- };
27
- import "./player.css";
28
- import { mousePointer } from "../utils";
29
- import { paramStr, typeStr } from "@midscene/web/ui-utils";
30
- import { treeToList } from "@midscene/shared/extractor";
31
- const stillDuration = 900;
32
- const actionSpinningPointerDuration = 300;
33
- const stillAfterInsightDuration = 300;
34
- const locateDuration = 800;
35
- const actionDuration = 1e3;
36
- const clearInsightDuration = 200;
37
- const cameraStateForRect = (rect, imageWidth, imageHeight) => {
38
- const canvasRatio = imageWidth / imageHeight;
39
- const rectRatio = rect.width / rect.height;
40
- let rectWidthOnPage;
41
- if (rectRatio >= canvasRatio) {
42
- rectWidthOnPage = rect.width;
43
- } else {
44
- rectWidthOnPage = rect.height / imageHeight * imageWidth;
45
- }
46
- const cameraPaddingRatio = rectWidthOnPage > 400 ? 0.1 : rectWidthOnPage > 50 ? 0.2 : 0.3;
47
- const cameraWidth = Math.min(
48
- imageWidth,
49
- rectWidthOnPage + imageWidth * cameraPaddingRatio * 2
50
- );
51
- const cameraHeight = cameraWidth * (imageHeight / imageWidth);
52
- let left = Math.min(
53
- rect.left - imageWidth * cameraPaddingRatio,
54
- imageWidth - cameraWidth
55
- );
56
- left = Math.max(left, 0);
57
- let top = Math.min(
58
- rect.top - imageHeight * cameraPaddingRatio,
59
- imageHeight - cameraHeight
60
- );
61
- top = Math.max(top, 0);
62
- return {
63
- left: Math.round(left),
64
- top: Math.round(top),
65
- width: Math.round(cameraWidth)
66
- };
67
- };
68
- const mergeTwoCameraState = (cameraState1, cameraState2) => {
69
- const newLeft = Math.min(cameraState1.left, cameraState2.left);
70
- const newTop = Math.min(cameraState1.top, cameraState2.top);
71
- const newRight = Math.max(
72
- cameraState1.left + cameraState1.width,
73
- cameraState2.left + cameraState2.width
74
- );
75
- const newWidth = newRight - newLeft;
76
- return {
77
- left: newLeft,
78
- top: newTop,
79
- width: newWidth
80
- };
81
- };
82
- const allScriptsFromDump = (dump) => {
83
- let width = void 0;
84
- let height = void 0;
85
- let sdkVersion = void 0;
86
- let modelName = void 0;
87
- let modelDescription = void 0;
88
- dump.executions.forEach((execution) => {
89
- if (execution.sdkVersion) {
90
- sdkVersion = execution.sdkVersion;
91
- }
92
- if (execution.model_name) {
93
- modelName = execution.model_name;
94
- }
95
- if (execution.model_description) {
96
- modelDescription = execution.model_description;
97
- }
98
- execution.tasks.forEach((task) => {
99
- var _a, _b;
100
- const insightTask = task;
101
- if ((_b = (_a = insightTask.pageContext) == null ? void 0 : _a.size) == null ? void 0 : _b.width) {
102
- width = insightTask.pageContext.size.width;
103
- height = insightTask.pageContext.size.height;
104
- }
105
- });
106
- });
107
- if (!width || !height) {
108
- console.warn("width or height is missing in dump file");
109
- return {
110
- scripts: [],
111
- sdkVersion,
112
- modelName,
113
- modelDescription
114
- };
115
- }
116
- const allScripts = [];
117
- dump.executions.forEach((execution) => {
118
- const scripts = generateAnimationScripts(execution, -1, width, height);
119
- if (scripts) {
120
- allScripts.push(...scripts);
121
- }
122
- });
123
- const allScriptsWithoutIntermediateDoneFrame = allScripts.filter(
124
- (script, index) => {
125
- if (index !== allScripts.length - 1 && script.title === "Done") {
126
- return false;
127
- }
128
- return true;
129
- }
130
- );
131
- return {
132
- scripts: allScriptsWithoutIntermediateDoneFrame,
133
- width,
134
- height,
135
- sdkVersion,
136
- modelName,
137
- modelDescription
138
- };
139
- };
140
- const generateAnimationScripts = (execution, task, imageWidth, imageHeight) => {
141
- if (!execution || !execution.tasks.length)
142
- return null;
143
- if (imageWidth === 0 || imageHeight === 0) {
144
- return null;
145
- }
146
- let tasksIncluded = [];
147
- if (task === -1) {
148
- tasksIncluded = execution.tasks;
149
- } else {
150
- const startIndex = execution.tasks.findIndex((t) => t === task);
151
- if (startIndex === -1) {
152
- console.error("task not found, cannot generate animation scripts");
153
- return null;
154
- }
155
- if (startIndex === execution.tasks.length - 1) {
156
- return null;
157
- }
158
- for (let i = startIndex; i < execution.tasks.length; i++) {
159
- if (i > startIndex && execution.tasks[i].type === "Planning") {
160
- break;
161
- }
162
- tasksIncluded.push(execution.tasks[i]);
163
- }
164
- }
165
- if (tasksIncluded.length === 0) {
166
- return null;
167
- }
168
- const fullPageCameraState = cameraStateForRect(
169
- {
170
- left: 0,
171
- top: 0,
172
- width: imageWidth,
173
- height: imageHeight
174
- },
175
- imageWidth,
176
- imageHeight
177
- );
178
- const pointerScript = (img, title, subTitle) => {
179
- return {
180
- type: "pointer",
181
- img,
182
- duration: 0,
183
- title,
184
- subTitle
185
- };
186
- };
187
- const scripts = [];
188
- let insightCameraState = void 0;
189
- let currentCameraState = fullPageCameraState;
190
- let insightOnTop = false;
191
- const taskCount = tasksIncluded.length;
192
- let initSubTitle = "";
193
- let errorStateFlag = false;
194
- tasksIncluded.forEach((task2, index) => {
195
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
196
- if (errorStateFlag)
197
- return;
198
- if (index === 0) {
199
- initSubTitle = paramStr(task2);
200
- }
201
- if (task2.type === "Planning") {
202
- const planningTask = task2;
203
- if (planningTask.recorder && planningTask.recorder.length > 0) {
204
- scripts.push({
205
- type: "img",
206
- img: (_b = (_a = planningTask.recorder) == null ? void 0 : _a[0]) == null ? void 0 : _b.screenshot,
207
- camera: index === 0 ? fullPageCameraState : void 0,
208
- duration: stillDuration,
209
- title: typeStr(task2),
210
- subTitle: paramStr(task2)
211
- });
212
- }
213
- } else if (task2.type === "Insight" && task2.subType === "Locate") {
214
- const insightTask = task2;
215
- const resultElement = (_c = insightTask.output) == null ? void 0 : _c.element;
216
- const title = typeStr(task2);
217
- const subTitle = paramStr(task2);
218
- if (resultElement == null ? void 0 : resultElement.rect) {
219
- insightCameraState = __spreadProps(__spreadValues({}, cameraStateForRect(resultElement.rect, imageWidth, imageHeight)), {
220
- pointerLeft: resultElement.center[0],
221
- pointerTop: resultElement.center[1]
222
- });
223
- }
224
- const context = insightTask.pageContext;
225
- if (context == null ? void 0 : context.screenshotBase64) {
226
- const insightDump = (_d = insightTask.log) == null ? void 0 : _d.dump;
227
- const insightContentLength = context.tree ? treeToList(context.tree).length : 0;
228
- if (context.screenshotBase64) {
229
- scripts.push({
230
- type: "img",
231
- img: context.screenshotBase64,
232
- duration: stillAfterInsightDuration,
233
- title,
234
- subTitle
235
- });
236
- }
237
- let cameraState = void 0;
238
- if (currentCameraState === fullPageCameraState) {
239
- cameraState = void 0;
240
- } else if (!insightCameraState) {
241
- cameraState = void 0;
242
- } else {
243
- cameraState = mergeTwoCameraState(
244
- currentCameraState,
245
- insightCameraState
246
- );
247
- }
248
- scripts.push({
249
- type: "insight",
250
- img: context.screenshotBase64,
251
- context,
252
- camera: cameraState,
253
- highlightElement: ((_e = insightTask.output) == null ? void 0 : _e.element) || void 0,
254
- searchArea: (_f = insightDump == null ? void 0 : insightDump.taskInfo) == null ? void 0 : _f.searchArea,
255
- duration: insightContentLength > 20 ? locateDuration : locateDuration * 0.5,
256
- insightCameraDuration: locateDuration,
257
- title,
258
- subTitle
259
- });
260
- scripts.push({
261
- type: "sleep",
262
- duration: stillAfterInsightDuration,
263
- title,
264
- subTitle
265
- });
266
- insightOnTop = true;
267
- }
268
- } else if (task2.type === "Action" && task2.subType !== "FalsyConditionStatement") {
269
- const title = typeStr(task2);
270
- const subTitle = paramStr(task2);
271
- scripts.push(pointerScript(mousePointer, title, subTitle));
272
- currentCameraState = insightCameraState != null ? insightCameraState : fullPageCameraState;
273
- scripts.push({
274
- type: "img",
275
- img: (_h = (_g = task2.recorder) == null ? void 0 : _g[0]) == null ? void 0 : _h.screenshot,
276
- duration: actionDuration,
277
- camera: task2.subType === "Sleep" ? fullPageCameraState : insightCameraState,
278
- title,
279
- subTitle
280
- });
281
- if (insightOnTop) {
282
- scripts.push({
283
- type: "clear-insight",
284
- duration: clearInsightDuration,
285
- title,
286
- subTitle
287
- });
288
- insightOnTop = false;
289
- }
290
- const imgStillDuration = index < taskCount - 1 ? stillDuration : 0;
291
- if ((_j = (_i = task2.recorder) == null ? void 0 : _i[1]) == null ? void 0 : _j.screenshot) {
292
- scripts.push({
293
- type: "spinning-pointer",
294
- duration: actionSpinningPointerDuration,
295
- title,
296
- subTitle
297
- });
298
- scripts.push(pointerScript(mousePointer, title, subTitle));
299
- scripts.push({
300
- type: "img",
301
- img: (_l = (_k = task2.recorder) == null ? void 0 : _k[1]) == null ? void 0 : _l.screenshot,
302
- duration: imgStillDuration,
303
- title,
304
- subTitle
305
- });
306
- } else {
307
- scripts.push({
308
- type: "sleep",
309
- duration: imgStillDuration,
310
- title,
311
- subTitle
312
- });
313
- }
314
- } else {
315
- const title = typeStr(task2);
316
- const subTitle = paramStr(task2);
317
- const screenshot = (_n = (_m = task2.recorder) == null ? void 0 : _m[task2.recorder.length - 1]) == null ? void 0 : _n.screenshot;
318
- if (screenshot) {
319
- scripts.push({
320
- type: "img",
321
- img: screenshot,
322
- duration: stillDuration,
323
- camera: fullPageCameraState,
324
- title,
325
- subTitle
326
- });
327
- }
328
- }
329
- if (task2.status !== "finished") {
330
- errorStateFlag = true;
331
- const errorTitle = typeStr(task2);
332
- const errorMsg = task2.errorMessage || "unknown error";
333
- const errorSubTitle = errorMsg.indexOf("NOT_IMPLEMENTED_AS_DESIGNED") > 0 ? "Further actions cannot be performed in the current environment" : errorMsg;
334
- scripts.push({
335
- type: "img",
336
- img: task2.recorder && task2.recorder.length > 0 ? task2.recorder[task2.recorder.length - 1].screenshot : "",
337
- camera: fullPageCameraState,
338
- duration: stillDuration,
339
- title: errorTitle,
340
- subTitle: errorSubTitle
341
- });
342
- return;
343
- }
344
- });
345
- if (!errorStateFlag) {
346
- scripts.push({
347
- title: "Done",
348
- subTitle: initSubTitle,
349
- type: "img",
350
- duration: stillDuration,
351
- camera: fullPageCameraState
352
- });
353
- }
354
- return scripts;
355
- };
356
- export {
357
- allScriptsFromDump,
358
- cameraStateForRect,
359
- generateAnimationScripts,
360
- mergeTwoCameraState
361
- };
@@ -1,30 +0,0 @@
1
- import Buffer from "buffer";
2
- import processBrowser from "process/browser";
3
- import console from "console-browserify";
4
- var buffer = {
5
- Buffer
6
- };
7
- import { jsx } from "react/jsx-runtime";
8
- import "./shiny-text.css";
9
- const ShinyText = ({
10
- text,
11
- disabled = false,
12
- speed = 5,
13
- className = ""
14
- }) => {
15
- const style = {
16
- "--animation-duration": `${speed}s`
17
- };
18
- return /* @__PURE__ */ jsx(
19
- "div",
20
- {
21
- className: `shiny-text ${disabled ? "disabled" : ""} ${className}`,
22
- style,
23
- children: text
24
- }
25
- );
26
- };
27
- var shiny_text_default = ShinyText;
28
- export {
29
- shiny_text_default as default
30
- };
@@ -1,34 +0,0 @@
1
- import Buffer from "buffer";
2
- import processBrowser from "process/browser";
3
- import console from "console-browserify";
4
- var buffer = {
5
- Buffer
6
- };
7
- import * as Z from "zustand";
8
- const { create } = Z;
9
- const HISTORY_KEY = "midscene-prompt-history";
10
- const getHistoryFromLocalStorage = () => {
11
- const historyString = localStorage.getItem(HISTORY_KEY);
12
- return historyString ? JSON.parse(historyString) : [];
13
- };
14
- const useHistoryStore = create((set, get) => ({
15
- history: getHistoryFromLocalStorage(),
16
- clearHistory: () => {
17
- set({ history: [] });
18
- localStorage.removeItem(HISTORY_KEY);
19
- },
20
- addHistory: (historyItem) => {
21
- const newHistory = [
22
- historyItem,
23
- ...get().history.filter((h) => h.prompt !== historyItem.prompt)
24
- ];
25
- while (newHistory.length > 10) {
26
- newHistory.pop();
27
- }
28
- set({ history: newHistory });
29
- localStorage.setItem(HISTORY_KEY, JSON.stringify(newHistory));
30
- }
31
- }));
32
- export {
33
- useHistoryStore
34
- };