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
@@ -1693,7 +1693,7 @@ import yaml3 from "js-yaml";
|
|
1693
1693
|
import semver from "semver";
|
1694
1694
|
|
1695
1695
|
// package.json
|
1696
|
-
var version = "1.0.
|
1696
|
+
var version = "1.0.5";
|
1697
1697
|
|
1698
1698
|
// src/common/task-cache.ts
|
1699
1699
|
var debug3 = getDebug3("cache");
|
@@ -1875,10 +1875,13 @@ var PageAgent = class {
|
|
1875
1875
|
generateReport: true,
|
1876
1876
|
autoPrintReportMsg: true,
|
1877
1877
|
groupName: "Midscene Report",
|
1878
|
-
groupDescription: ""
|
1878
|
+
groupDescription: "",
|
1879
|
+
enableCumulativeContext: true,
|
1880
|
+
autoClearContext: false
|
1879
1881
|
},
|
1880
1882
|
opts || {}
|
1881
1883
|
);
|
1884
|
+
this.initializeContextStore();
|
1882
1885
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1883
1886
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1884
1887
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1905,6 +1908,69 @@ var PageAgent = class {
|
|
1905
1908
|
opts?.testId || this.page.pageType || "web"
|
1906
1909
|
);
|
1907
1910
|
}
|
1911
|
+
/**
|
1912
|
+
* Initialize context store for cumulative context functionality
|
1913
|
+
*/
|
1914
|
+
async initializeContextStore() {
|
1915
|
+
if (!this.opts.enableCumulativeContext) {
|
1916
|
+
debug4("Cumulative context disabled via options");
|
1917
|
+
return;
|
1918
|
+
}
|
1919
|
+
try {
|
1920
|
+
const aiModel = await import("misoai-core/ai-model");
|
1921
|
+
this.contextStore = aiModel.getContextStore();
|
1922
|
+
debug4("Context store initialized successfully", {
|
1923
|
+
autoClearContext: this.opts.autoClearContext,
|
1924
|
+
testId: this.opts.testId
|
1925
|
+
});
|
1926
|
+
if (this.opts.autoClearContext) {
|
1927
|
+
this.contextStore.clear();
|
1928
|
+
debug4("Context store cleared due to autoClearContext option");
|
1929
|
+
} else {
|
1930
|
+
const existingData = this.contextStore.getAllData();
|
1931
|
+
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1932
|
+
debug4("Context store preserving existing data", {
|
1933
|
+
existingDataKeys: Object.keys(existingData),
|
1934
|
+
existingStepsCount: existingSteps
|
1935
|
+
});
|
1936
|
+
}
|
1937
|
+
} catch (error) {
|
1938
|
+
debug4("Failed to initialize context store:", error);
|
1939
|
+
console.warn("⚠️ Could not initialize context store:", error);
|
1940
|
+
}
|
1941
|
+
}
|
1942
|
+
/**
|
1943
|
+
* Get the context store instance
|
1944
|
+
*/
|
1945
|
+
getContextStore() {
|
1946
|
+
return this.contextStore;
|
1947
|
+
}
|
1948
|
+
/**
|
1949
|
+
* Clear the context store
|
1950
|
+
*/
|
1951
|
+
clearContext() {
|
1952
|
+
if (this.contextStore) {
|
1953
|
+
this.contextStore.clear();
|
1954
|
+
}
|
1955
|
+
}
|
1956
|
+
/**
|
1957
|
+
* Get all stored data from context store
|
1958
|
+
*/
|
1959
|
+
getStoredData() {
|
1960
|
+
if (this.contextStore) {
|
1961
|
+
return this.contextStore.getAllData();
|
1962
|
+
}
|
1963
|
+
return {};
|
1964
|
+
}
|
1965
|
+
/**
|
1966
|
+
* Get step summary from context store
|
1967
|
+
*/
|
1968
|
+
getStepSummary() {
|
1969
|
+
if (this.contextStore) {
|
1970
|
+
return this.contextStore.getStepSummary();
|
1971
|
+
}
|
1972
|
+
return "";
|
1973
|
+
}
|
1908
1974
|
async getUIContext(action) {
|
1909
1975
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
1910
1976
|
return await parseContextFromWebPage(this.page, {
|
@@ -2140,18 +2206,30 @@ var PageAgent = class {
|
|
2140
2206
|
};
|
2141
2207
|
}
|
2142
2208
|
async aiAction(taskPrompt, opt) {
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2209
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2210
|
+
try {
|
2211
|
+
const originalPrompt = taskPrompt;
|
2212
|
+
const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
|
2213
|
+
if (originalPrompt !== processedPrompt) {
|
2214
|
+
debug4("Context replacement in aiAction:", {
|
2215
|
+
original: originalPrompt,
|
2216
|
+
processed: processedPrompt,
|
2217
|
+
storedData: this.contextStore.getAllData()
|
2218
|
+
});
|
2219
|
+
}
|
2220
|
+
this.contextStore.addStep({
|
2221
|
+
type: "action",
|
2222
|
+
summary: `Action: ${processedPrompt}`,
|
2223
|
+
prompt: processedPrompt
|
2224
|
+
});
|
2225
|
+
debug4("Added action step to context store:", {
|
2226
|
+
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2227
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2228
|
+
});
|
2229
|
+
taskPrompt = processedPrompt;
|
2230
|
+
} catch (error) {
|
2231
|
+
debug4("Context store operation failed:", error);
|
2232
|
+
}
|
2155
2233
|
}
|
2156
2234
|
const cacheable = opt?.cacheable;
|
2157
2235
|
const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
|
@@ -2222,38 +2300,50 @@ var PageAgent = class {
|
|
2222
2300
|
debug4("Context store not available:", error);
|
2223
2301
|
}
|
2224
2302
|
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2225
|
-
if (
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2303
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2304
|
+
if (storageKey && output) {
|
2305
|
+
try {
|
2306
|
+
const pendingAliases = this.contextStore._pendingAliases;
|
2307
|
+
if (pendingAliases) {
|
2308
|
+
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2309
|
+
delete this.contextStore._pendingAliases;
|
2310
|
+
debug4("Stored query result with aliases:", {
|
2311
|
+
key: storageKey,
|
2312
|
+
value: output,
|
2313
|
+
aliases: pendingAliases
|
2314
|
+
});
|
2315
|
+
} else {
|
2316
|
+
this.contextStore.storeData(storageKey, output);
|
2317
|
+
debug4("Stored query result:", {
|
2318
|
+
key: storageKey,
|
2319
|
+
value: output
|
2320
|
+
});
|
2321
|
+
}
|
2322
|
+
this.contextStore.addStep({
|
2323
|
+
type: "query",
|
2324
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2325
|
+
data: output,
|
2326
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2327
|
+
});
|
2328
|
+
debug4("Added query step to context store:", {
|
2329
|
+
storageKey,
|
2330
|
+
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2331
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2332
|
+
});
|
2333
|
+
} catch (error) {
|
2334
|
+
debug4("Failed to store query result:", error);
|
2335
|
+
}
|
2336
|
+
} else {
|
2337
|
+
try {
|
2338
|
+
this.contextStore.addStep({
|
2339
|
+
type: "query",
|
2340
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2341
|
+
data: output,
|
2342
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2343
|
+
});
|
2344
|
+
} catch (error) {
|
2345
|
+
debug4("Failed to add query step:", error);
|
2235
2346
|
}
|
2236
|
-
contextStore.addStep({
|
2237
|
-
type: "query",
|
2238
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2239
|
-
data: output,
|
2240
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2241
|
-
});
|
2242
|
-
} catch (error) {
|
2243
|
-
debug4("Failed to store query result:", error);
|
2244
|
-
}
|
2245
|
-
} else {
|
2246
|
-
try {
|
2247
|
-
const aiModel = await import("misoai-core/ai-model");
|
2248
|
-
const contextStore = aiModel.getContextStore();
|
2249
|
-
contextStore.addStep({
|
2250
|
-
type: "query",
|
2251
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2252
|
-
data: output,
|
2253
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2254
|
-
});
|
2255
|
-
} catch (error) {
|
2256
|
-
debug4("Failed to add query step:", error);
|
2257
2347
|
}
|
2258
2348
|
}
|
2259
2349
|
const metadata = this.afterTaskRunning(executor);
|
@@ -2366,17 +2456,29 @@ var PageAgent = class {
|
|
2366
2456
|
}
|
2367
2457
|
async aiAssert(assertion, msg, opt) {
|
2368
2458
|
let processedAssertion = assertion;
|
2369
|
-
|
2370
|
-
|
2371
|
-
|
2372
|
-
|
2373
|
-
|
2374
|
-
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2459
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2460
|
+
try {
|
2461
|
+
const originalAssertion = assertion;
|
2462
|
+
processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
|
2463
|
+
if (originalAssertion !== processedAssertion) {
|
2464
|
+
debug4("Context replacement in aiAssert:", {
|
2465
|
+
original: originalAssertion,
|
2466
|
+
processed: processedAssertion,
|
2467
|
+
context: "assertion",
|
2468
|
+
storedData: this.contextStore.getAllData()
|
2469
|
+
});
|
2470
|
+
}
|
2471
|
+
this.contextStore.addStep({
|
2472
|
+
type: "assertion",
|
2473
|
+
summary: `Assertion: ${processedAssertion}`,
|
2474
|
+
prompt: processedAssertion
|
2475
|
+
});
|
2476
|
+
debug4("Added assertion step to context store:", {
|
2477
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2478
|
+
});
|
2479
|
+
} catch (error) {
|
2480
|
+
debug4("Context store operation failed:", error);
|
2481
|
+
}
|
2380
2482
|
}
|
2381
2483
|
let currentUrl = "";
|
2382
2484
|
if (this.page.url) {
|