@midscene/core 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4966,6 +4966,7 @@ var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
4966
4966
  var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
4967
4967
  var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
4968
4968
  var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
4969
+ var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
4969
4970
  var OPENAI_API_KEY = "OPENAI_API_KEY";
4970
4971
  var OPENAI_BASE_URL = "OPENAI_BASE_URL";
4971
4972
  var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
@@ -4976,6 +4977,7 @@ var allConfigFromEnv = () => {
4976
4977
  return {
4977
4978
  [MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
4978
4979
  [MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
4980
+ [MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
4979
4981
  [MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
4980
4982
  [MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
4981
4983
  [MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
package/dist/lib/index.js CHANGED
@@ -5030,6 +5030,7 @@ var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
5030
5030
  var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
5031
5031
  var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
5032
5032
  var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
5033
+ var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
5033
5034
  var OPENAI_API_KEY = "OPENAI_API_KEY";
5034
5035
  var OPENAI_BASE_URL = "OPENAI_BASE_URL";
5035
5036
  var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
@@ -5040,6 +5041,7 @@ var allConfigFromEnv = () => {
5040
5041
  return {
5041
5042
  [MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
5042
5043
  [MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
5044
+ [MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
5043
5045
  [MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
5044
5046
  [MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
5045
5047
  [MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
@@ -5185,6 +5187,7 @@ function extractJSONFromCodeBlock(response) {
5185
5187
 
5186
5188
  // src/utils.ts
5187
5189
  var import_node_assert4 = __toESM(require("assert"));
5190
+ var import_node_child_process = require("child_process");
5188
5191
  var import_node_fs = require("fs");
5189
5192
  var import_node_os = require("os");
5190
5193
  var import_node_path = require("path");
@@ -5322,7 +5325,7 @@ function stringifyDumpData(data, indents) {
5322
5325
  return JSON.stringify(data, replacerForPageObject, indents);
5323
5326
  }
5324
5327
  function getVersion() {
5325
- return "0.8.2";
5328
+ return "0.8.3";
5326
5329
  }
5327
5330
 
5328
5331
  // src/action/executor.ts
@@ -1,4 +1,4 @@
1
- export { h as AiAssert, f as AiExtractElementInfo, A as AiInspectElement, c as callAiFn, d as callToGetJSONObject, e as describeUserPage, p as plan, t as transformElementPositionToId } from './index-691f031e.js';
1
+ export { h as AiAssert, f as AiExtractElementInfo, A as AiInspectElement, c as callAiFn, d as callToGetJSONObject, e as describeUserPage, p as plan, t as transformElementPositionToId } from './index-690c2a06.js';
2
2
  export { ChatCompletionMessageParam } from 'openai/resources';
3
3
  import './types-29994b1b.js';
4
4
 
@@ -20,6 +20,7 @@ declare function callAiFn<T>(options: {
20
20
  declare const allConfigFromEnv: () => {
21
21
  MIDSCENE_OPENAI_INIT_CONFIG_JSON: string | undefined;
22
22
  MIDSCENE_MODEL_NAME: string | undefined;
23
+ MIDSCENE_DEBUG_MODE: string | undefined;
23
24
  MIDSCENE_LANGSMITH_DEBUG: string | undefined;
24
25
  MIDSCENE_DEBUG_AI_PROFILE: string | undefined;
25
26
  MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG: string | undefined;
@@ -35,6 +36,7 @@ declare const getAIConfig: (configKey: keyof typeof userConfig) => string | unde
35
36
  declare const allAIConfig: () => {
36
37
  MIDSCENE_OPENAI_INIT_CONFIG_JSON: string | undefined;
37
38
  MIDSCENE_MODEL_NAME: string | undefined;
39
+ MIDSCENE_DEBUG_MODE: string | undefined;
38
40
  MIDSCENE_LANGSMITH_DEBUG: string | undefined;
39
41
  MIDSCENE_DEBUG_AI_PROFILE: string | undefined;
40
42
  MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG: string | undefined;
@@ -1,7 +1,7 @@
1
1
  import { E as ExecutionTask, a as ExecutionTaskApply, b as ExecutionDump, B as BaseElement, U as UIContext, D as DumpSubscriber, I as InsightOptions, c as InsightTaskInfo, A as AISingleElementResponse, d as InsightAssertionResponse } from './types-29994b1b.js';
2
2
  export { l as AIAssertionResponse, h as AIElementIdResponse, i as AIElementPositionResponse, j as AIElementResponse, e as AIResponseFormat, k as AISectionParseResponse, f as AISingleElementResponseById, g as AISingleElementResponseByPosition, w as AgentAssertOpt, v as AgentWaitForOpt, Q as BaseAgentParserOpt, o as BasicSectionQuery, C as CallAIFn, O as Color, q as DumpMeta, u as ElementById, n as EnsureObject, W as ExecutionRecorderItem, ac as ExecutionTaskAction, ab as ExecutionTaskActionApply, aa as ExecutionTaskInsightAssertion, a9 as ExecutionTaskInsightAssertionApply, a8 as ExecutionTaskInsightAssertionParam, a1 as ExecutionTaskInsightDumpLog, a3 as ExecutionTaskInsightLocate, a2 as ExecutionTaskInsightLocateApply, a0 as ExecutionTaskInsightLocateOutput, $ as ExecutionTaskInsightLocateParam, a7 as ExecutionTaskInsightQuery, a6 as ExecutionTaskInsightQueryApply, a5 as ExecutionTaskInsightQueryOutput, a4 as ExecutionTaskInsightQueryParam, ae as ExecutionTaskPlanning, ad as ExecutionTaskPlanningApply, _ as ExecutionTaskReturn, X as ExecutionTaskType, Y as ExecutorContext, af as GroupedActionDump, s as InsightDump, p as InsightExtractParam, L as LiteUISection, t as PartialInsightDumpFromSDK, y as PlanningAIResponse, x as PlanningAction, J as PlanningActionParamAssert, M as PlanningActionParamError, F as PlanningActionParamHover, G as PlanningActionParamInputOrKeyPress, H as PlanningActionParamScroll, K as PlanningActionParamSleep, z as PlanningActionParamTap, N as PlanningActionParamWaitFor, V as PlaywrightParserOpt, P as Point, T as PuppeteerParserOpt, R as Rect, r as ReportDumpWithAttributes, S as Size, Z as TaskCacheInfo, m as UISection } from './types-29994b1b.js';
3
- import { c as callAiFn, r as retrieveElement, a as retrieveSection } from './index-691f031e.js';
4
- export { b as allAIConfig, g as getAIConfig, o as overrideAIConfig, p as plan, t as transformElementPositionToId } from './index-691f031e.js';
3
+ import { c as callAiFn, r as retrieveElement, a as retrieveSection } from './index-690c2a06.js';
4
+ export { b as allAIConfig, g as getAIConfig, o as overrideAIConfig, p as plan, t as transformElementPositionToId } from './index-690c2a06.js';
5
5
  export { getVersion, setLogDir } from './utils.js';
6
6
  import 'openai/resources';
7
7
 
@@ -22,5 +22,8 @@ declare function sleep(ms: number): Promise<unknown>;
22
22
  declare function replacerForPageObject(key: string, value: any): any;
23
23
  declare function stringifyDumpData(data: any, indents?: number): string;
24
24
  declare function getVersion(): string;
25
+ declare function uploadTestInfoToServer({ testUrl, }: {
26
+ testUrl: string;
27
+ }): void;
25
28
 
26
- export { getLogDir, getLogDirByType, getTmpDir, getTmpFile, getVersion, groupedActionDumpFileExt, insightDumpFileExt, overlapped, replacerForPageObject, reportHTMLContent, setLogDir, sleep, stringifyDumpData, writeDumpReport, writeLogFile };
29
+ export { getLogDir, getLogDirByType, getTmpDir, getTmpFile, getVersion, groupedActionDumpFileExt, insightDumpFileExt, overlapped, replacerForPageObject, reportHTMLContent, setLogDir, sleep, stringifyDumpData, uploadTestInfoToServer, writeDumpReport, writeLogFile };
package/dist/lib/utils.js CHANGED
@@ -43,16 +43,75 @@ __export(utils_exports, {
43
43
  setLogDir: () => setLogDir,
44
44
  sleep: () => sleep,
45
45
  stringifyDumpData: () => stringifyDumpData,
46
+ uploadTestInfoToServer: () => uploadTestInfoToServer,
46
47
  writeDumpReport: () => writeDumpReport,
47
48
  writeLogFile: () => writeLogFile
48
49
  });
49
50
  module.exports = __toCommonJS(utils_exports);
50
- var import_node_assert = __toESM(require("assert"));
51
+ var import_node_assert4 = __toESM(require("assert"));
52
+ var import_node_child_process = require("child_process");
51
53
  var import_node_fs = require("fs");
52
54
  var import_node_os = require("os");
53
55
  var import_node_path = require("path");
54
56
  var import_fs = require("@midscene/shared/fs");
57
+ var import_utils2 = require("@midscene/shared/utils");
58
+
59
+ // src/ai-model/openai/index.ts
60
+ var import_node_assert3 = __toESM(require("assert"));
55
61
  var import_utils = require("@midscene/shared/utils");
62
+ var import_openai5 = __toESM(require("openai"));
63
+
64
+ // src/ai-model/coze/index.ts
65
+ var import_node_assert = __toESM(require("assert"));
66
+ var COZE_INSPECT_ELEMENT_BOT_ID = process.env.COZE_INSPECT_ELEMENT_BOT_ID || "";
67
+ var COZE_AI_ACTION_BOT_ID = process.env.COZE_AI_ACTION_BOT_ID || "";
68
+ var COZE_AI_ASSERT_BOT_ID = process.env.COZE_AI_ASSERT_BOT_ID || "";
69
+ var COZE_EXTRACT_INFO_BOT_ID = process.env.COZE_EXTRACT_INFO_BOT_ID || "";
70
+
71
+ // src/ai-model/prompt/util.ts
72
+ var import_node_assert2 = __toESM(require("assert"));
73
+
74
+ // src/image/index.ts
75
+ var import_img = require("@midscene/shared/img");
76
+
77
+ // src/ai-model/openai/index.ts
78
+ var MIDSCENE_OPENAI_INIT_CONFIG_JSON = "MIDSCENE_OPENAI_INIT_CONFIG_JSON";
79
+ var MIDSCENE_MODEL_NAME = "MIDSCENE_MODEL_NAME";
80
+ var MIDSCENE_LANGSMITH_DEBUG = "MIDSCENE_LANGSMITH_DEBUG";
81
+ var MIDSCENE_DEBUG_AI_PROFILE = "MIDSCENE_DEBUG_AI_PROFILE";
82
+ var MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG = "MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG";
83
+ var MIDSCENE_DEBUG_MODE = "MIDSCENE_DEBUG_MODE";
84
+ var OPENAI_API_KEY = "OPENAI_API_KEY";
85
+ var OPENAI_BASE_URL = "OPENAI_BASE_URL";
86
+ var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
87
+ var OPENAI_USE_AZURE = "OPENAI_USE_AZURE";
88
+ var MIDSCENE_CACHE = "MIDSCENE_CACHE";
89
+ var MATCH_BY_POSITION = "MATCH_BY_POSITION";
90
+ var allConfigFromEnv = () => {
91
+ return {
92
+ [MIDSCENE_OPENAI_INIT_CONFIG_JSON]: process.env[MIDSCENE_OPENAI_INIT_CONFIG_JSON] || void 0,
93
+ [MIDSCENE_MODEL_NAME]: process.env[MIDSCENE_MODEL_NAME] || void 0,
94
+ [MIDSCENE_DEBUG_MODE]: process.env[MIDSCENE_DEBUG_MODE] || void 0,
95
+ [MIDSCENE_LANGSMITH_DEBUG]: process.env[MIDSCENE_LANGSMITH_DEBUG] || void 0,
96
+ [MIDSCENE_DEBUG_AI_PROFILE]: process.env[MIDSCENE_DEBUG_AI_PROFILE] || void 0,
97
+ [MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG]: process.env[MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG] || void 0,
98
+ [OPENAI_API_KEY]: process.env[OPENAI_API_KEY] || void 0,
99
+ [OPENAI_BASE_URL]: process.env[OPENAI_BASE_URL] || void 0,
100
+ [MIDSCENE_MODEL_TEXT_ONLY]: process.env[MIDSCENE_MODEL_TEXT_ONLY] || void 0,
101
+ [OPENAI_USE_AZURE]: process.env[OPENAI_USE_AZURE] || void 0,
102
+ [MIDSCENE_CACHE]: process.env[MIDSCENE_CACHE] || void 0,
103
+ [MATCH_BY_POSITION]: process.env[MATCH_BY_POSITION] || void 0
104
+ };
105
+ };
106
+ var userConfig = {};
107
+ var getAIConfig = (configKey) => {
108
+ if (typeof userConfig[configKey] !== "undefined") {
109
+ return userConfig[configKey];
110
+ }
111
+ return allConfigFromEnv()[configKey];
112
+ };
113
+
114
+ // src/utils.ts
56
115
  var logDir = (0, import_node_path.join)(process.cwd(), "./midscene_run/");
57
116
  var logEnvReady = false;
58
117
  var insightDumpFileExt = "insight-dump.json";
@@ -72,11 +131,11 @@ function getLogDirByType(type) {
72
131
  }
73
132
  var reportTpl = null;
74
133
  function getReportTpl() {
75
- if (import_utils.ifInBrowser) {
134
+ if (import_utils2.ifInBrowser) {
76
135
  if (!reportTpl && window.midscene_report_tpl) {
77
136
  reportTpl = window.midscene_report_tpl;
78
137
  }
79
- (0, import_node_assert.default)(
138
+ (0, import_node_assert4.default)(
80
139
  reportTpl,
81
140
  "reportTpl should be set before writing report in browser"
82
141
  );
@@ -120,7 +179,7 @@ function reportHTMLContent(dumpData) {
120
179
  return reportContent;
121
180
  }
122
181
  function writeDumpReport(fileName, dumpData) {
123
- if (import_utils.ifInBrowser) {
182
+ if (import_utils2.ifInBrowser) {
124
183
  console.log("will not write report in browser");
125
184
  return null;
126
185
  }
@@ -135,13 +194,13 @@ function writeDumpReport(fileName, dumpData) {
135
194
  return reportPath;
136
195
  }
137
196
  function writeLogFile(opts) {
138
- if (import_utils.ifInBrowser) {
197
+ if (import_utils2.ifInBrowser) {
139
198
  return "/mock/report.html";
140
199
  }
141
200
  const { fileName, fileExt, fileContent, type = "dump" } = opts;
142
201
  const targetDir = getLogDirByType(type);
143
202
  if (!logEnvReady) {
144
- (0, import_node_assert.default)(targetDir, "logDir should be set before writing dump file");
203
+ (0, import_node_assert4.default)(targetDir, "logDir should be set before writing dump file");
145
204
  const gitIgnorePath = (0, import_node_path.join)(targetDir, "../../.gitignore");
146
205
  let gitIgnoreContent = "";
147
206
  if ((0, import_node_fs.existsSync)(gitIgnorePath)) {
@@ -173,7 +232,7 @@ ${logDirName}/dump
173
232
  return filePath;
174
233
  }
175
234
  function getTmpDir() {
176
- if (import_utils.ifInBrowser) {
235
+ if (import_utils2.ifInBrowser) {
177
236
  return null;
178
237
  }
179
238
  const runningPkgInfo = (0, import_fs.getRunningPkgInfo)();
@@ -186,11 +245,11 @@ function getTmpDir() {
186
245
  return path;
187
246
  }
188
247
  function getTmpFile(fileExtWithoutDot) {
189
- if (import_utils.ifInBrowser) {
248
+ if (import_utils2.ifInBrowser) {
190
249
  return null;
191
250
  }
192
251
  const tmpDir = getTmpDir();
193
- const filename = `${(0, import_utils.uuid)()}.${fileExtWithoutDot}`;
252
+ const filename = `${(0, import_utils2.uuid)()}.${fileExtWithoutDot}`;
194
253
  return (0, import_node_path.join)(tmpDir, filename);
195
254
  }
196
255
  function overlapped(container, target) {
@@ -213,7 +272,49 @@ function stringifyDumpData(data, indents) {
213
272
  return JSON.stringify(data, replacerForPageObject, indents);
214
273
  }
215
274
  function getVersion() {
216
- return "0.8.2";
275
+ return "0.8.3";
276
+ }
277
+ function debugLog(...message) {
278
+ const debugMode = getAIConfig(MIDSCENE_DEBUG_MODE);
279
+ if (debugMode) {
280
+ console.log("[Midscene]", ...message);
281
+ }
282
+ }
283
+ var lastReportedRepoUrl = "";
284
+ function uploadTestInfoToServer({
285
+ testUrl
286
+ }) {
287
+ let repoUrl = "";
288
+ const extraConfigString = getAIConfig(MIDSCENE_OPENAI_INIT_CONFIG_JSON);
289
+ const extraConfig = extraConfigString ? JSON.parse(extraConfigString) : {};
290
+ const serverUrl = extraConfig == null ? void 0 : extraConfig.REPORT_SERVER_URL;
291
+ try {
292
+ repoUrl = (0, import_node_child_process.execSync)("git config --get remote.origin.url").toString().trim();
293
+ } catch (error) {
294
+ debugLog("Failed to get git repo URL:", error);
295
+ }
296
+ if (serverUrl && (repoUrl && repoUrl !== lastReportedRepoUrl || !repoUrl && testUrl)) {
297
+ debugLog("Uploading test info to server", {
298
+ serverUrl,
299
+ repoUrl,
300
+ testUrl
301
+ });
302
+ fetch(serverUrl, {
303
+ method: "POST",
304
+ headers: {
305
+ "Content-Type": "application/json"
306
+ },
307
+ body: JSON.stringify({
308
+ repo_url: repoUrl,
309
+ test_url: testUrl
310
+ })
311
+ }).then((response) => response.json()).then((data) => {
312
+ debugLog("Successfully uploaded test info to server:", data);
313
+ }).catch(
314
+ (error) => debugLog("Failed to upload test info to server:", error)
315
+ );
316
+ lastReportedRepoUrl = repoUrl;
317
+ }
217
318
  }
218
319
  // Annotate the CommonJS export names for ESM import in node:
219
320
  0 && (module.exports = {
@@ -230,6 +331,7 @@ function getVersion() {
230
331
  setLogDir,
231
332
  sleep,
232
333
  stringifyDumpData,
334
+ uploadTestInfoToServer,
233
335
  writeDumpReport,
234
336
  writeLogFile
235
337
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midscene/core",
3
3
  "description": "An AI-powered automation SDK can control the page, perform assertions, and extract data in JSON format using natural language. See https://midscenejs.com/ for details.",
4
- "version": "0.8.2",
4
+ "version": "0.8.3",
5
5
  "repository": "https://github.com/web-infra-dev/midscene",
6
6
  "homepage": "https://midscenejs.com/",
7
7
  "jsnext:source": "./src/index.ts",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "openai": "4.57.1",
36
36
  "optional": "0.1.4",
37
- "@midscene/shared": "0.8.2"
37
+ "@midscene/shared": "0.8.3"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@modern-js/module-tools": "2.60.6",