@bini-bar-labs/atomic-web-agent-core 1.0.0 → 1.0.2
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 +137 -1
- package/dist/AWAgent/AWAgent.d.ts +6 -0
- package/dist/AWAgent/AWAgent.d.ts.map +1 -1
- package/dist/AWAgent/AWAgent.js +178 -6
- package/dist/AWAgent/AWAgent.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/extract-data.tool.d.ts +9 -0
- package/dist/tools/extract-data.tool.d.ts.map +1 -0
- package/dist/tools/extract-data.tool.js +23 -0
- package/dist/tools/extract-data.tool.js.map +1 -0
- package/dist/tools/get-DOM-snapshot.tool.d.ts +8 -1
- package/dist/tools/get-DOM-snapshot.tool.d.ts.map +1 -1
- package/dist/tools/get-DOM-snapshot.tool.js +29 -3
- package/dist/tools/get-DOM-snapshot.tool.js.map +1 -1
- package/dist/tools/navigate.tool.js +1 -1
- package/dist/tools/navigate.tool.js.map +1 -1
- package/dist/tools/utils/accessibility-snapshot.util.d.ts +4 -1
- package/dist/tools/utils/accessibility-snapshot.util.d.ts.map +1 -1
- package/dist/tools/utils/accessibility-snapshot.util.js +41 -4
- package/dist/tools/utils/accessibility-snapshot.util.js.map +1 -1
- package/dist/tools/validate-condition.tool.d.ts +12 -0
- package/dist/tools/validate-condition.tool.d.ts.map +1 -0
- package/dist/tools/validate-condition.tool.js +23 -0
- package/dist/tools/validate-condition.tool.js.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -50,6 +50,112 @@ await agent.run("Navigate to https://example.com and take a screenshot");
|
|
|
50
50
|
await agent.close();
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
## Page Validation
|
|
54
|
+
|
|
55
|
+
The `test()` method enables you to validate conditions on the current webpage using natural language. It returns `true` if the condition is met, `false` otherwise.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// Example: Check if user is logged in
|
|
59
|
+
const isLoggedIn = await agent.test("The user is logged in");
|
|
60
|
+
console.log(isLoggedIn); // true or false
|
|
61
|
+
|
|
62
|
+
// Example: Verify form validation
|
|
63
|
+
const hasError = await agent.test("An error message is displayed");
|
|
64
|
+
|
|
65
|
+
// Example: Check element state
|
|
66
|
+
const isButtonDisabled = await agent.test("The submit button is disabled");
|
|
67
|
+
|
|
68
|
+
// Example: Verify content presence
|
|
69
|
+
const hasWelcomeMessage = await agent.test("A welcome message appears on the page");
|
|
70
|
+
|
|
71
|
+
// Example: Complex state validation
|
|
72
|
+
const isCheckoutReady = await agent.test(
|
|
73
|
+
"The shopping cart has items and the checkout button is clickable"
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Best Practices for test() Conditions
|
|
78
|
+
|
|
79
|
+
- **Be specific and measurable**: "The login button is visible" is better than "The page looks good"
|
|
80
|
+
- **Focus on observable state**: Describe what should be visible or present on the page
|
|
81
|
+
- **Avoid subjective interpretations**: Use concrete, verifiable conditions
|
|
82
|
+
- **Keep it atomic**: Test one condition at a time for clearer results
|
|
83
|
+
|
|
84
|
+
## Data Extraction
|
|
85
|
+
|
|
86
|
+
The `extract()` method enables you to extract structured data from webpages using Zod schemas. It returns typed data that matches your schema.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { z } from "zod";
|
|
90
|
+
|
|
91
|
+
// Define your data schema
|
|
92
|
+
const productSchema = z.object({
|
|
93
|
+
title: z.string().describe("The product title"),
|
|
94
|
+
price: z.number().describe("The product price in dollars"),
|
|
95
|
+
description: z.string().describe("The product description"),
|
|
96
|
+
inStock: z.boolean().describe("Whether the product is in stock"),
|
|
97
|
+
rating: z.number().optional().describe("Product rating out of 5"),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
type Product = z.infer<typeof productSchema>;
|
|
101
|
+
|
|
102
|
+
// Extract data from the page
|
|
103
|
+
const product = await agent.extract<Product>(
|
|
104
|
+
productSchema,
|
|
105
|
+
"Extract product information from this page"
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
console.log(product);
|
|
109
|
+
// { title: "...", price: 99.99, description: "...", inStock: true, rating: 4.5 }
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### More Examples
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
// Extract multiple items (array)
|
|
116
|
+
const itemsSchema = z.object({
|
|
117
|
+
items: z.array(
|
|
118
|
+
z.object({
|
|
119
|
+
name: z.string(),
|
|
120
|
+
price: z.number(),
|
|
121
|
+
})
|
|
122
|
+
),
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const data = await agent.extract(itemsSchema);
|
|
126
|
+
|
|
127
|
+
// Extract user profile
|
|
128
|
+
const profileSchema = z.object({
|
|
129
|
+
name: z.string(),
|
|
130
|
+
email: z.string().email(),
|
|
131
|
+
age: z.number().optional(),
|
|
132
|
+
isVerified: z.boolean(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const profile = await agent.extract(profileSchema);
|
|
136
|
+
|
|
137
|
+
// Extract with custom instructions
|
|
138
|
+
const statsSchema = z.object({
|
|
139
|
+
visitors: z.number(),
|
|
140
|
+
pageViews: z.number(),
|
|
141
|
+
bounceRate: z.number(),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const stats = await agent.extract(
|
|
145
|
+
statsSchema,
|
|
146
|
+
"Look for the analytics dashboard section and extract the key metrics displayed"
|
|
147
|
+
);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Features
|
|
151
|
+
|
|
152
|
+
- **Type-safe**: Full TypeScript support with automatic type inference
|
|
153
|
+
- **Schema validation**: Extracted data is validated against your Zod schema
|
|
154
|
+
- **Native structured output**: Uses LangChain's `providerStrategy` for efficient extraction via model provider's native structured output capability
|
|
155
|
+
- **Automatic field detection**: AI determines how to extract each field
|
|
156
|
+
- **Flexible**: Works with complex nested schemas
|
|
157
|
+
- **Error handling**: Clear validation errors if data doesn't match schema
|
|
158
|
+
|
|
53
159
|
## API Reference
|
|
54
160
|
|
|
55
161
|
### AWAgent
|
|
@@ -75,6 +181,8 @@ new AWAgent(
|
|
|
75
181
|
|
|
76
182
|
- `init(launchOptions?: LaunchOptions, contextOptions?: BrowserContextOptions): Promise<void>` - Initialize the browser and agent
|
|
77
183
|
- `run(message: string): Promise<void>` - Execute a task with the agent
|
|
184
|
+
- `test(condition: string): Promise<boolean>` - Validate a condition on the current page and return true/false
|
|
185
|
+
- `extract<T>(schema: z.ZodSchema<T>, instructions?: string): Promise<T>` - Extract structured data from the page using a Zod schema
|
|
78
186
|
- `close(): Promise<void>` - Close the browser and clean up resources
|
|
79
187
|
|
|
80
188
|
### Exports
|
|
@@ -85,6 +193,8 @@ export { type PlaywrightPage } from "@bini-bar-labs/atomic-web-agent-core";
|
|
|
85
193
|
export { createTool } from "@bini-bar-labs/atomic-web-agent-core";
|
|
86
194
|
export { type AgentTool } from "@bini-bar-labs/atomic-web-agent-core";
|
|
87
195
|
export { ElementLocatorRegistry } from "@bini-bar-labs/atomic-web-agent-core";
|
|
196
|
+
export { validateConditionTool } from "@bini-bar-labs/atomic-web-agent-core";
|
|
197
|
+
export { extractDataTool } from "@bini-bar-labs/atomic-web-agent-core";
|
|
88
198
|
export {
|
|
89
199
|
type ElementSnapshot,
|
|
90
200
|
type PageSnapshot,
|
|
@@ -100,9 +210,35 @@ The agent comes with several pre-configured tools:
|
|
|
100
210
|
- **Click**: Click elements by ID or position
|
|
101
211
|
- **Input**: Type text into input fields
|
|
102
212
|
- **Screenshot**: Capture page screenshots
|
|
103
|
-
- **DOM Snapshot**: Get accessibility-based page structure
|
|
213
|
+
- **DOM Snapshot**: Get accessibility-based page structure (with optional extra tags)
|
|
104
214
|
- **Wait**: Wait for specified durations
|
|
105
215
|
- **Console Print**: Output messages to console
|
|
216
|
+
- **Validation**: Return validation results (used by `test()` method)
|
|
217
|
+
|
|
218
|
+
Note: The `extract()` method uses native structured output via LangChain's `providerStrategy` rather than a custom tool, allowing for more efficient data extraction directly from the model provider.
|
|
219
|
+
|
|
220
|
+
### DOM Snapshot with Custom Elements
|
|
221
|
+
|
|
222
|
+
The DOM Snapshot tool is intelligent and can include additional HTML elements beyond the default interactive elements. The AI can request specific tags to be included in the snapshot.
|
|
223
|
+
|
|
224
|
+
**How it works:**
|
|
225
|
+
- By default, the snapshot includes only interactive elements (buttons, inputs, links, etc.)
|
|
226
|
+
- The AI can specify additional HTML tags to include using the `extraTags` parameter
|
|
227
|
+
- This is useful for validation tasks that need to examine text content or specific elements
|
|
228
|
+
|
|
229
|
+
**Example use case:**
|
|
230
|
+
When you ask the agent to validate text content on a page, the AI will automatically:
|
|
231
|
+
1. Call `GetDOMSnapshot` with `extraTags: ["p", "span", "h1", "h2"]`
|
|
232
|
+
2. Receive a snapshot that includes both interactive elements AND the specified text elements
|
|
233
|
+
3. Validate the condition based on the complete snapshot
|
|
234
|
+
|
|
235
|
+
**Common tags the AI might request:**
|
|
236
|
+
- Text content: `p`, `span`, `div`
|
|
237
|
+
- Headings: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`
|
|
238
|
+
- Lists: `li`, `ul`, `ol`
|
|
239
|
+
- Labels: `label`
|
|
240
|
+
|
|
241
|
+
This feature enables more accurate validation and interaction with webpage content without overwhelming the context with unnecessary elements.
|
|
106
242
|
|
|
107
243
|
## Custom Tools
|
|
108
244
|
|
|
@@ -2,6 +2,7 @@ import { ChatAnthropic } from "@langchain/anthropic";
|
|
|
2
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
3
|
import { Tool } from "langchain";
|
|
4
4
|
import { type BrowserContextOptions, type LaunchOptions, type Page } from "playwright";
|
|
5
|
+
import { z } from "zod";
|
|
5
6
|
import { ElementLocatorRegistry } from "../tools/utils/element-registry.util.js";
|
|
6
7
|
import type { AgentTool } from "./AWAgent.types.js";
|
|
7
8
|
export declare class AWAgent {
|
|
@@ -29,7 +30,12 @@ export declare class AWAgent {
|
|
|
29
30
|
getCurrentPage(): Page;
|
|
30
31
|
getAllPages(): Page[];
|
|
31
32
|
do(task: string): Promise<void>;
|
|
33
|
+
test(condition: string): Promise<boolean>;
|
|
34
|
+
extract<T>(instructions: string, schema: z.ZodSchema<T>): Promise<T>;
|
|
32
35
|
close(): Promise<void>;
|
|
36
|
+
private extractValidationResult;
|
|
37
|
+
private generateSchemaDescription;
|
|
38
|
+
private extractStructuredOutput;
|
|
33
39
|
private createTools;
|
|
34
40
|
}
|
|
35
41
|
//# sourceMappingURL=AWAgent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AWAgent.d.ts","sourceRoot":"","sources":["../../src/AWAgent/AWAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"AWAgent.d.ts","sourceRoot":"","sources":["../../src/AWAgent/AWAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAQL,IAAI,EAEL,MAAM,WAAW,CAAC;AACnB,OAAO,EAGL,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAClB,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAGjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpD,qBAAa,OAAO;IAClB,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,OAAO,CAA+B;IAC9C,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,aAAa,CAKnB;IACF,OAAO,CAAC,WAAW,CAAgC;gBAGjD,KAAK,EAAE,aAAa,GAAG,UAAU,EACjC,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACvC,aAAa,CAAC,EAAE;YACd,kBAAkB,CAAC,EAAE,CACnB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,sBAAsB,KAC7B,SAAS,CAAC;SAChB,CAAC;KACH;IASG,IAAI,CACR,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,cAAc,CAAC,EAAE,qBAAqB,CAAC;KACxC;IAWG,OAAO;IASb,cAAc;IAOd,WAAW;IAQL,EAAE,CAAC,IAAI,EAAE,MAAM;IA0Cf,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiDzC,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAsDpE,KAAK;IAeX,OAAO,CAAC,uBAAuB;IA+C/B,OAAO,CAAC,yBAAyB;IAOjC,OAAO,CAAC,uBAAuB;IAwD/B,OAAO,CAAC,WAAW;CAiBpB"}
|
package/dist/AWAgent/AWAgent.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ChatAnthropic } from "@langchain/anthropic";
|
|
2
2
|
import { ChatOpenAI } from "@langchain/openai";
|
|
3
|
-
import { createAgent, HumanMessage, SystemMessage, Tool, } from "langchain";
|
|
3
|
+
import { AIMessage, createAgent, HumanMessage, providerStrategy, SystemMessage, Tool, ToolMessage, } from "langchain";
|
|
4
4
|
import { chromium, } from "playwright";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
7
|
import { clickByElementIdTool } from "../tools/click-by-element-id.tool.js";
|
|
6
|
-
import { clickByPositionTool } from "../tools/click-by-position.tool.js";
|
|
7
8
|
import { getDOMSnapshotTool } from "../tools/get-DOM-snapshot.tool.js";
|
|
8
|
-
import { getPageScreenShotTool } from "../tools/get-page-screenshot.tool.js";
|
|
9
9
|
import { inputByElementIdTool } from "../tools/input-by-element-id.tool.js";
|
|
10
10
|
import { navigateTool } from "../tools/navigate.tool.js";
|
|
11
11
|
import { printToConsoleTool } from "../tools/print-to-console.tool.js";
|
|
12
12
|
import { ElementLocatorRegistry } from "../tools/utils/element-registry.util.js";
|
|
13
|
+
import { validateConditionTool } from "../tools/validate-condition.tool.js";
|
|
13
14
|
import { waitTool } from "../tools/wait.tool.js";
|
|
14
15
|
import { loggingMiddleware } from "./middlewares/logging-calls.middleware.js";
|
|
15
16
|
import { trimMessagesHistoryMiddleware } from "./middlewares/trim-messages-history.middleware.js";
|
|
@@ -67,10 +68,25 @@ export class AWAgent {
|
|
|
67
68
|
}
|
|
68
69
|
if (!this.agent) {
|
|
69
70
|
const tools = this.createTools(this.currentPageContext);
|
|
71
|
+
// Enhance system message with behavioral guidelines
|
|
72
|
+
const baseMessage = typeof this.systemMessage.content === "string"
|
|
73
|
+
? this.systemMessage.content
|
|
74
|
+
: JSON.stringify(this.systemMessage.content);
|
|
75
|
+
const enhancedSystemPrompt = new SystemMessage(`${baseMessage}
|
|
76
|
+
|
|
77
|
+
IMPORTANT BEHAVIORAL GUIDELINES:
|
|
78
|
+
1. You are operating on a browser page. ALWAYS start by using GetDOMSnapshot to see what page you're currently on and what's available.
|
|
79
|
+
2. Be PROACTIVE and take ACTION immediately. Do NOT ask the user clarifying questions unless absolutely necessary.
|
|
80
|
+
3. If you're already on a website and the user asks to navigate to a section (e.g., "go to men's shoes"), use the available page elements to navigate within the current site.
|
|
81
|
+
4. Use ClickByElementId to click on links, buttons, or navigation elements that match the user's intent.
|
|
82
|
+
5. If you need more context about the page, use GetDOMSnapshot with extra tags like ["a", "nav", "h1", "h2"] to see navigation links and headings.
|
|
83
|
+
6. Only use NavigateToURL if you need to go to a completely different website with a specific URL.
|
|
84
|
+
7. Execute the task directly based on what you observe on the page. Be decisive.
|
|
85
|
+
8. If you cannot complete the task with the available tools and page elements, explain why clearly.`);
|
|
70
86
|
const agent = createAgent({
|
|
71
87
|
model: this.model,
|
|
72
88
|
tools: tools,
|
|
73
|
-
systemPrompt:
|
|
89
|
+
systemPrompt: enhancedSystemPrompt,
|
|
74
90
|
middleware: [loggingMiddleware, trimMessagesHistoryMiddleware],
|
|
75
91
|
});
|
|
76
92
|
this.agent = agent;
|
|
@@ -80,6 +96,82 @@ export class AWAgent {
|
|
|
80
96
|
});
|
|
81
97
|
return console.log(response.messages.at(-1).content);
|
|
82
98
|
}
|
|
99
|
+
async test(condition) {
|
|
100
|
+
if (!this.currentPageContext) {
|
|
101
|
+
throw new Error("Agent is not initialized");
|
|
102
|
+
}
|
|
103
|
+
// Create a temporary agent with validation tools
|
|
104
|
+
const validationTools = [
|
|
105
|
+
...this.createTools(this.currentPageContext),
|
|
106
|
+
validateConditionTool(),
|
|
107
|
+
];
|
|
108
|
+
const validationSystemPrompt = new SystemMessage(`You are a webpage validation agent. Your task is to determine if a given condition is true or false on the current webpage.
|
|
109
|
+
|
|
110
|
+
Instructions:
|
|
111
|
+
1. First, use GetDOMSnapshot to examine the page structure
|
|
112
|
+
2. If needed, use GetPageScreenShot for visual confirmation
|
|
113
|
+
3. Analyze whether the condition is met based on the available evidence
|
|
114
|
+
4. Call ReturnValidationResult with your boolean conclusion and reasoning
|
|
115
|
+
5. IMPORTANT: After calling ReturnValidationResult, your task is complete. Do NOT take any further actions.
|
|
116
|
+
|
|
117
|
+
Be precise and factual. Only return true if you have clear evidence the condition is met.
|
|
118
|
+
If you cannot determine the result with confidence, return false with an explanation.
|
|
119
|
+
|
|
120
|
+
Your final action MUST be to call ReturnValidationResult. Do not continue after that.`);
|
|
121
|
+
const validationAgent = createAgent({
|
|
122
|
+
model: this.model,
|
|
123
|
+
tools: validationTools,
|
|
124
|
+
systemPrompt: validationSystemPrompt,
|
|
125
|
+
middleware: [loggingMiddleware, trimMessagesHistoryMiddleware],
|
|
126
|
+
});
|
|
127
|
+
const response = await validationAgent.invoke({
|
|
128
|
+
messages: [new HumanMessage(`Validate: ${condition}`)],
|
|
129
|
+
}, {
|
|
130
|
+
recursionLimit: 10, // Limit iterations to prevent infinite loops
|
|
131
|
+
});
|
|
132
|
+
// Parse the validation result from the agent's messages
|
|
133
|
+
const result = this.extractValidationResult(response.messages);
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
async extract(instructions, schema) {
|
|
137
|
+
if (!this.currentPageContext) {
|
|
138
|
+
throw new Error("Agent is not initialized");
|
|
139
|
+
}
|
|
140
|
+
// Create tools for extraction (without the extractDataTool)
|
|
141
|
+
const extractionTools = this.createTools(this.currentPageContext);
|
|
142
|
+
// Generate schema description for the AI
|
|
143
|
+
const schemaDescription = this.generateSchemaDescription(schema);
|
|
144
|
+
const extractionSystemPrompt = new SystemMessage(`You are a webpage data extraction agent. Your task is to extract structured data from the current webpage according to a specific schema.
|
|
145
|
+
|
|
146
|
+
Instructions:
|
|
147
|
+
1. Use GetDOMSnapshot to examine the page structure. Include extra tags if needed (e.g., ["p", "span", "h1"] for text content)
|
|
148
|
+
2. If needed, use GetPageScreenShot for visual confirmation
|
|
149
|
+
3. Analyze the page content and extract the required data fields according to the schema
|
|
150
|
+
4. Return the extracted data in your final response
|
|
151
|
+
|
|
152
|
+
Additional instructions: ${instructions}\n\n
|
|
153
|
+
Data Schema: ${schemaDescription}
|
|
154
|
+
|
|
155
|
+
Be precise and accurate. Extract only the data that is clearly present on the page.
|
|
156
|
+
If a field is not found or cannot be determined, use null for optional fields or your best judgment for required fields.`);
|
|
157
|
+
const extractionAgent = createAgent({
|
|
158
|
+
model: this.model,
|
|
159
|
+
tools: extractionTools,
|
|
160
|
+
systemPrompt: extractionSystemPrompt,
|
|
161
|
+
// No middleware - incompatible with structured output (providerStrategy)
|
|
162
|
+
responseFormat: providerStrategy(schema),
|
|
163
|
+
});
|
|
164
|
+
const response = await extractionAgent.invoke({
|
|
165
|
+
messages: [
|
|
166
|
+
new HumanMessage(`Extract data from the current page according to the schema.`),
|
|
167
|
+
],
|
|
168
|
+
}, {
|
|
169
|
+
recursionLimit: 15, // Limit iterations to prevent infinite loops
|
|
170
|
+
});
|
|
171
|
+
// Extract the structured output from the response
|
|
172
|
+
const extractedData = this.extractStructuredOutput(response, schema);
|
|
173
|
+
return extractedData;
|
|
174
|
+
}
|
|
83
175
|
async close() {
|
|
84
176
|
if (this.context) {
|
|
85
177
|
for (const page of this.context.pages()) {
|
|
@@ -94,6 +186,86 @@ export class AWAgent {
|
|
|
94
186
|
this.browser = null;
|
|
95
187
|
}
|
|
96
188
|
}
|
|
189
|
+
extractValidationResult(messages) {
|
|
190
|
+
// Find the ReturnValidationResult tool call in messages
|
|
191
|
+
// Iterate from the end to find the most recent tool call
|
|
192
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
193
|
+
const message = messages[i];
|
|
194
|
+
// Check if this is a tool message with the validation result
|
|
195
|
+
if (message instanceof ToolMessage &&
|
|
196
|
+
message.name === "ReturnValidationResult") {
|
|
197
|
+
try {
|
|
198
|
+
const content = JSON.parse(typeof message.content === "string"
|
|
199
|
+
? message.content
|
|
200
|
+
: JSON.stringify(message.content));
|
|
201
|
+
return content.result;
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
throw new Error(`Failed to parse validation result: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Also check tool calls in AI messages
|
|
208
|
+
if (message instanceof AIMessage &&
|
|
209
|
+
message.tool_calls &&
|
|
210
|
+
Array.isArray(message.tool_calls)) {
|
|
211
|
+
for (const toolCall of message.tool_calls) {
|
|
212
|
+
if (toolCall.name === "ReturnValidationResult" && toolCall.args) {
|
|
213
|
+
return toolCall.args
|
|
214
|
+
.result;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
throw new Error("Validation result not found in agent response. The agent did not call ReturnValidationResult.");
|
|
220
|
+
}
|
|
221
|
+
generateSchemaDescription(schema) {
|
|
222
|
+
// Convert Zod schema to JSON Schema for a clear, standard representation
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
|
|
224
|
+
const jsonSchema = zodToJsonSchema(schema, "extractionSchema");
|
|
225
|
+
return JSON.stringify(jsonSchema, null, 2);
|
|
226
|
+
}
|
|
227
|
+
extractStructuredOutput(response, schema) {
|
|
228
|
+
// With providerStrategy, the structured output should be in the last message
|
|
229
|
+
const lastMessage = response.messages[response.messages.length - 1];
|
|
230
|
+
if (lastMessage instanceof AIMessage) {
|
|
231
|
+
try {
|
|
232
|
+
// The structured output is typically in message.content or message.additional_kwargs
|
|
233
|
+
let structuredData;
|
|
234
|
+
// Check if content is already an object (structured output)
|
|
235
|
+
if (typeof lastMessage.content === "object" &&
|
|
236
|
+
lastMessage.content !== null) {
|
|
237
|
+
structuredData = lastMessage.content;
|
|
238
|
+
}
|
|
239
|
+
// Check additional_kwargs for structured output
|
|
240
|
+
else if (lastMessage.additional_kwargs?.structured_output) {
|
|
241
|
+
structuredData = lastMessage.additional_kwargs.structured_output;
|
|
242
|
+
}
|
|
243
|
+
// Try parsing content as JSON
|
|
244
|
+
else if (typeof lastMessage.content === "string") {
|
|
245
|
+
try {
|
|
246
|
+
structuredData = JSON.parse(lastMessage.content);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
throw new Error("Could not parse structured output from response");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Validate the extracted data against the schema
|
|
253
|
+
const validatedData = schema.parse(structuredData);
|
|
254
|
+
console.log("Data extracted and validated successfully");
|
|
255
|
+
return validatedData;
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
if (error instanceof z.ZodError) {
|
|
259
|
+
const errorMessages = error.issues
|
|
260
|
+
.map((e) => `${e.path.join(".")}: ${e.message}`)
|
|
261
|
+
.join(", ");
|
|
262
|
+
throw new Error(`Extracted data validation failed: ${errorMessages}`);
|
|
263
|
+
}
|
|
264
|
+
throw new Error(`Failed to extract structured output: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
throw new Error("No structured output found in agent response. Expected an AI message with structured data.");
|
|
268
|
+
}
|
|
97
269
|
createTools(page) {
|
|
98
270
|
return [
|
|
99
271
|
// Element ID-based tools (recommended for use with accessibility snapshots)
|
|
@@ -105,8 +277,8 @@ export class AWAgent {
|
|
|
105
277
|
// Other utility tools
|
|
106
278
|
waitTool(),
|
|
107
279
|
navigateTool(page),
|
|
108
|
-
getPageScreenShotTool(page),
|
|
109
|
-
clickByPositionTool(page),
|
|
280
|
+
// getPageScreenShotTool(page),
|
|
281
|
+
// clickByPositionTool(page),
|
|
110
282
|
printToConsoleTool(),
|
|
111
283
|
...this.customTools.map((buildTool) => buildTool(page)),
|
|
112
284
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AWAgent.js","sourceRoot":"","sources":["../../src/AWAgent/AWAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,YAAY,
|
|
1
|
+
{"version":3,"file":"AWAgent.js","sourceRoot":"","sources":["../../src/AWAgent/AWAgent.ts"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-4,4 +4,6 @@ export { tool as createTool } from "langchain";
|
|
|
4
4
|
export { type AgentTool } from "./AWAgent/AWAgent.types.js";
|
|
5
5
|
export { ElementLocatorRegistry } from "./tools/utils/element-registry.util.js";
|
|
6
6
|
export { type ElementSnapshot, type PageSnapshot, generateAccessibilitySnapshot, } from "./tools/utils/accessibility-snapshot.util.js";
|
|
7
|
+
export { validateConditionTool } from "./tools/validate-condition.tool.js";
|
|
8
|
+
export { extractDataTool } from "./tools/extract-data.tool.js";
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,KAAK,IAAI,IAAI,cAAc,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,6BAA6B,GAC9B,MAAM,8CAA8C,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,KAAK,IAAI,IAAI,cAAc,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,6BAA6B,GAC9B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { tool as createTool } from "langchain";
|
|
|
4
4
|
export {} from "./AWAgent/AWAgent.types.js";
|
|
5
5
|
export { ElementLocatorRegistry } from "./tools/utils/element-registry.util.js";
|
|
6
6
|
export { generateAccessibilitySnapshot, } from "./tools/utils/accessibility-snapshot.util.js";
|
|
7
|
+
export { validateConditionTool } from "./tools/validate-condition.tool.js";
|
|
8
|
+
export { extractDataTool } from "./tools/extract-data.tool.js";
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAA+B,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAGL,6BAA6B,GAC9B,MAAM,8CAA8C,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAA+B,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAChF,OAAO,EAGL,6BAA6B,GAC9B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare function extractDataTool(): import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
3
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
4
|
+
}, z.core.$strip>, {
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
}, {
|
|
7
|
+
data: Record<string, unknown>;
|
|
8
|
+
}, string>;
|
|
9
|
+
//# sourceMappingURL=extract-data.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-data.tool.d.ts","sourceRoot":"","sources":["../../src/tools/extract-data.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wBAAgB,eAAe;;;UAER,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;WAsB7C"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export function extractDataTool() {
|
|
4
|
+
return tool(({ data }) => {
|
|
5
|
+
console.log(`Data extracted successfully`);
|
|
6
|
+
console.log(`Extracted data:`, JSON.stringify(data, null, 2));
|
|
7
|
+
return JSON.stringify({ data });
|
|
8
|
+
}, {
|
|
9
|
+
name: "ReturnExtractedData",
|
|
10
|
+
description: `Use this tool to return the extracted data from the webpage after gathering all required information.
|
|
11
|
+
Call this tool once you have collected all the data fields according to the extraction schema.
|
|
12
|
+
This is a TERMINAL action - after calling this tool, your task is complete and you should not take any further actions.
|
|
13
|
+
|
|
14
|
+
The data parameter should be a JSON object containing all the fields specified in the extraction instructions.
|
|
15
|
+
Make sure all required fields are present and have the correct types.`,
|
|
16
|
+
schema: z.object({
|
|
17
|
+
data: z
|
|
18
|
+
.record(z.string(), z.unknown())
|
|
19
|
+
.describe("The extracted data as a JSON object with the specified fields"),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=extract-data.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-data.tool.js","sourceRoot":"","sources":["../../src/tools/extract-data.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CACT,CAAC,EAAE,IAAI,EAAqC,EAAE,EAAE;QAC9C,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IAClC,CAAC,EACD;QACE,IAAI,EAAE,qBAAqB;QAC3B,WAAW,EAAE;;;;;sEAKmD;QAChE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,IAAI,EAAE,CAAC;iBACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;iBAC/B,QAAQ,CACP,+DAA+D,CAChE;SACJ,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { type Page } from "playwright";
|
|
2
|
+
import { z } from "zod";
|
|
2
3
|
import { type ElementLocatorRegistry } from "./utils/element-registry.util.js";
|
|
3
|
-
export declare function getDOMSnapshotTool(page: Page, elementRegistry: ElementLocatorRegistry): import("langchain").
|
|
4
|
+
export declare function getDOMSnapshotTool(page: Page, elementRegistry: ElementLocatorRegistry): import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
5
|
+
extraTags: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
6
|
+
}, z.core.$strip>, {
|
|
7
|
+
extraTags?: string[];
|
|
8
|
+
}, {
|
|
9
|
+
extraTags?: string[] | undefined;
|
|
10
|
+
}, string>;
|
|
4
11
|
//# sourceMappingURL=get-DOM-snapshot.tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-DOM-snapshot.tool.d.ts","sourceRoot":"","sources":["../../src/tools/get-DOM-snapshot.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"get-DOM-snapshot.tool.d.ts","sourceRoot":"","sources":["../../src/tools/get-DOM-snapshot.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAE/E,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,IAAI,EACV,eAAe,EAAE,sBAAsB;;;gBAGI,MAAM,EAAE;;;WAwDpD"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { tool } from "langchain";
|
|
2
2
|
import {} from "playwright";
|
|
3
|
+
import { z } from "zod";
|
|
3
4
|
import { generateAccessibilitySnapshot } from "./utils/accessibility-snapshot.util.js";
|
|
4
5
|
import {} from "./utils/element-registry.util.js";
|
|
5
6
|
export function getDOMSnapshotTool(page, elementRegistry) {
|
|
6
|
-
return tool(async () => {
|
|
7
|
+
return tool(async ({ extraTags = [] }) => {
|
|
7
8
|
console.log("Taking accessibility-based DOM snapshot...");
|
|
9
|
+
if (extraTags.length > 0) {
|
|
10
|
+
console.log(` - Including extra tags: ${extraTags.join(", ")}`);
|
|
11
|
+
}
|
|
8
12
|
// Generate accessibility snapshot with visual metadata
|
|
9
|
-
const snapshot = await generateAccessibilitySnapshot(page, elementRegistry.getMap());
|
|
13
|
+
const snapshot = await generateAccessibilitySnapshot(page, elementRegistry.getMap(), extraTags);
|
|
10
14
|
// Convert to JSON string for the model
|
|
11
15
|
const snapshotJson = JSON.stringify(snapshot, null, 2);
|
|
12
16
|
const snapshotSize = new Blob([snapshotJson]).size;
|
|
@@ -20,7 +24,29 @@ export function getDOMSnapshotTool(page, elementRegistry) {
|
|
|
20
24
|
description: `Get an accessibility-based snapshot of the current webpage.
|
|
21
25
|
Returns a structured JSON representation with interactive elements, their roles, names, and visual properties.
|
|
22
26
|
Each element has a unique 'id' that can be used with action tools (ClickByElementId, InputByElementId).
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
By default, the snapshot includes only visible, interactive elements like buttons, links, text inputs, etc.
|
|
29
|
+
|
|
30
|
+
You can optionally include additional HTML elements by specifying their tag names in the 'extraTags' parameter.
|
|
31
|
+
This is useful for validation tasks that need to examine text content or specific elements.
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
- To include paragraph text: extraTags: ["p"]
|
|
35
|
+
- To include headings: extraTags: ["h1", "h2", "h3"]
|
|
36
|
+
- To include spans and divs: extraTags: ["span", "div"]
|
|
37
|
+
- To include multiple types: extraTags: ["p", "span", "h1", "h2", "label"]
|
|
38
|
+
|
|
39
|
+
Common tags you might want to include:
|
|
40
|
+
- Text content: "p", "span", "div"
|
|
41
|
+
- Headings: "h1", "h2", "h3", "h4", "h5", "h6"
|
|
42
|
+
- Lists: "li", "ul", "ol"
|
|
43
|
+
- Labels: "label"`,
|
|
44
|
+
schema: z.object({
|
|
45
|
+
extraTags: z
|
|
46
|
+
.array(z.string())
|
|
47
|
+
.default([])
|
|
48
|
+
.describe("Optional array of additional HTML tag names to include in the snapshot (e.g., ['p', 'span', 'h1']). Defaults to empty array."),
|
|
49
|
+
}),
|
|
24
50
|
});
|
|
25
51
|
}
|
|
26
52
|
//# sourceMappingURL=get-DOM-snapshot.tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-DOM-snapshot.tool.js","sourceRoot":"","sources":["../../src/tools/get-DOM-snapshot.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAA+B,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,kBAAkB,CAChC,IAAU,EACV,eAAuC;IAEvC,OAAO,IAAI,CACT,KAAK,
|
|
1
|
+
{"version":3,"file":"get-DOM-snapshot.tool.js","sourceRoot":"","sources":["../../src/tools/get-DOM-snapshot.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAA+B,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,kBAAkB,CAChC,IAAU,EACV,eAAuC;IAEvC,OAAO,IAAI,CACT,KAAK,EAAE,EAAE,SAAS,GAAG,EAAE,EAA4B,EAAE,EAAE;QACrD,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAC1D,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,6BAA6B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,uDAAuD;QACvD,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAClD,IAAI,EACJ,eAAe,CAAC,MAAM,EAAE,EACxB,SAAS,CACV,CAAC;QAEF,uCAAuC;QACvC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACvD,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QAEnD,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/D,OAAO,CAAC,GAAG,CAAC,sBAAsB,YAAY,QAAQ,CAAC,CAAC;QACxD,OAAO,CAAC,GAAG,CAAC,YAAY,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QAExC,OAAO,YAAY,CAAC;IACtB,CAAC,EACD;QACE,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE;;;;;;;;;;;;;;;;;;;kBAmBD;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,SAAS,EAAE,CAAC;iBACT,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;iBACjB,OAAO,CAAC,EAAE,CAAC;iBACX,QAAQ,CACP,8HAA8H,CAC/H;SACJ,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -9,7 +9,7 @@ export function navigateTool(page) {
|
|
|
9
9
|
name: "NavigateToURL",
|
|
10
10
|
description: "Navigate to a specified URL",
|
|
11
11
|
schema: z.object({
|
|
12
|
-
url: z.string().
|
|
12
|
+
url: z.string().describe("The URL to navigate to (e.g., https://example.com)"),
|
|
13
13
|
}),
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigate.tool.js","sourceRoot":"","sources":["../../src/tools/navigate.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAa,MAAM,YAAY,CAAC;AACvC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,CACT,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;QACzC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC,EACD;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"navigate.tool.js","sourceRoot":"","sources":["../../src/tools/navigate.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAa,MAAM,YAAY,CAAC;AACvC,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,OAAO,IAAI,CACT,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;QAChB,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;QACzC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC,EACD;QACE,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;SAC/E,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -29,6 +29,9 @@ export interface PageSnapshot {
|
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Generates an accessibility-based snapshot of the page with visual metadata
|
|
32
|
+
* @param page - The Playwright page to snapshot
|
|
33
|
+
* @param locatorMap - Map to store element locators
|
|
34
|
+
* @param extraTags - Optional array of additional HTML tags to include (e.g., ["p", "span", "h1"])
|
|
32
35
|
*/
|
|
33
|
-
export declare function generateAccessibilitySnapshot(page: Page, locatorMap: Map<string, Locator
|
|
36
|
+
export declare function generateAccessibilitySnapshot(page: Page, locatorMap: Map<string, Locator>, extraTags?: string[]): Promise<PageSnapshot>;
|
|
34
37
|
//# sourceMappingURL=accessibility-snapshot.util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility-snapshot.util.d.ts","sourceRoot":"","sources":["../../../src/tools/utils/accessibility-snapshot.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,IAAI,EACA;QACE,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,GACD,SAAS,CAAC;IACd,QAAQ,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAsGD
|
|
1
|
+
{"version":3,"file":"accessibility-snapshot.util.d.ts","sourceRoot":"","sources":["../../../src/tools/utils/accessibility-snapshot.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,IAAI,EACA;QACE,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,GACD,SAAS,CAAC;IACd,QAAQ,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAsGD;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,GAAE,MAAM,EAAO,GACvB,OAAO,CAAC,YAAY,CAAC,CAmOvB"}
|
|
@@ -73,14 +73,17 @@ async function enrichElement(page, elementData, locatorMap) {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Generates an accessibility-based snapshot of the page with visual metadata
|
|
76
|
+
* @param page - The Playwright page to snapshot
|
|
77
|
+
* @param locatorMap - Map to store element locators
|
|
78
|
+
* @param extraTags - Optional array of additional HTML tags to include (e.g., ["p", "span", "h1"])
|
|
76
79
|
*/
|
|
77
|
-
export async function generateAccessibilitySnapshot(page, locatorMap) {
|
|
80
|
+
export async function generateAccessibilitySnapshot(page, locatorMap, extraTags = []) {
|
|
78
81
|
// Reset counter for consistent IDs
|
|
79
82
|
elementIdCounter = 0;
|
|
80
83
|
// Clear previous locator map
|
|
81
84
|
locatorMap.clear();
|
|
82
85
|
// Extract all interactive elements with XPath locators
|
|
83
|
-
const elementsData = await page.evaluate(() => {
|
|
86
|
+
const elementsData = await page.evaluate((additionalTags) => {
|
|
84
87
|
const results = [];
|
|
85
88
|
function getXPath(element) {
|
|
86
89
|
if (element.id) {
|
|
@@ -139,6 +142,33 @@ export async function generateAccessibilitySnapshot(page, locatorMap) {
|
|
|
139
142
|
return "main";
|
|
140
143
|
if (tagName === "dialog")
|
|
141
144
|
return "dialog";
|
|
145
|
+
// Text content elements
|
|
146
|
+
if (tagName === "p")
|
|
147
|
+
return "paragraph";
|
|
148
|
+
if (tagName === "span")
|
|
149
|
+
return "text";
|
|
150
|
+
if (tagName === "div")
|
|
151
|
+
return "text";
|
|
152
|
+
if (tagName === "h1")
|
|
153
|
+
return "heading";
|
|
154
|
+
if (tagName === "h2")
|
|
155
|
+
return "heading";
|
|
156
|
+
if (tagName === "h3")
|
|
157
|
+
return "heading";
|
|
158
|
+
if (tagName === "h4")
|
|
159
|
+
return "heading";
|
|
160
|
+
if (tagName === "h5")
|
|
161
|
+
return "heading";
|
|
162
|
+
if (tagName === "h6")
|
|
163
|
+
return "heading";
|
|
164
|
+
if (tagName === "label")
|
|
165
|
+
return "label";
|
|
166
|
+
if (tagName === "li")
|
|
167
|
+
return "listitem";
|
|
168
|
+
if (tagName === "ul")
|
|
169
|
+
return "list";
|
|
170
|
+
if (tagName === "ol")
|
|
171
|
+
return "list";
|
|
142
172
|
return "generic";
|
|
143
173
|
}
|
|
144
174
|
function getName(element) {
|
|
@@ -164,10 +194,15 @@ export async function generateAccessibilitySnapshot(page, locatorMap) {
|
|
|
164
194
|
return (labels[0].textContent || "").trim();
|
|
165
195
|
}
|
|
166
196
|
}
|
|
197
|
+
// For text elements (p, span, div, headings), return text content
|
|
198
|
+
const tagName = element.tagName.toLowerCase();
|
|
199
|
+
if (["p", "span", "div", "h1", "h2", "h3", "h4", "h5", "h6", "label", "li"].includes(tagName)) {
|
|
200
|
+
return (element.textContent || "").trim().substring(0, 200);
|
|
201
|
+
}
|
|
167
202
|
return "";
|
|
168
203
|
}
|
|
169
204
|
// Find all interactive elements
|
|
170
|
-
const
|
|
205
|
+
const baseSelectors = [
|
|
171
206
|
"button",
|
|
172
207
|
"a[href]",
|
|
173
208
|
"input",
|
|
@@ -181,6 +216,8 @@ export async function generateAccessibilitySnapshot(page, locatorMap) {
|
|
|
181
216
|
"[role='combobox']",
|
|
182
217
|
"[onclick]",
|
|
183
218
|
];
|
|
219
|
+
// Add additional tags if provided
|
|
220
|
+
const selectors = [...baseSelectors, ...additionalTags];
|
|
184
221
|
const elements = document.querySelectorAll(selectors.join(", "));
|
|
185
222
|
elements.forEach((element) => {
|
|
186
223
|
const role = inferRole(element);
|
|
@@ -221,7 +258,7 @@ export async function generateAccessibilitySnapshot(page, locatorMap) {
|
|
|
221
258
|
});
|
|
222
259
|
});
|
|
223
260
|
return results;
|
|
224
|
-
});
|
|
261
|
+
}, extraTags);
|
|
225
262
|
// Get viewport size
|
|
226
263
|
const viewportSize = page.viewportSize() || { width: 1280, height: 800 };
|
|
227
264
|
// Enrich each element with visual metadata
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessibility-snapshot.util.js","sourceRoot":"","sources":["../../../src/tools/utils/accessibility-snapshot.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,YAAY,CAAC;AA8CrD,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,GAAG,IAAI,IAAI,gBAAgB,EAAE,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,IAAU,EACV,WAAwB,EACxB,UAAgC;IAEhC,MAAM,EAAE,GAAG,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC;QACH,6BAA6B;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;QAE3D,0BAA0B;QAC1B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,6BAA6B;QAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;QAEhC,8BAA8B;QAC9B,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAE5B,uBAAuB;QACvB,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,IAAI,CAAC,CAAC,6BAA6B;QAC5C,CAAC;QAED,mBAAmB;QACnB,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,C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AI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;oBAC5B,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;oBAC5B,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC;oBAChC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC;iBAClC;gBACH,CAAC,CAAC,SAAS;YACb,QAAQ,EAAE,SAAS;SACpB,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,2CAA2C;QAC3C,OAAO,CAAC,IAAI,CAAC,4BAA4B,WAAW,CAAC,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"accessibility-snapshot.util.js","sourceRoot":"","sources":["../../../src/tools/utils/accessibility-snapshot.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,MAAM,YAAY,CAAC;AA8CrD,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,GAAG,IAAI,IAAI,gBAAgB,EAAE,EAAE,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa,CAC1B,IAAU,EACV,WAAwB,EACxB,UAAgC;IAEhC,MAAM,EAAE,GAAG,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAE/C,IAAI,CAAC;QACH,6BAA6B;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC;QAE3D,0BAA0B;QAC1B,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,IA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AAE,SAAS,CAAC,CAAC;IAEd,oBAAoB;IACpB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAEzE,2CAA2C;IAC3C,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;QAC3E,IAAI,eAAe,EAAE,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QACf,QAAQ,EAAE;YACR,KAAK,EAAE,YAAY,CAAC,KAAK;YACzB,MAAM,EAAE,YAAY,CAAC,MAAM;SAC5B;QACD,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare function validateConditionTool(): import("langchain").DynamicStructuredTool<z.ZodObject<{
|
|
3
|
+
result: z.ZodBoolean;
|
|
4
|
+
reasoning: z.ZodString;
|
|
5
|
+
}, z.core.$strip>, {
|
|
6
|
+
result: boolean;
|
|
7
|
+
reasoning: string;
|
|
8
|
+
}, {
|
|
9
|
+
result: boolean;
|
|
10
|
+
reasoning: string;
|
|
11
|
+
}, string>;
|
|
12
|
+
//# sourceMappingURL=validate-condition.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-condition.tool.d.ts","sourceRoot":"","sources":["../../src/tools/validate-condition.tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wBAAgB,qBAAqB;;;;YAEC,OAAO;eAAa,MAAM;;;;WAoB/D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { tool } from "langchain";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export function validateConditionTool() {
|
|
4
|
+
return tool(({ result, reasoning }) => {
|
|
5
|
+
console.log(`Validation result: ${result}`);
|
|
6
|
+
console.log(`Reasoning: ${reasoning}`);
|
|
7
|
+
return JSON.stringify({ result, reasoning });
|
|
8
|
+
}, {
|
|
9
|
+
name: "ReturnValidationResult",
|
|
10
|
+
description: `Use this tool to return the final validation result after examining the page.
|
|
11
|
+
Call this tool once you have determined whether the condition is true or false.
|
|
12
|
+
This is a TERMINAL action - after calling this tool, your task is complete and you should not take any further actions.
|
|
13
|
+
|
|
14
|
+
Parameters:
|
|
15
|
+
- result: true if the condition is met, false otherwise
|
|
16
|
+
- reasoning: Brief explanation of why the condition is true/false`,
|
|
17
|
+
schema: z.object({
|
|
18
|
+
result: z.boolean().describe("Whether the condition is met"),
|
|
19
|
+
reasoning: z.string().describe("Brief explanation of the result"),
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=validate-condition.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-condition.tool.js","sourceRoot":"","sources":["../../src/tools/validate-condition.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,CACT,CAAC,EAAE,MAAM,EAAE,SAAS,EAA0C,EAAE,EAAE;QAChE,OAAO,CAAC,GAAG,CAAC,sBAAsB,MAAM,EAAE,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,cAAc,SAAS,EAAE,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/C,CAAC,EACD;QACE,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE;;;;;;kEAM+C;QAC5D,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;YACf,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;YAC5D,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;SAClE,CAAC;KACH,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bini-bar-labs/atomic-web-agent-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "The core of the Atomic Web Agent, providing essential functionalities for web interaction.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"dedent": "1.7.0",
|
|
60
60
|
"langchain": "1.1.1",
|
|
61
61
|
"playwright": "1.57.0",
|
|
62
|
-
"zod": "4.1.13"
|
|
62
|
+
"zod": "4.1.13",
|
|
63
|
+
"zod-to-json-schema": "^3.25.1"
|
|
63
64
|
}
|
|
64
65
|
}
|