misoai-web 1.0.4 → 1.0.5
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/README.md +349 -5
- package/dist/es/agent.js +158 -56
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode.js +160 -58
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +159 -57
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +158 -56
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +158 -56
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +158 -56
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +158 -56
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +158 -56
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +158 -56
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/lib/agent.js +158 -56
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode.js +160 -58
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +159 -57
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +158 -56
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +158 -56
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +158 -56
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +158 -56
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +158 -56
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +158 -56
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/types/agent.d.ts +26 -0
- package/package.json +1 -1
package/dist/es/playground.js
CHANGED
@@ -1661,7 +1661,7 @@ import yaml3 from "js-yaml";
|
|
1661
1661
|
import semver from "semver";
|
1662
1662
|
|
1663
1663
|
// package.json
|
1664
|
-
var version = "1.0.
|
1664
|
+
var version = "1.0.5";
|
1665
1665
|
|
1666
1666
|
// src/common/task-cache.ts
|
1667
1667
|
var debug3 = getDebug3("cache");
|
@@ -1843,10 +1843,13 @@ var PageAgent = class {
|
|
1843
1843
|
generateReport: true,
|
1844
1844
|
autoPrintReportMsg: true,
|
1845
1845
|
groupName: "Midscene Report",
|
1846
|
-
groupDescription: ""
|
1846
|
+
groupDescription: "",
|
1847
|
+
enableCumulativeContext: true,
|
1848
|
+
autoClearContext: false
|
1847
1849
|
},
|
1848
1850
|
opts || {}
|
1849
1851
|
);
|
1852
|
+
this.initializeContextStore();
|
1850
1853
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1851
1854
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1852
1855
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1873,6 +1876,69 @@ var PageAgent = class {
|
|
1873
1876
|
opts?.testId || this.page.pageType || "web"
|
1874
1877
|
);
|
1875
1878
|
}
|
1879
|
+
/**
|
1880
|
+
* Initialize context store for cumulative context functionality
|
1881
|
+
*/
|
1882
|
+
async initializeContextStore() {
|
1883
|
+
if (!this.opts.enableCumulativeContext) {
|
1884
|
+
debug4("Cumulative context disabled via options");
|
1885
|
+
return;
|
1886
|
+
}
|
1887
|
+
try {
|
1888
|
+
const aiModel = await import("misoai-core/ai-model");
|
1889
|
+
this.contextStore = aiModel.getContextStore();
|
1890
|
+
debug4("Context store initialized successfully", {
|
1891
|
+
autoClearContext: this.opts.autoClearContext,
|
1892
|
+
testId: this.opts.testId
|
1893
|
+
});
|
1894
|
+
if (this.opts.autoClearContext) {
|
1895
|
+
this.contextStore.clear();
|
1896
|
+
debug4("Context store cleared due to autoClearContext option");
|
1897
|
+
} else {
|
1898
|
+
const existingData = this.contextStore.getAllData();
|
1899
|
+
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1900
|
+
debug4("Context store preserving existing data", {
|
1901
|
+
existingDataKeys: Object.keys(existingData),
|
1902
|
+
existingStepsCount: existingSteps
|
1903
|
+
});
|
1904
|
+
}
|
1905
|
+
} catch (error) {
|
1906
|
+
debug4("Failed to initialize context store:", error);
|
1907
|
+
console.warn("⚠️ Could not initialize context store:", error);
|
1908
|
+
}
|
1909
|
+
}
|
1910
|
+
/**
|
1911
|
+
* Get the context store instance
|
1912
|
+
*/
|
1913
|
+
getContextStore() {
|
1914
|
+
return this.contextStore;
|
1915
|
+
}
|
1916
|
+
/**
|
1917
|
+
* Clear the context store
|
1918
|
+
*/
|
1919
|
+
clearContext() {
|
1920
|
+
if (this.contextStore) {
|
1921
|
+
this.contextStore.clear();
|
1922
|
+
}
|
1923
|
+
}
|
1924
|
+
/**
|
1925
|
+
* Get all stored data from context store
|
1926
|
+
*/
|
1927
|
+
getStoredData() {
|
1928
|
+
if (this.contextStore) {
|
1929
|
+
return this.contextStore.getAllData();
|
1930
|
+
}
|
1931
|
+
return {};
|
1932
|
+
}
|
1933
|
+
/**
|
1934
|
+
* Get step summary from context store
|
1935
|
+
*/
|
1936
|
+
getStepSummary() {
|
1937
|
+
if (this.contextStore) {
|
1938
|
+
return this.contextStore.getStepSummary();
|
1939
|
+
}
|
1940
|
+
return "";
|
1941
|
+
}
|
1876
1942
|
async getUIContext(action) {
|
1877
1943
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
1878
1944
|
return await parseContextFromWebPage(this.page, {
|
@@ -2108,18 +2174,30 @@ var PageAgent = class {
|
|
2108
2174
|
};
|
2109
2175
|
}
|
2110
2176
|
async aiAction(taskPrompt, opt) {
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2177
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2178
|
+
try {
|
2179
|
+
const originalPrompt = taskPrompt;
|
2180
|
+
const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
|
2181
|
+
if (originalPrompt !== processedPrompt) {
|
2182
|
+
debug4("Context replacement in aiAction:", {
|
2183
|
+
original: originalPrompt,
|
2184
|
+
processed: processedPrompt,
|
2185
|
+
storedData: this.contextStore.getAllData()
|
2186
|
+
});
|
2187
|
+
}
|
2188
|
+
this.contextStore.addStep({
|
2189
|
+
type: "action",
|
2190
|
+
summary: `Action: ${processedPrompt}`,
|
2191
|
+
prompt: processedPrompt
|
2192
|
+
});
|
2193
|
+
debug4("Added action step to context store:", {
|
2194
|
+
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2195
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2196
|
+
});
|
2197
|
+
taskPrompt = processedPrompt;
|
2198
|
+
} catch (error) {
|
2199
|
+
debug4("Context store operation failed:", error);
|
2200
|
+
}
|
2123
2201
|
}
|
2124
2202
|
const cacheable = opt?.cacheable;
|
2125
2203
|
const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
|
@@ -2190,38 +2268,50 @@ var PageAgent = class {
|
|
2190
2268
|
debug4("Context store not available:", error);
|
2191
2269
|
}
|
2192
2270
|
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2193
|
-
if (
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2271
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2272
|
+
if (storageKey && output) {
|
2273
|
+
try {
|
2274
|
+
const pendingAliases = this.contextStore._pendingAliases;
|
2275
|
+
if (pendingAliases) {
|
2276
|
+
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2277
|
+
delete this.contextStore._pendingAliases;
|
2278
|
+
debug4("Stored query result with aliases:", {
|
2279
|
+
key: storageKey,
|
2280
|
+
value: output,
|
2281
|
+
aliases: pendingAliases
|
2282
|
+
});
|
2283
|
+
} else {
|
2284
|
+
this.contextStore.storeData(storageKey, output);
|
2285
|
+
debug4("Stored query result:", {
|
2286
|
+
key: storageKey,
|
2287
|
+
value: output
|
2288
|
+
});
|
2289
|
+
}
|
2290
|
+
this.contextStore.addStep({
|
2291
|
+
type: "query",
|
2292
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2293
|
+
data: output,
|
2294
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2295
|
+
});
|
2296
|
+
debug4("Added query step to context store:", {
|
2297
|
+
storageKey,
|
2298
|
+
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2299
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2300
|
+
});
|
2301
|
+
} catch (error) {
|
2302
|
+
debug4("Failed to store query result:", error);
|
2303
|
+
}
|
2304
|
+
} else {
|
2305
|
+
try {
|
2306
|
+
this.contextStore.addStep({
|
2307
|
+
type: "query",
|
2308
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2309
|
+
data: output,
|
2310
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2311
|
+
});
|
2312
|
+
} catch (error) {
|
2313
|
+
debug4("Failed to add query step:", error);
|
2203
2314
|
}
|
2204
|
-
contextStore.addStep({
|
2205
|
-
type: "query",
|
2206
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2207
|
-
data: output,
|
2208
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2209
|
-
});
|
2210
|
-
} catch (error) {
|
2211
|
-
debug4("Failed to store query result:", error);
|
2212
|
-
}
|
2213
|
-
} else {
|
2214
|
-
try {
|
2215
|
-
const aiModel = await import("misoai-core/ai-model");
|
2216
|
-
const contextStore = aiModel.getContextStore();
|
2217
|
-
contextStore.addStep({
|
2218
|
-
type: "query",
|
2219
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2220
|
-
data: output,
|
2221
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2222
|
-
});
|
2223
|
-
} catch (error) {
|
2224
|
-
debug4("Failed to add query step:", error);
|
2225
2315
|
}
|
2226
2316
|
}
|
2227
2317
|
const metadata = this.afterTaskRunning(executor);
|
@@ -2334,17 +2424,29 @@ var PageAgent = class {
|
|
2334
2424
|
}
|
2335
2425
|
async aiAssert(assertion, msg, opt) {
|
2336
2426
|
let processedAssertion = assertion;
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2347
|
-
|
2427
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2428
|
+
try {
|
2429
|
+
const originalAssertion = assertion;
|
2430
|
+
processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
|
2431
|
+
if (originalAssertion !== processedAssertion) {
|
2432
|
+
debug4("Context replacement in aiAssert:", {
|
2433
|
+
original: originalAssertion,
|
2434
|
+
processed: processedAssertion,
|
2435
|
+
context: "assertion",
|
2436
|
+
storedData: this.contextStore.getAllData()
|
2437
|
+
});
|
2438
|
+
}
|
2439
|
+
this.contextStore.addStep({
|
2440
|
+
type: "assertion",
|
2441
|
+
summary: `Assertion: ${processedAssertion}`,
|
2442
|
+
prompt: processedAssertion
|
2443
|
+
});
|
2444
|
+
debug4("Added assertion step to context store:", {
|
2445
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2446
|
+
});
|
2447
|
+
} catch (error) {
|
2448
|
+
debug4("Context store operation failed:", error);
|
2449
|
+
}
|
2348
2450
|
}
|
2349
2451
|
let currentUrl = "";
|
2350
2452
|
if (this.page.url) {
|