misoai-web 1.0.5 → 1.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +9 -353
- package/bin/midscene-playground +2 -2
- package/dist/es/agent.js +9 -191
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +11 -193
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +10 -192
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +13 -195
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +9 -191
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/midscene-server.js.map +1 -1
- package/dist/es/playground.js +9 -191
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright-report.js.map +1 -1
- package/dist/es/playwright.js +10 -192
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +13 -195
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +13 -195
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/ui-utils.js.map +1 -1
- package/dist/es/utils.js.map +1 -1
- package/dist/es/yaml.js +5 -3
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +9 -191
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +11 -193
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +10 -192
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +13 -195
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +9 -191
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/midscene-server.js.map +1 -1
- package/dist/lib/playground.js +9 -191
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright-report.js.map +1 -1
- package/dist/lib/playwright.js +10 -192
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +13 -195
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +13 -195
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/ui-utils.js.map +1 -1
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/yaml.js +5 -3
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent.d.ts +1 -27
- package/dist/types/bridge-mode-browser.d.ts +2 -2
- package/dist/types/bridge-mode.d.ts +2 -2
- package/dist/types/{browser-a1877d18.d.ts → browser-aec1055d.d.ts} +1 -1
- package/dist/types/chrome-extension.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/midscene-server.d.ts +1 -1
- package/dist/types/{page-663ece08.d.ts → page-86ab0fe1.d.ts} +34 -34
- package/dist/types/playground.d.ts +2 -2
- package/dist/types/playwright.d.ts +1 -1
- package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
- package/dist/types/puppeteer.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/yaml.d.ts +1 -1
- package/iife-script/htmlElement.js +2 -2
- package/iife-script/htmlElementDebug.js +2 -2
- package/package.json +3 -3
package/dist/lib/index.js
CHANGED
@@ -60,10 +60,11 @@ var ScriptPlayer = class {
|
|
60
60
|
this.unnamedResultIndex = 0;
|
61
61
|
this.pageAgent = null;
|
62
62
|
this.result = {};
|
63
|
+
const target = script.target || script.web || script.android;
|
63
64
|
if (import_utils.ifInBrowser) {
|
64
65
|
this.output = void 0;
|
65
|
-
} else if (
|
66
|
-
this.output = (0, import_node_path.resolve)(process.cwd(),
|
66
|
+
} else if (target?.output) {
|
67
|
+
this.output = (0, import_node_path.resolve)(process.cwd(), target.output);
|
67
68
|
} else {
|
68
69
|
this.output = (0, import_node_path.join)((0, import_common.getMidsceneRunSubDir)("output"), `${process.pid}.json`);
|
69
70
|
}
|
@@ -137,12 +138,13 @@ var ScriptPlayer = class {
|
|
137
138
|
} else if ("aiAssert" in flowItem) {
|
138
139
|
const assertTask = flowItem;
|
139
140
|
const prompt = assertTask.aiAssert;
|
141
|
+
const msg = assertTask.errorMessage;
|
140
142
|
(0, import_utils.assert)(prompt, "missing prompt for aiAssert");
|
141
143
|
(0, import_utils.assert)(
|
142
144
|
typeof prompt === "string",
|
143
145
|
"prompt for aiAssert must be a string"
|
144
146
|
);
|
145
|
-
await agent.aiAssert(prompt);
|
147
|
+
await agent.aiAssert(prompt, msg);
|
146
148
|
} else if ("aiQuery" in flowItem) {
|
147
149
|
const queryTask = flowItem;
|
148
150
|
const prompt = queryTask.aiQuery;
|
@@ -1711,7 +1713,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1711
1713
|
var import_semver = __toESM(require("semver"));
|
1712
1714
|
|
1713
1715
|
// package.json
|
1714
|
-
var version = "1.
|
1716
|
+
var version = "1.5.6";
|
1715
1717
|
|
1716
1718
|
// src/common/task-cache.ts
|
1717
1719
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1893,13 +1895,10 @@ var PageAgent = class {
|
|
1893
1895
|
generateReport: true,
|
1894
1896
|
autoPrintReportMsg: true,
|
1895
1897
|
groupName: "Midscene Report",
|
1896
|
-
groupDescription: ""
|
1897
|
-
enableCumulativeContext: true,
|
1898
|
-
autoClearContext: false
|
1898
|
+
groupDescription: ""
|
1899
1899
|
},
|
1900
1900
|
opts || {}
|
1901
1901
|
);
|
1902
|
-
this.initializeContextStore();
|
1903
1902
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1904
1903
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || import_constants2.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1905
1904
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || import_constants2.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1926,69 +1925,6 @@ var PageAgent = class {
|
|
1926
1925
|
opts?.testId || this.page.pageType || "web"
|
1927
1926
|
);
|
1928
1927
|
}
|
1929
|
-
/**
|
1930
|
-
* Initialize context store for cumulative context functionality
|
1931
|
-
*/
|
1932
|
-
async initializeContextStore() {
|
1933
|
-
if (!this.opts.enableCumulativeContext) {
|
1934
|
-
debug4("Cumulative context disabled via options");
|
1935
|
-
return;
|
1936
|
-
}
|
1937
|
-
try {
|
1938
|
-
const aiModel = await import("misoai-core/ai-model");
|
1939
|
-
this.contextStore = aiModel.getContextStore();
|
1940
|
-
debug4("Context store initialized successfully", {
|
1941
|
-
autoClearContext: this.opts.autoClearContext,
|
1942
|
-
testId: this.opts.testId
|
1943
|
-
});
|
1944
|
-
if (this.opts.autoClearContext) {
|
1945
|
-
this.contextStore.clear();
|
1946
|
-
debug4("Context store cleared due to autoClearContext option");
|
1947
|
-
} else {
|
1948
|
-
const existingData = this.contextStore.getAllData();
|
1949
|
-
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1950
|
-
debug4("Context store preserving existing data", {
|
1951
|
-
existingDataKeys: Object.keys(existingData),
|
1952
|
-
existingStepsCount: existingSteps
|
1953
|
-
});
|
1954
|
-
}
|
1955
|
-
} catch (error) {
|
1956
|
-
debug4("Failed to initialize context store:", error);
|
1957
|
-
console.warn("⚠️ Could not initialize context store:", error);
|
1958
|
-
}
|
1959
|
-
}
|
1960
|
-
/**
|
1961
|
-
* Get the context store instance
|
1962
|
-
*/
|
1963
|
-
getContextStore() {
|
1964
|
-
return this.contextStore;
|
1965
|
-
}
|
1966
|
-
/**
|
1967
|
-
* Clear the context store
|
1968
|
-
*/
|
1969
|
-
clearContext() {
|
1970
|
-
if (this.contextStore) {
|
1971
|
-
this.contextStore.clear();
|
1972
|
-
}
|
1973
|
-
}
|
1974
|
-
/**
|
1975
|
-
* Get all stored data from context store
|
1976
|
-
*/
|
1977
|
-
getStoredData() {
|
1978
|
-
if (this.contextStore) {
|
1979
|
-
return this.contextStore.getAllData();
|
1980
|
-
}
|
1981
|
-
return {};
|
1982
|
-
}
|
1983
|
-
/**
|
1984
|
-
* Get step summary from context store
|
1985
|
-
*/
|
1986
|
-
getStepSummary() {
|
1987
|
-
if (this.contextStore) {
|
1988
|
-
return this.contextStore.getStepSummary();
|
1989
|
-
}
|
1990
|
-
return "";
|
1991
|
-
}
|
1992
1928
|
async getUIContext(action) {
|
1993
1929
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
1994
1930
|
return await parseContextFromWebPage(this.page, {
|
@@ -2224,31 +2160,6 @@ var PageAgent = class {
|
|
2224
2160
|
};
|
2225
2161
|
}
|
2226
2162
|
async aiAction(taskPrompt, opt) {
|
2227
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2228
|
-
try {
|
2229
|
-
const originalPrompt = taskPrompt;
|
2230
|
-
const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
|
2231
|
-
if (originalPrompt !== processedPrompt) {
|
2232
|
-
debug4("Context replacement in aiAction:", {
|
2233
|
-
original: originalPrompt,
|
2234
|
-
processed: processedPrompt,
|
2235
|
-
storedData: this.contextStore.getAllData()
|
2236
|
-
});
|
2237
|
-
}
|
2238
|
-
this.contextStore.addStep({
|
2239
|
-
type: "action",
|
2240
|
-
summary: `Action: ${processedPrompt}`,
|
2241
|
-
prompt: processedPrompt
|
2242
|
-
});
|
2243
|
-
debug4("Added action step to context store:", {
|
2244
|
-
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2245
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2246
|
-
});
|
2247
|
-
taskPrompt = processedPrompt;
|
2248
|
-
} catch (error) {
|
2249
|
-
debug4("Context store operation failed:", error);
|
2250
|
-
}
|
2251
|
-
}
|
2252
2163
|
const cacheable = opt?.cacheable;
|
2253
2164
|
const isVlmUiTars = (0, import_env2.vlLocateMode)() === "vlm-ui-tars";
|
2254
2165
|
const matchedCache = isVlmUiTars || cacheable === false ? void 0 : this.taskCache?.matchPlanCache(taskPrompt);
|
@@ -2295,75 +2206,7 @@ var PageAgent = class {
|
|
2295
2206
|
};
|
2296
2207
|
}
|
2297
2208
|
async aiQuery(demand) {
|
2298
|
-
|
2299
|
-
let storageKey;
|
2300
|
-
try {
|
2301
|
-
const aiModel = await import("misoai-core/ai-model");
|
2302
|
-
const contextStore = aiModel.getContextStore();
|
2303
|
-
if (typeof demand === "string") {
|
2304
|
-
const storageInstruction = contextStore.parseStorageInstruction(demand);
|
2305
|
-
if (storageInstruction) {
|
2306
|
-
storageKey = storageInstruction.key;
|
2307
|
-
processedDemand = storageInstruction.cleanText;
|
2308
|
-
contextStore._pendingAliases = storageInstruction.aliases;
|
2309
|
-
} else {
|
2310
|
-
const storageMatch = demand.match(/store\s+(?:as\s+)?(\w+)/i);
|
2311
|
-
if (storageMatch) {
|
2312
|
-
storageKey = storageMatch[1];
|
2313
|
-
processedDemand = demand.replace(/,?\s*store\s+(?:as\s+)?\w+/i, "").trim();
|
2314
|
-
}
|
2315
|
-
}
|
2316
|
-
}
|
2317
|
-
} catch (error) {
|
2318
|
-
debug4("Context store not available:", error);
|
2319
|
-
}
|
2320
|
-
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2321
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2322
|
-
if (storageKey && output) {
|
2323
|
-
try {
|
2324
|
-
const pendingAliases = this.contextStore._pendingAliases;
|
2325
|
-
if (pendingAliases) {
|
2326
|
-
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2327
|
-
delete this.contextStore._pendingAliases;
|
2328
|
-
debug4("Stored query result with aliases:", {
|
2329
|
-
key: storageKey,
|
2330
|
-
value: output,
|
2331
|
-
aliases: pendingAliases
|
2332
|
-
});
|
2333
|
-
} else {
|
2334
|
-
this.contextStore.storeData(storageKey, output);
|
2335
|
-
debug4("Stored query result:", {
|
2336
|
-
key: storageKey,
|
2337
|
-
value: output
|
2338
|
-
});
|
2339
|
-
}
|
2340
|
-
this.contextStore.addStep({
|
2341
|
-
type: "query",
|
2342
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2343
|
-
data: output,
|
2344
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2345
|
-
});
|
2346
|
-
debug4("Added query step to context store:", {
|
2347
|
-
storageKey,
|
2348
|
-
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2349
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2350
|
-
});
|
2351
|
-
} catch (error) {
|
2352
|
-
debug4("Failed to store query result:", error);
|
2353
|
-
}
|
2354
|
-
} else {
|
2355
|
-
try {
|
2356
|
-
this.contextStore.addStep({
|
2357
|
-
type: "query",
|
2358
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2359
|
-
data: output,
|
2360
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2361
|
-
});
|
2362
|
-
} catch (error) {
|
2363
|
-
debug4("Failed to add query step:", error);
|
2364
|
-
}
|
2365
|
-
}
|
2366
|
-
}
|
2209
|
+
const { output, executor } = await this.taskExecutor.query(demand);
|
2367
2210
|
const metadata = this.afterTaskRunning(executor);
|
2368
2211
|
return {
|
2369
2212
|
result: output,
|
@@ -2473,31 +2316,6 @@ var PageAgent = class {
|
|
2473
2316
|
};
|
2474
2317
|
}
|
2475
2318
|
async aiAssert(assertion, msg, opt) {
|
2476
|
-
let processedAssertion = assertion;
|
2477
|
-
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2478
|
-
try {
|
2479
|
-
const originalAssertion = assertion;
|
2480
|
-
processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
|
2481
|
-
if (originalAssertion !== processedAssertion) {
|
2482
|
-
debug4("Context replacement in aiAssert:", {
|
2483
|
-
original: originalAssertion,
|
2484
|
-
processed: processedAssertion,
|
2485
|
-
context: "assertion",
|
2486
|
-
storedData: this.contextStore.getAllData()
|
2487
|
-
});
|
2488
|
-
}
|
2489
|
-
this.contextStore.addStep({
|
2490
|
-
type: "assertion",
|
2491
|
-
summary: `Assertion: ${processedAssertion}`,
|
2492
|
-
prompt: processedAssertion
|
2493
|
-
});
|
2494
|
-
debug4("Added assertion step to context store:", {
|
2495
|
-
totalSteps: this.contextStore.getRecentSteps(100).length
|
2496
|
-
});
|
2497
|
-
} catch (error) {
|
2498
|
-
debug4("Context store operation failed:", error);
|
2499
|
-
}
|
2500
|
-
}
|
2501
2319
|
let currentUrl = "";
|
2502
2320
|
if (this.page.url) {
|
2503
2321
|
try {
|
@@ -2505,7 +2323,7 @@ var PageAgent = class {
|
|
2505
2323
|
} catch (e) {
|
2506
2324
|
}
|
2507
2325
|
}
|
2508
|
-
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${
|
2326
|
+
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2509
2327
|
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2510
2328
|
const metadata = this.afterTaskRunning(executor, true);
|
2511
2329
|
if (output && opt?.keepRawResponse) {
|
@@ -2734,7 +2552,7 @@ var Page = class {
|
|
2734
2552
|
this.everMoved = false;
|
2735
2553
|
this.underlyingPage = underlyingPage;
|
2736
2554
|
this.pageType = pageType;
|
2737
|
-
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout
|
2555
|
+
this.waitForNavigationTimeout = opts?.waitForNavigationTimeout ?? import_constants3.DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
2738
2556
|
}
|
2739
2557
|
async evaluate(pageFunction, arg) {
|
2740
2558
|
let result;
|
@@ -3265,9 +3083,9 @@ var WebPage2 = class extends Page {
|
|
3265
3083
|
}
|
3266
3084
|
async waitUntilNetworkIdle(options) {
|
3267
3085
|
await this.underlyingPage.waitForNetworkIdle({
|
3268
|
-
idleTime: options?.idleTime
|
3269
|
-
concurrency: options?.concurrency
|
3270
|
-
timeout: options?.timeout
|
3086
|
+
idleTime: options?.idleTime ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_TIME,
|
3087
|
+
concurrency: options?.concurrency ?? import_constants4.DEFAULT_WAIT_FOR_NETWORK_IDLE_CONCURRENCY,
|
3088
|
+
timeout: options?.timeout ?? this.waitForNetworkIdleTimeout
|
3271
3089
|
});
|
3272
3090
|
}
|
3273
3091
|
};
|