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/README.md
CHANGED
@@ -1,9 +1,353 @@
|
|
1
|
-
|
1
|
+
# @midscene/web - AI-Powered Web Automation
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/js/@midscene%2Fweb)
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
4
5
|
|
5
|
-
|
6
|
+
AI-powered web automation library with advanced cumulative context system for intelligent, multi-step browser interactions.
|
6
7
|
|
7
|
-
##
|
8
|
+
## 🚀 Features
|
8
9
|
|
9
|
-
|
10
|
+
- **🧠 Cumulative Context System**: AI remembers previous actions and data across steps
|
11
|
+
- **🗣️ Natural Language Data References**: No more `{stored.key}` syntax needed
|
12
|
+
- **🎯 Smart Context-Aware Assertions**: Intelligent data replacement in assertions
|
13
|
+
- **🔄 Multi-Step Workflows**: Seamless information flow between actions
|
14
|
+
- **🛡️ Built-in CAPTCHA Solving**: Advanced AI-powered CAPTCHA detection and solving
|
15
|
+
- **📊 Comprehensive Logging**: Full visibility into context operations and AI calls
|
16
|
+
- **🎭 Framework Support**: Works with Puppeteer, Playwright, and more
|
17
|
+
|
18
|
+
## 📦 Installation
|
19
|
+
|
20
|
+
```bash
|
21
|
+
npm install @midscene/web puppeteer
|
22
|
+
# or
|
23
|
+
yarn add @midscene/web puppeteer
|
24
|
+
```
|
25
|
+
|
26
|
+
## 🎯 Quick Start
|
27
|
+
|
28
|
+
### Basic Usage with Cumulative Context
|
29
|
+
|
30
|
+
```javascript
|
31
|
+
import { PuppeteerAgent } from '@midscene/web';
|
32
|
+
import puppeteer from 'puppeteer';
|
33
|
+
|
34
|
+
const browser = await puppeteer.launch({ headless: false });
|
35
|
+
const page = await browser.newPage();
|
36
|
+
|
37
|
+
// Create agent with cumulative context enabled
|
38
|
+
const agent = new PuppeteerAgent(page, {
|
39
|
+
enableCumulativeContext: true, // 🔥 Enable context system
|
40
|
+
autoClearContext: true, // 🧹 Start with clean context
|
41
|
+
testId: 'my-automation'
|
42
|
+
});
|
43
|
+
|
44
|
+
await page.goto('https://example.com');
|
45
|
+
|
46
|
+
// Step 1: Store data with natural language
|
47
|
+
await agent.aiQuery('kullanıcı adını "john_doe" olarak username şeklinde kaydet');
|
48
|
+
|
49
|
+
// Step 2: Use stored data without {stored.key} syntax!
|
50
|
+
await agent.aiAction('arama kutusuna username verisini yaz');
|
51
|
+
|
52
|
+
// Step 3: Context-aware assertion
|
53
|
+
await agent.aiAssert('arama kutusunda username değeri görünüyor');
|
54
|
+
|
55
|
+
await browser.close();
|
56
|
+
```
|
57
|
+
|
58
|
+
## 🧠 Cumulative Context System
|
59
|
+
|
60
|
+
### Natural Language Data Storage
|
61
|
+
|
62
|
+
```javascript
|
63
|
+
// Turkish natural language storage
|
64
|
+
await agent.aiQuery('ürün adını "iPhone 15" olarak urun_adi şeklinde kaydet');
|
65
|
+
await agent.aiQuery('fiyatı "999$" olarak fiyat şeklinde kaydet');
|
66
|
+
|
67
|
+
// English natural language storage
|
68
|
+
await agent.aiQuery('extract username and store as user_name');
|
69
|
+
await agent.aiQuery('get email address, store as email');
|
70
|
+
```
|
71
|
+
|
72
|
+
### Automatic Data Usage
|
73
|
+
|
74
|
+
```javascript
|
75
|
+
// No need for {stored.key} syntax!
|
76
|
+
await agent.aiAction('formu urun_adi ve fiyat ile doldur');
|
77
|
+
await agent.aiAction('use user_name and email to fill the form');
|
78
|
+
|
79
|
+
// Multiple data references in one action
|
80
|
+
await agent.aiAction('sepete urun_adi ürününü fiyat fiyatıyla ekle');
|
81
|
+
```
|
82
|
+
|
83
|
+
### Context-Aware Assertions
|
84
|
+
|
85
|
+
```javascript
|
86
|
+
// Smart replacement - AI decides when to replace
|
87
|
+
await agent.aiAssert('sepette urun_adi ürünü görünüyor'); // ✅ Will replace
|
88
|
+
await agent.aiAssert('sayfada iPhone yazısı var'); // ❓ Context-dependent
|
89
|
+
```
|
90
|
+
|
91
|
+
## 🛡️ AI CAPTCHA Solving
|
92
|
+
|
93
|
+
The `aiCaptcha` method provides intelligent CAPTCHA detection and solving capabilities with automatic execution:
|
94
|
+
|
95
|
+
```javascript
|
96
|
+
// Basic CAPTCHA solving (auto-detects complexity)
|
97
|
+
await agent.aiCaptcha();
|
98
|
+
|
99
|
+
// Advanced CAPTCHA solving with options
|
100
|
+
await agent.aiCaptcha({
|
101
|
+
deepThink: true, // Force deep analysis
|
102
|
+
autoDetectComplexity: true // Auto-detect if deep thinking needed (default: true)
|
103
|
+
});
|
104
|
+
```
|
105
|
+
|
106
|
+
### CAPTCHA Features
|
107
|
+
|
108
|
+
- **🔍 Automatic Detection**: Identifies CAPTCHA type (text, image, unknown)
|
109
|
+
- **🧠 Complexity Analysis**: Auto-detects if deep thinking is needed
|
110
|
+
- **📝 Text CAPTCHAs**: Solves distorted text and automatically inputs solution
|
111
|
+
- **🖼️ Image CAPTCHAs**: Handles "select all images with..." challenges with coordinate clicking
|
112
|
+
- **🎯 Automatic Execution**: Performs all required actions (click, input, verify) automatically
|
113
|
+
- **⚡ Smart Processing**: Uses appropriate AI model based on complexity
|
114
|
+
- **🔄 Action Sequence**: Executes complete CAPTCHA solving workflow
|
115
|
+
|
116
|
+
### CAPTCHA Response Format
|
117
|
+
|
118
|
+
The AI returns a structured response with:
|
119
|
+
|
120
|
+
```javascript
|
121
|
+
{
|
122
|
+
captchaType: "text" | "image" | "unknown",
|
123
|
+
solution: "The solution text or description",
|
124
|
+
thought: "AI reasoning process",
|
125
|
+
actions: [
|
126
|
+
{
|
127
|
+
type: "click" | "input" | "verify",
|
128
|
+
target: "Description of target element",
|
129
|
+
value: "Text to input (for input actions)",
|
130
|
+
coordinates: [x, y] // For precise clicking
|
131
|
+
}
|
132
|
+
]
|
133
|
+
}
|
134
|
+
```
|
135
|
+
|
136
|
+
### CAPTCHA Example
|
137
|
+
|
138
|
+
```javascript
|
139
|
+
// Navigate to page with CAPTCHA
|
140
|
+
await page.goto('https://example.com/login');
|
141
|
+
|
142
|
+
// Fill login form
|
143
|
+
await agent.aiInput('john@example.com', 'email field');
|
144
|
+
await agent.aiInput('password123', 'password field');
|
145
|
+
|
146
|
+
// Solve CAPTCHA automatically - AI will:
|
147
|
+
// 1. Analyze the CAPTCHA type and complexity
|
148
|
+
// 2. Generate solution
|
149
|
+
// 3. Execute all required actions automatically
|
150
|
+
const captchaResult = await agent.aiCaptcha({
|
151
|
+
autoDetectComplexity: true
|
152
|
+
});
|
153
|
+
|
154
|
+
console.log('CAPTCHA solved:', captchaResult.result.captchaType);
|
155
|
+
console.log('Solution:', captchaResult.result.solution);
|
156
|
+
console.log('Actions performed:', captchaResult.result.actions.length);
|
157
|
+
|
158
|
+
// Form is now ready to submit
|
159
|
+
await agent.aiTap('login button');
|
160
|
+
```
|
161
|
+
|
162
|
+
### Advanced CAPTCHA Scenarios
|
163
|
+
|
164
|
+
```javascript
|
165
|
+
// Complex image CAPTCHA with deep thinking
|
166
|
+
await agent.aiCaptcha({
|
167
|
+
deepThink: true // Forces detailed analysis for complex puzzles
|
168
|
+
});
|
169
|
+
|
170
|
+
// Text CAPTCHA with automatic input
|
171
|
+
// AI will automatically:
|
172
|
+
// - Click on input field
|
173
|
+
// - Type the solution
|
174
|
+
// - Click verify button
|
175
|
+
await agent.aiCaptcha();
|
176
|
+
|
177
|
+
// Using with cumulative context
|
178
|
+
await agent.aiQuery('CAPTCHA çözümünü captcha_cozum olarak kaydet');
|
179
|
+
await agent.aiCaptcha();
|
180
|
+
await agent.aiAssert('CAPTCHA başarıyla çözüldü');
|
181
|
+
```
|
182
|
+
|
183
|
+
## ⚙️ Configuration Options
|
184
|
+
|
185
|
+
```javascript
|
186
|
+
const agent = new PuppeteerAgent(page, {
|
187
|
+
// Context System
|
188
|
+
enableCumulativeContext: true, // Enable/disable context system
|
189
|
+
autoClearContext: false, // Auto-clear on agent creation
|
190
|
+
|
191
|
+
// Basic Options
|
192
|
+
testId: 'my-test', // Test identifier
|
193
|
+
cacheId: 'my-cache', // Cache identifier
|
194
|
+
aiActionContext: 'context', // AI behavior context
|
195
|
+
|
196
|
+
// Reporting
|
197
|
+
generateReport: true, // Generate HTML reports
|
198
|
+
autoPrintReportMsg: true, // Print report messages
|
199
|
+
|
200
|
+
// Navigation
|
201
|
+
forceSameTabNavigation: true, // Force same-tab navigation
|
202
|
+
waitForNavigationTimeout: 30000, // Navigation timeout
|
203
|
+
waitForNetworkIdleTimeout: 5000 // Network idle timeout
|
204
|
+
});
|
205
|
+
```
|
206
|
+
|
207
|
+
## 📊 Context Management
|
208
|
+
|
209
|
+
### Direct Context Access
|
210
|
+
|
211
|
+
```javascript
|
212
|
+
// Get stored data
|
213
|
+
const storedData = agent.getStoredData();
|
214
|
+
console.log('Stored:', storedData);
|
215
|
+
|
216
|
+
// Get step summary
|
217
|
+
const summary = agent.getStepSummary();
|
218
|
+
console.log('Steps:', summary);
|
219
|
+
|
220
|
+
// Clear context manually
|
221
|
+
agent.clearContext();
|
222
|
+
|
223
|
+
// Get context store instance
|
224
|
+
const contextStore = agent.getContextStore();
|
225
|
+
```
|
226
|
+
|
227
|
+
### Manual Data Storage
|
228
|
+
|
229
|
+
```javascript
|
230
|
+
const contextStore = agent.getContextStore();
|
231
|
+
|
232
|
+
// Store data manually
|
233
|
+
contextStore.storeData('customKey', 'customValue');
|
234
|
+
|
235
|
+
// Store with aliases for natural language
|
236
|
+
contextStore.storeDataWithAliases('productName', 'iPhone 15', ['urun', 'product']);
|
237
|
+
|
238
|
+
// Get recent steps
|
239
|
+
const recentSteps = contextStore.getRecentSteps(5);
|
240
|
+
```
|
241
|
+
|
242
|
+
## 🔍 Debug Logging
|
243
|
+
|
244
|
+
Enable comprehensive logging to see context operations:
|
245
|
+
|
246
|
+
```bash
|
247
|
+
# All debug logs
|
248
|
+
DEBUG=midscene:* node your-script.js
|
249
|
+
|
250
|
+
# Context-specific logs
|
251
|
+
DEBUG=midscene:agent node your-script.js
|
252
|
+
|
253
|
+
# AI call logs
|
254
|
+
DEBUG=midscene:ai:*,midscene:agent node your-script.js
|
255
|
+
```
|
256
|
+
|
257
|
+
### Log Examples
|
258
|
+
|
259
|
+
```
|
260
|
+
DEBUG midscene:agent Context replacement in aiAction: {
|
261
|
+
original: "type username in search box",
|
262
|
+
processed: "type john_doe in search box",
|
263
|
+
storedData: { "username": "john_doe" }
|
264
|
+
}
|
265
|
+
|
266
|
+
DEBUG midscene:agent Stored query result with aliases: {
|
267
|
+
key: "username",
|
268
|
+
value: "john_doe",
|
269
|
+
aliases: ["username", "user", "kullanici"]
|
270
|
+
}
|
271
|
+
```
|
272
|
+
|
273
|
+
## 🎭 Multi-Step Workflow Example
|
274
|
+
|
275
|
+
```javascript
|
276
|
+
// E-commerce automation with context
|
277
|
+
const agent = new PuppeteerAgent(page, {
|
278
|
+
enableCumulativeContext: true,
|
279
|
+
autoClearContext: true
|
280
|
+
});
|
281
|
+
|
282
|
+
await page.goto('https://shop.example.com');
|
283
|
+
|
284
|
+
// Step 1: Search and store product info
|
285
|
+
await agent.aiAction('arama kutusuna "laptop" yaz ve ara');
|
286
|
+
await agent.aiQuery('ilk ürünün adını urun_adi olarak kaydet');
|
287
|
+
await agent.aiQuery('ilk ürünün fiyatını urun_fiyati olarak kaydet');
|
288
|
+
|
289
|
+
// Step 2: Add to cart using stored data
|
290
|
+
await agent.aiAction('urun_adi ürününü sepete ekle');
|
291
|
+
|
292
|
+
// Step 3: Verify cart contents
|
293
|
+
await agent.aiAction('sepete git');
|
294
|
+
await agent.aiAssert('sepette urun_adi ürünü urun_fiyati fiyatıyla görünüyor');
|
295
|
+
|
296
|
+
// Step 4: Proceed to checkout
|
297
|
+
await agent.aiAction('ödeme sayfasına git');
|
298
|
+
await agent.aiAssert('ödeme sayfasında urun_adi ürünü listeleniyor');
|
299
|
+
```
|
300
|
+
|
301
|
+
## 🔄 Backward Compatibility
|
302
|
+
|
303
|
+
The new context system is fully backward compatible:
|
304
|
+
|
305
|
+
```javascript
|
306
|
+
// Old syntax still works
|
307
|
+
await agent.aiQuery('extract username, store as user');
|
308
|
+
await agent.aiAction('type {stored.user} in field');
|
309
|
+
|
310
|
+
// New syntax (recommended)
|
311
|
+
await agent.aiQuery('kullanıcı adını user olarak kaydet');
|
312
|
+
await agent.aiAction('alana user verisini yaz');
|
313
|
+
|
314
|
+
// Mixed usage
|
315
|
+
await agent.aiAction('use {stored.email} and user verisi together');
|
316
|
+
```
|
317
|
+
|
318
|
+
## 📚 API Reference
|
319
|
+
|
320
|
+
### Core Methods
|
321
|
+
|
322
|
+
- `aiAction(prompt)` - Perform actions with context awareness
|
323
|
+
- `aiQuery(prompt)` - Extract data with automatic storage
|
324
|
+
- `aiAssert(assertion)` - Context-aware assertions
|
325
|
+
- `aiCaptcha(options)` - Intelligent CAPTCHA solving
|
326
|
+
- `aiTap(target, options)` - Click elements
|
327
|
+
- `aiInput(text, target, options)` - Input text
|
328
|
+
|
329
|
+
### Context Methods
|
330
|
+
|
331
|
+
- `getStoredData()` - Get all stored data
|
332
|
+
- `getStepSummary()` - Get step summary
|
333
|
+
- `clearContext()` - Clear context store
|
334
|
+
- `getContextStore()` - Get context store instance
|
335
|
+
|
336
|
+
## 🤝 Contributing
|
337
|
+
|
338
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
339
|
+
|
340
|
+
## 📄 License
|
341
|
+
|
342
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
343
|
+
|
344
|
+
## 🔗 Links
|
345
|
+
|
346
|
+
- [Documentation](https://midscenejs.com)
|
347
|
+
- [GitHub Repository](https://github.com/web-infra-dev/midscene)
|
348
|
+
- [NPM Package](https://www.npmjs.com/package/@midscene/web)
|
349
|
+
- [Examples](https://github.com/web-infra-dev/midscene/tree/main/packages/web-integration/examples)
|
350
|
+
|
351
|
+
---
|
352
|
+
|
353
|
+
**Made with ❤️ by the Midscene Team**
|
package/dist/es/agent.js
CHANGED
@@ -1660,7 +1660,7 @@ import yaml3 from "js-yaml";
|
|
1660
1660
|
import semver from "semver";
|
1661
1661
|
|
1662
1662
|
// package.json
|
1663
|
-
var version = "1.0.
|
1663
|
+
var version = "1.0.5";
|
1664
1664
|
|
1665
1665
|
// src/common/task-cache.ts
|
1666
1666
|
var debug3 = getDebug3("cache");
|
@@ -1842,10 +1842,13 @@ var PageAgent = class {
|
|
1842
1842
|
generateReport: true,
|
1843
1843
|
autoPrintReportMsg: true,
|
1844
1844
|
groupName: "Midscene Report",
|
1845
|
-
groupDescription: ""
|
1845
|
+
groupDescription: "",
|
1846
|
+
enableCumulativeContext: true,
|
1847
|
+
autoClearContext: false
|
1846
1848
|
},
|
1847
1849
|
opts || {}
|
1848
1850
|
);
|
1851
|
+
this.initializeContextStore();
|
1849
1852
|
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1850
1853
|
this.page.waitForNavigationTimeout = this.opts.waitForNavigationTimeout || DEFAULT_WAIT_FOR_NAVIGATION_TIMEOUT;
|
1851
1854
|
this.page.waitForNetworkIdleTimeout = this.opts.waitForNetworkIdleTimeout || DEFAULT_WAIT_FOR_NETWORK_IDLE_TIMEOUT;
|
@@ -1872,6 +1875,69 @@ var PageAgent = class {
|
|
1872
1875
|
opts?.testId || this.page.pageType || "web"
|
1873
1876
|
);
|
1874
1877
|
}
|
1878
|
+
/**
|
1879
|
+
* Initialize context store for cumulative context functionality
|
1880
|
+
*/
|
1881
|
+
async initializeContextStore() {
|
1882
|
+
if (!this.opts.enableCumulativeContext) {
|
1883
|
+
debug4("Cumulative context disabled via options");
|
1884
|
+
return;
|
1885
|
+
}
|
1886
|
+
try {
|
1887
|
+
const aiModel = await import("misoai-core/ai-model");
|
1888
|
+
this.contextStore = aiModel.getContextStore();
|
1889
|
+
debug4("Context store initialized successfully", {
|
1890
|
+
autoClearContext: this.opts.autoClearContext,
|
1891
|
+
testId: this.opts.testId
|
1892
|
+
});
|
1893
|
+
if (this.opts.autoClearContext) {
|
1894
|
+
this.contextStore.clear();
|
1895
|
+
debug4("Context store cleared due to autoClearContext option");
|
1896
|
+
} else {
|
1897
|
+
const existingData = this.contextStore.getAllData();
|
1898
|
+
const existingSteps = this.contextStore.getRecentSteps(100).length;
|
1899
|
+
debug4("Context store preserving existing data", {
|
1900
|
+
existingDataKeys: Object.keys(existingData),
|
1901
|
+
existingStepsCount: existingSteps
|
1902
|
+
});
|
1903
|
+
}
|
1904
|
+
} catch (error) {
|
1905
|
+
debug4("Failed to initialize context store:", error);
|
1906
|
+
console.warn("⚠️ Could not initialize context store:", error);
|
1907
|
+
}
|
1908
|
+
}
|
1909
|
+
/**
|
1910
|
+
* Get the context store instance
|
1911
|
+
*/
|
1912
|
+
getContextStore() {
|
1913
|
+
return this.contextStore;
|
1914
|
+
}
|
1915
|
+
/**
|
1916
|
+
* Clear the context store
|
1917
|
+
*/
|
1918
|
+
clearContext() {
|
1919
|
+
if (this.contextStore) {
|
1920
|
+
this.contextStore.clear();
|
1921
|
+
}
|
1922
|
+
}
|
1923
|
+
/**
|
1924
|
+
* Get all stored data from context store
|
1925
|
+
*/
|
1926
|
+
getStoredData() {
|
1927
|
+
if (this.contextStore) {
|
1928
|
+
return this.contextStore.getAllData();
|
1929
|
+
}
|
1930
|
+
return {};
|
1931
|
+
}
|
1932
|
+
/**
|
1933
|
+
* Get step summary from context store
|
1934
|
+
*/
|
1935
|
+
getStepSummary() {
|
1936
|
+
if (this.contextStore) {
|
1937
|
+
return this.contextStore.getStepSummary();
|
1938
|
+
}
|
1939
|
+
return "";
|
1940
|
+
}
|
1875
1941
|
async getUIContext(action) {
|
1876
1942
|
if (action && (action === "extract" || action === "assert" || action === "captcha")) {
|
1877
1943
|
return await parseContextFromWebPage(this.page, {
|
@@ -2107,18 +2173,30 @@ var PageAgent = class {
|
|
2107
2173
|
};
|
2108
2174
|
}
|
2109
2175
|
async aiAction(taskPrompt, opt) {
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2176
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2177
|
+
try {
|
2178
|
+
const originalPrompt = taskPrompt;
|
2179
|
+
const processedPrompt = this.contextStore.replaceAllReferences(taskPrompt, "action");
|
2180
|
+
if (originalPrompt !== processedPrompt) {
|
2181
|
+
debug4("Context replacement in aiAction:", {
|
2182
|
+
original: originalPrompt,
|
2183
|
+
processed: processedPrompt,
|
2184
|
+
storedData: this.contextStore.getAllData()
|
2185
|
+
});
|
2186
|
+
}
|
2187
|
+
this.contextStore.addStep({
|
2188
|
+
type: "action",
|
2189
|
+
summary: `Action: ${processedPrompt}`,
|
2190
|
+
prompt: processedPrompt
|
2191
|
+
});
|
2192
|
+
debug4("Added action step to context store:", {
|
2193
|
+
stepNumber: this.contextStore.getRecentSteps(1)[0]?.stepNumber,
|
2194
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2195
|
+
});
|
2196
|
+
taskPrompt = processedPrompt;
|
2197
|
+
} catch (error) {
|
2198
|
+
debug4("Context store operation failed:", error);
|
2199
|
+
}
|
2122
2200
|
}
|
2123
2201
|
const cacheable = opt?.cacheable;
|
2124
2202
|
const isVlmUiTars = vlLocateMode() === "vlm-ui-tars";
|
@@ -2189,38 +2267,50 @@ var PageAgent = class {
|
|
2189
2267
|
debug4("Context store not available:", error);
|
2190
2268
|
}
|
2191
2269
|
const { output, executor } = await this.taskExecutor.query(processedDemand);
|
2192
|
-
if (
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2270
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2271
|
+
if (storageKey && output) {
|
2272
|
+
try {
|
2273
|
+
const pendingAliases = this.contextStore._pendingAliases;
|
2274
|
+
if (pendingAliases) {
|
2275
|
+
this.contextStore.storeDataWithAliases(storageKey, output, pendingAliases, typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand));
|
2276
|
+
delete this.contextStore._pendingAliases;
|
2277
|
+
debug4("Stored query result with aliases:", {
|
2278
|
+
key: storageKey,
|
2279
|
+
value: output,
|
2280
|
+
aliases: pendingAliases
|
2281
|
+
});
|
2282
|
+
} else {
|
2283
|
+
this.contextStore.storeData(storageKey, output);
|
2284
|
+
debug4("Stored query result:", {
|
2285
|
+
key: storageKey,
|
2286
|
+
value: output
|
2287
|
+
});
|
2288
|
+
}
|
2289
|
+
this.contextStore.addStep({
|
2290
|
+
type: "query",
|
2291
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2292
|
+
data: output,
|
2293
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2294
|
+
});
|
2295
|
+
debug4("Added query step to context store:", {
|
2296
|
+
storageKey,
|
2297
|
+
totalStoredItems: Object.keys(this.contextStore.getAllData()).length,
|
2298
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2299
|
+
});
|
2300
|
+
} catch (error) {
|
2301
|
+
debug4("Failed to store query result:", error);
|
2302
|
+
}
|
2303
|
+
} else {
|
2304
|
+
try {
|
2305
|
+
this.contextStore.addStep({
|
2306
|
+
type: "query",
|
2307
|
+
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2308
|
+
data: output,
|
2309
|
+
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2310
|
+
});
|
2311
|
+
} catch (error) {
|
2312
|
+
debug4("Failed to add query step:", error);
|
2202
2313
|
}
|
2203
|
-
contextStore.addStep({
|
2204
|
-
type: "query",
|
2205
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)} (stored as ${storageKey})`,
|
2206
|
-
data: output,
|
2207
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2208
|
-
});
|
2209
|
-
} catch (error) {
|
2210
|
-
debug4("Failed to store query result:", error);
|
2211
|
-
}
|
2212
|
-
} else {
|
2213
|
-
try {
|
2214
|
-
const aiModel = await import("misoai-core/ai-model");
|
2215
|
-
const contextStore = aiModel.getContextStore();
|
2216
|
-
contextStore.addStep({
|
2217
|
-
type: "query",
|
2218
|
-
summary: `Query: ${typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)}`,
|
2219
|
-
data: output,
|
2220
|
-
prompt: typeof processedDemand === "string" ? processedDemand : JSON.stringify(processedDemand)
|
2221
|
-
});
|
2222
|
-
} catch (error) {
|
2223
|
-
debug4("Failed to add query step:", error);
|
2224
2314
|
}
|
2225
2315
|
}
|
2226
2316
|
const metadata = this.afterTaskRunning(executor);
|
@@ -2333,17 +2423,29 @@ var PageAgent = class {
|
|
2333
2423
|
}
|
2334
2424
|
async aiAssert(assertion, msg, opt) {
|
2335
2425
|
let processedAssertion = assertion;
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2426
|
+
if (this.opts.enableCumulativeContext && this.contextStore) {
|
2427
|
+
try {
|
2428
|
+
const originalAssertion = assertion;
|
2429
|
+
processedAssertion = this.contextStore.replaceAllReferences(assertion, "assertion");
|
2430
|
+
if (originalAssertion !== processedAssertion) {
|
2431
|
+
debug4("Context replacement in aiAssert:", {
|
2432
|
+
original: originalAssertion,
|
2433
|
+
processed: processedAssertion,
|
2434
|
+
context: "assertion",
|
2435
|
+
storedData: this.contextStore.getAllData()
|
2436
|
+
});
|
2437
|
+
}
|
2438
|
+
this.contextStore.addStep({
|
2439
|
+
type: "assertion",
|
2440
|
+
summary: `Assertion: ${processedAssertion}`,
|
2441
|
+
prompt: processedAssertion
|
2442
|
+
});
|
2443
|
+
debug4("Added assertion step to context store:", {
|
2444
|
+
totalSteps: this.contextStore.getRecentSteps(100).length
|
2445
|
+
});
|
2446
|
+
} catch (error) {
|
2447
|
+
debug4("Context store operation failed:", error);
|
2448
|
+
}
|
2347
2449
|
}
|
2348
2450
|
let currentUrl = "";
|
2349
2451
|
if (this.page.url) {
|