playwright-mimic 0.1.0 → 0.1.1
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 +633 -446
- package/dist/agentic/agent.d.ts +106 -0
- package/dist/agentic/agent.d.ts.map +1 -0
- package/dist/agentic/agent.js +528 -0
- package/dist/agentic/agent.js.map +1 -0
- package/dist/agentic/index.d.ts +13 -0
- package/dist/agentic/index.d.ts.map +1 -0
- package/dist/agentic/index.js +12 -0
- package/dist/agentic/index.js.map +1 -0
- package/dist/agentic/planner.d.ts +41 -0
- package/dist/agentic/planner.d.ts.map +1 -0
- package/dist/agentic/planner.js +136 -0
- package/dist/agentic/planner.js.map +1 -0
- package/dist/agentic/react.d.ts +35 -0
- package/dist/agentic/react.d.ts.map +1 -0
- package/dist/agentic/react.js +170 -0
- package/dist/agentic/react.js.map +1 -0
- package/dist/agentic/recovery.d.ts +55 -0
- package/dist/agentic/recovery.d.ts.map +1 -0
- package/dist/agentic/recovery.js +200 -0
- package/dist/agentic/recovery.js.map +1 -0
- package/dist/agentic/reflection.d.ts +40 -0
- package/dist/agentic/reflection.d.ts.map +1 -0
- package/dist/agentic/reflection.js +142 -0
- package/dist/agentic/reflection.js.map +1 -0
- package/dist/agentic/types.d.ts +177 -0
- package/dist/agentic/types.d.ts.map +1 -0
- package/dist/agentic/types.js +8 -0
- package/dist/agentic/types.js.map +1 -0
- package/dist/agentic/wait.d.ts +50 -0
- package/dist/agentic/wait.d.ts.map +1 -0
- package/dist/agentic/wait.js +140 -0
- package/dist/agentic/wait.js.map +1 -0
- package/dist/agentic-mimic.d.ts +56 -0
- package/dist/agentic-mimic.d.ts.map +1 -0
- package/dist/agentic-mimic.js +98 -0
- package/dist/agentic-mimic.js.map +1 -0
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -9
- package/dist/index.js.map +1 -1
- package/dist/mimic/actionType.d.ts +7 -0
- package/dist/mimic/actionType.d.ts.map +1 -0
- package/dist/mimic/actionType.js +44 -0
- package/dist/mimic/actionType.js.map +1 -0
- package/dist/mimic/annotations.d.ts +20 -0
- package/dist/mimic/annotations.d.ts.map +1 -0
- package/dist/mimic/annotations.js +30 -0
- package/dist/mimic/annotations.js.map +1 -0
- package/dist/mimic/cli.d.ts +15 -0
- package/dist/mimic/cli.d.ts.map +1 -0
- package/dist/mimic/cli.js +17 -0
- package/dist/mimic/cli.js.map +1 -0
- package/dist/mimic/click.d.ts +39 -0
- package/dist/mimic/click.d.ts.map +1 -0
- package/dist/mimic/click.js +233 -0
- package/dist/mimic/click.js.map +1 -0
- package/dist/mimic/forms.d.ts +47 -0
- package/dist/mimic/forms.d.ts.map +1 -0
- package/dist/mimic/forms.js +264 -0
- package/dist/mimic/forms.js.map +1 -0
- package/dist/mimic/navigation.d.ts +19 -0
- package/dist/mimic/navigation.d.ts.map +1 -0
- package/dist/mimic/navigation.js +117 -0
- package/dist/mimic/navigation.js.map +1 -0
- package/dist/mimic/replay.d.ts +21 -0
- package/dist/mimic/replay.d.ts.map +1 -0
- package/dist/mimic/replay.js +133 -0
- package/dist/mimic/replay.js.map +1 -0
- package/dist/mimic/schema/action.d.ts +315 -0
- package/dist/mimic/schema/action.d.ts.map +1 -0
- package/dist/mimic/schema/action.js +204 -0
- package/dist/mimic/schema/action.js.map +1 -0
- package/dist/mimic/selector.d.ts +139 -0
- package/dist/mimic/selector.d.ts.map +1 -0
- package/dist/mimic/selector.js +1103 -0
- package/dist/mimic/selector.js.map +1 -0
- package/dist/mimic/selectorDescriptor.d.ts +13 -0
- package/dist/mimic/selectorDescriptor.d.ts.map +1 -0
- package/dist/mimic/selectorDescriptor.js +9 -0
- package/dist/mimic/selectorDescriptor.js.map +1 -0
- package/dist/mimic/selectorSerialization.d.ts +30 -0
- package/dist/mimic/selectorSerialization.d.ts.map +1 -0
- package/dist/mimic/selectorSerialization.js +170 -0
- package/dist/mimic/selectorSerialization.js.map +1 -0
- package/dist/mimic/selectorTypes.d.ts +200 -0
- package/dist/mimic/selectorTypes.d.ts.map +1 -0
- package/dist/mimic/selectorTypes.js +2 -0
- package/dist/mimic/selectorTypes.js.map +1 -0
- package/dist/mimic/selectorUtils.d.ts +26 -0
- package/dist/mimic/selectorUtils.d.ts.map +1 -0
- package/dist/mimic/selectorUtils.js +144 -0
- package/dist/mimic/selectorUtils.js.map +1 -0
- package/dist/mimic/storage.d.ts +75 -0
- package/dist/mimic/storage.d.ts.map +1 -0
- package/dist/mimic/storage.js +197 -0
- package/dist/mimic/storage.js.map +1 -0
- package/dist/mimic/types.d.ts +63 -0
- package/dist/mimic/types.d.ts.map +1 -0
- package/dist/mimic/types.js +7 -0
- package/dist/mimic/types.js.map +1 -0
- package/dist/mimic.d.ts +28 -4
- package/dist/mimic.d.ts.map +1 -1
- package/dist/mimic.js +374 -32
- package/dist/mimic.js.map +1 -1
- package/dist/mimicry.d.ts +4 -4
- package/dist/mimicry.d.ts.map +1 -1
- package/dist/mimicry.js +22 -13
- package/dist/mimicry.js.map +1 -1
- package/package.json +5 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic System Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Exports for the agentic browser automation system.
|
|
5
|
+
*/
|
|
6
|
+
export { Agent } from './agent.js';
|
|
7
|
+
export type { AgentState, AgentConfig, ActionRecord, ActionReflection, PlanningResult, PlanStep, ReasoningResult, DecidedAction, ErrorRecord, } from './types.js';
|
|
8
|
+
export { createPlan, refinePlan } from './planner.js';
|
|
9
|
+
export { reasonAndDecide, validateAction } from './react.js';
|
|
10
|
+
export { reflectOnAction, reflectOnProgress } from './reflection.js';
|
|
11
|
+
export { determineRecoveryStrategy, classifyError, getRetryDelay, shouldRetryBasedOnError } from './recovery.js';
|
|
12
|
+
export { smartWait, waitForLoadersToDisappear, detectLoadingIndicators, isPageLoading, } from './wait.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agentic/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EACV,UAAU,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,eAAe,EACf,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,aAAa,EACb,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,GACd,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic System Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Exports for the agentic browser automation system.
|
|
5
|
+
*/
|
|
6
|
+
export { Agent } from './agent.js';
|
|
7
|
+
export { createPlan, refinePlan } from './planner.js';
|
|
8
|
+
export { reasonAndDecide, validateAction } from './react.js';
|
|
9
|
+
export { reflectOnAction, reflectOnProgress } from './reflection.js';
|
|
10
|
+
export { determineRecoveryStrategy, classifyError, getRetryDelay, shouldRetryBasedOnError } from './recovery.js';
|
|
11
|
+
export { smartWait, waitForLoadersToDisappear, detectLoadingIndicators, isPageLoading, } from './wait.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agentic/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAYnC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,aAAa,EACb,aAAa,EACb,uBAAuB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,GACd,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning Module
|
|
3
|
+
*
|
|
4
|
+
* Implements the Planning Pattern for agentic systems.
|
|
5
|
+
* Breaks down high-level goals into actionable steps with dependencies.
|
|
6
|
+
*/
|
|
7
|
+
import { type LanguageModel } from 'ai';
|
|
8
|
+
import type { PlanningResult } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create an execution plan from a high-level goal
|
|
11
|
+
*
|
|
12
|
+
* Uses AI to decompose a goal into actionable steps with dependencies,
|
|
13
|
+
* success criteria, and risk assessment.
|
|
14
|
+
*
|
|
15
|
+
* @param brain - Language model for planning
|
|
16
|
+
* @param goal - High-level goal or objective
|
|
17
|
+
* @param currentState - Current state of the page/agent (optional)
|
|
18
|
+
* @returns Promise resolving to a structured plan
|
|
19
|
+
*/
|
|
20
|
+
export declare function createPlan(brain: LanguageModel, goal: string, currentState?: {
|
|
21
|
+
url?: string;
|
|
22
|
+
pageTitle?: string;
|
|
23
|
+
availableElements?: number;
|
|
24
|
+
}): Promise<PlanningResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Refine a plan based on execution feedback
|
|
27
|
+
*
|
|
28
|
+
* Updates the plan when steps fail or when new information is discovered.
|
|
29
|
+
*
|
|
30
|
+
* @param brain - Language model for planning
|
|
31
|
+
* @param originalPlan - The original plan that needs refinement
|
|
32
|
+
* @param feedback - Feedback from execution (failures, discoveries, etc.)
|
|
33
|
+
* @returns Promise resolving to a refined plan
|
|
34
|
+
*/
|
|
35
|
+
export declare function refinePlan(brain: LanguageModel, originalPlan: PlanningResult, feedback: {
|
|
36
|
+
failedStep?: number;
|
|
37
|
+
failureReason?: string;
|
|
38
|
+
discoveredInfo?: string;
|
|
39
|
+
currentState?: string;
|
|
40
|
+
}): Promise<PlanningResult>;
|
|
41
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../src/agentic/planner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAC;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAwBjD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GACA,OAAO,CAAC,cAAc,CAAC,CA2DzB;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,KAAK,EAAE,aAAa,EACpB,YAAY,EAAE,cAAc,EAC5B,QAAQ,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACA,OAAO,CAAC,cAAc,CAAC,CAgCzB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning Module
|
|
3
|
+
*
|
|
4
|
+
* Implements the Planning Pattern for agentic systems.
|
|
5
|
+
* Breaks down high-level goals into actionable steps with dependencies.
|
|
6
|
+
*/
|
|
7
|
+
import { generateText, Output } from 'ai';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { countTokens } from '../utils/token-counter.js';
|
|
10
|
+
/**
|
|
11
|
+
* Schema for planning result validation
|
|
12
|
+
*
|
|
13
|
+
* Note: All fields must be required (no .default()) for AI SDK structured output compatibility.
|
|
14
|
+
* Empty arrays should be provided by the AI model when there are no values.
|
|
15
|
+
*/
|
|
16
|
+
const zPlanStep = z.object({
|
|
17
|
+
order: z.number().int().positive().describe('Step number in execution order'),
|
|
18
|
+
description: z.string().describe('Clear description of what this step should accomplish'),
|
|
19
|
+
expectedActionType: z.enum(['navigation', 'click', 'form', 'assertion', 'wait']).describe('Type of action expected for this step'),
|
|
20
|
+
successCriteria: z.string().describe('How to determine if this step was successful'),
|
|
21
|
+
dependencies: z.array(z.number().int().positive()).describe('Step numbers this step depends on (provide empty array [] if no dependencies)'),
|
|
22
|
+
});
|
|
23
|
+
const zPlanningResult = z.object({
|
|
24
|
+
steps: z.array(zPlanStep).min(1).describe('Ordered list of steps to achieve the goal'),
|
|
25
|
+
complexity: z.enum(['low', 'medium', 'high']).describe('Estimated complexity of the overall plan'),
|
|
26
|
+
challenges: z.array(z.string()).describe('Potential challenges or risks identified (provide empty array [] if none)'),
|
|
27
|
+
prerequisites: z.array(z.string()).describe('Prerequisites or requirements before starting (provide empty array [] if none)'),
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Create an execution plan from a high-level goal
|
|
31
|
+
*
|
|
32
|
+
* Uses AI to decompose a goal into actionable steps with dependencies,
|
|
33
|
+
* success criteria, and risk assessment.
|
|
34
|
+
*
|
|
35
|
+
* @param brain - Language model for planning
|
|
36
|
+
* @param goal - High-level goal or objective
|
|
37
|
+
* @param currentState - Current state of the page/agent (optional)
|
|
38
|
+
* @returns Promise resolving to a structured plan
|
|
39
|
+
*/
|
|
40
|
+
export async function createPlan(brain, goal, currentState) {
|
|
41
|
+
const stateContext = currentState
|
|
42
|
+
? `
|
|
43
|
+
Current State:
|
|
44
|
+
- URL: ${currentState.url || 'unknown'}
|
|
45
|
+
- Page Title: ${currentState.pageTitle || 'unknown'}
|
|
46
|
+
- Available Interactive Elements: ${currentState.availableElements || 0}
|
|
47
|
+
`
|
|
48
|
+
: '';
|
|
49
|
+
const prompt = `You are an expert test automation planner specializing in browser automation using Playwright.
|
|
50
|
+
|
|
51
|
+
Your task is to break down a high-level goal into a structured, executable plan.
|
|
52
|
+
|
|
53
|
+
**Goal:**
|
|
54
|
+
${goal}
|
|
55
|
+
|
|
56
|
+
${stateContext}
|
|
57
|
+
|
|
58
|
+
**Instructions:**
|
|
59
|
+
1. Break the goal into logical, sequential steps
|
|
60
|
+
2. Each step should be:
|
|
61
|
+
- Specific and actionable
|
|
62
|
+
- Have clear success criteria
|
|
63
|
+
- Identify dependencies on previous steps
|
|
64
|
+
- Specify the expected action type (navigation, click, form, assertion, wait)
|
|
65
|
+
3. Consider potential challenges (dynamic content, timing issues, element availability)
|
|
66
|
+
4. Identify any prerequisites (e.g., "must be logged in", "must be on specific page")
|
|
67
|
+
5. Assess overall complexity (low: 1-3 steps, medium: 4-7 steps, high: 8+ steps or complex interactions)
|
|
68
|
+
|
|
69
|
+
**Action Types:**
|
|
70
|
+
- navigation: Moving to a new page or URL
|
|
71
|
+
- click: Clicking buttons, links, or interactive elements
|
|
72
|
+
- form: Filling forms, selecting options, entering data
|
|
73
|
+
- assertion: Verifying state, content, or conditions
|
|
74
|
+
- wait: Waiting for conditions, loading, or timing
|
|
75
|
+
|
|
76
|
+
**Output Format:**
|
|
77
|
+
Return a structured plan with:
|
|
78
|
+
- Ordered steps (each with description, expected action type, success criteria, dependencies)
|
|
79
|
+
- dependencies: array of step numbers this step depends on (use empty array [] if no dependencies)
|
|
80
|
+
- Overall complexity assessment
|
|
81
|
+
- Potential challenges (use empty array [] if none)
|
|
82
|
+
- Prerequisites (use empty array [] if none)
|
|
83
|
+
|
|
84
|
+
**Important:** Always provide all fields, including empty arrays [] when there are no dependencies, challenges, or prerequisites.
|
|
85
|
+
|
|
86
|
+
Think step-by-step and create a comprehensive plan.`;
|
|
87
|
+
const result = await generateText({
|
|
88
|
+
model: brain,
|
|
89
|
+
prompt,
|
|
90
|
+
maxRetries: 3,
|
|
91
|
+
output: Output.object({ schema: zPlanningResult, name: 'executionPlan' }),
|
|
92
|
+
});
|
|
93
|
+
await countTokens(result);
|
|
94
|
+
return result.output;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Refine a plan based on execution feedback
|
|
98
|
+
*
|
|
99
|
+
* Updates the plan when steps fail or when new information is discovered.
|
|
100
|
+
*
|
|
101
|
+
* @param brain - Language model for planning
|
|
102
|
+
* @param originalPlan - The original plan that needs refinement
|
|
103
|
+
* @param feedback - Feedback from execution (failures, discoveries, etc.)
|
|
104
|
+
* @returns Promise resolving to a refined plan
|
|
105
|
+
*/
|
|
106
|
+
export async function refinePlan(brain, originalPlan, feedback) {
|
|
107
|
+
const prompt = `You are refining an execution plan based on feedback from execution.
|
|
108
|
+
|
|
109
|
+
**Original Plan:**
|
|
110
|
+
${JSON.stringify(originalPlan, null, 2)}
|
|
111
|
+
|
|
112
|
+
**Execution Feedback:**
|
|
113
|
+
${feedback.failedStep ? `Step ${feedback.failedStep} failed: ${feedback.failureReason}` : ''}
|
|
114
|
+
${feedback.discoveredInfo ? `New information discovered: ${feedback.discoveredInfo}` : ''}
|
|
115
|
+
${feedback.currentState ? `Current state: ${feedback.currentState}` : ''}
|
|
116
|
+
|
|
117
|
+
**Instructions:**
|
|
118
|
+
1. Analyze why the plan failed or what new information was discovered
|
|
119
|
+
2. Refine the plan by:
|
|
120
|
+
- Adjusting failed steps (fix approach, add prerequisites, break into smaller steps)
|
|
121
|
+
- Adding new steps if needed based on discoveries
|
|
122
|
+
- Updating dependencies if step order needs to change
|
|
123
|
+
- Revising complexity assessment if needed
|
|
124
|
+
3. Maintain the overall goal while adapting to new information
|
|
125
|
+
|
|
126
|
+
Return a refined plan that addresses the feedback.`;
|
|
127
|
+
const result = await generateText({
|
|
128
|
+
model: brain,
|
|
129
|
+
prompt,
|
|
130
|
+
maxRetries: 3,
|
|
131
|
+
output: Output.object({ schema: zPlanningResult, name: 'refinedPlan' }),
|
|
132
|
+
});
|
|
133
|
+
await countTokens(result);
|
|
134
|
+
return result.output;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=planner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.js","sourceRoot":"","sources":["../../src/agentic/planner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAsB,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD;;;;;GAKG;AACH,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;IAC7E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,uDAAuD,CAAC;IACzF,kBAAkB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,uCAAuC,CAAC;IAClI,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8CAA8C,CAAC;IACpF,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,+EAA+E,CAAC;CAC7I,CAAC,CAAC;AAEH,M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;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,KAAoB,EACpB,YAA4B,EAC5B,QAKC;IAED,MAAM,MAAM,GAAG;;;EAGf,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;;;EAGrC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,QAAQ,CAAC,UAAU,YAAY,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE;EAC1F,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,+BAA+B,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE;EACvF,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,kBAAkB,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;mDAWrB,CAAC;IAElD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;QAChC,KAAK,EAAE,KAAK;QACZ,MAAM;QACN,UAAU,EAAE,CAAC;QACb,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;KACxE,CAAC,CAAC;IAEH,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAE1B,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReAct Module (Reasoning and Acting)
|
|
3
|
+
*
|
|
4
|
+
* Implements the ReAct pattern: combines reasoning with real-time action execution.
|
|
5
|
+
* The agent observes, thinks, and decides what action to take next.
|
|
6
|
+
*/
|
|
7
|
+
import { type LanguageModel } from 'ai';
|
|
8
|
+
import type { ReasoningResult, DecidedAction, AgentState } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Reason about the current state and decide on the next action
|
|
11
|
+
*
|
|
12
|
+
* Implements the ReAct pattern: Observe → Think → Act
|
|
13
|
+
*
|
|
14
|
+
* @param brain - Language model for reasoning
|
|
15
|
+
* @param state - Current agent state
|
|
16
|
+
* @param currentStep - Current step from the plan (if planning is enabled)
|
|
17
|
+
* @returns Promise resolving to reasoning result with decided action
|
|
18
|
+
*/
|
|
19
|
+
export declare function reasonAndDecide(brain: LanguageModel, state: AgentState, currentStep?: {
|
|
20
|
+
description: string;
|
|
21
|
+
expectedActionType: string;
|
|
22
|
+
successCriteria: string;
|
|
23
|
+
}): Promise<ReasoningResult>;
|
|
24
|
+
/**
|
|
25
|
+
* Validate that a decided action is feasible given the current state
|
|
26
|
+
*
|
|
27
|
+
* @param action - The action to validate
|
|
28
|
+
* @param state - Current agent state
|
|
29
|
+
* @returns Whether the action is feasible and why
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateAction(action: DecidedAction, state: AgentState): {
|
|
32
|
+
feasible: boolean;
|
|
33
|
+
reason: string;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/agentic/react.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAC;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAsB7E;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,UAAU,EACjB,WAAW,CAAC,EAAE;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;CACzB,GACA,OAAO,CAAC,eAAe,CAAC,CAsF1B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,GAAG;IACxE,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAqDA"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ReAct Module (Reasoning and Acting)
|
|
3
|
+
*
|
|
4
|
+
* Implements the ReAct pattern: combines reasoning with real-time action execution.
|
|
5
|
+
* The agent observes, thinks, and decides what action to take next.
|
|
6
|
+
*/
|
|
7
|
+
import { generateText, Output } from 'ai';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { countTokens } from '../utils/token-counter.js';
|
|
10
|
+
/**
|
|
11
|
+
* Schema for reasoning result validation
|
|
12
|
+
*/
|
|
13
|
+
const zDecidedAction = z.object({
|
|
14
|
+
type: z.enum(['navigation', 'click', 'form', 'assertion', 'wait', 'retry', 'abort']).describe('Type of action to take'),
|
|
15
|
+
description: z.string().describe('Human-readable description of the action'),
|
|
16
|
+
parameters: z.record(z.string(), z.unknown()).describe('Parameters needed to execute this action'),
|
|
17
|
+
expectedOutcome: z.string().describe('What should happen after this action'),
|
|
18
|
+
rationale: z.string().describe('Why this action was chosen'),
|
|
19
|
+
});
|
|
20
|
+
const zReasoningResult = z.object({
|
|
21
|
+
observation: z.string().describe('What the agent observed about the current state'),
|
|
22
|
+
thought: z.string().describe('What the agent is thinking about the situation'),
|
|
23
|
+
action: zDecidedAction.describe('The action the agent decided to take'),
|
|
24
|
+
confidence: z.number().min(0).max(1).describe('Confidence level in this decision (0-1)'),
|
|
25
|
+
alternatives: z.array(zDecidedAction).default([]).describe('Alternative actions that were considered'),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Reason about the current state and decide on the next action
|
|
29
|
+
*
|
|
30
|
+
* Implements the ReAct pattern: Observe → Think → Act
|
|
31
|
+
*
|
|
32
|
+
* @param brain - Language model for reasoning
|
|
33
|
+
* @param state - Current agent state
|
|
34
|
+
* @param currentStep - Current step from the plan (if planning is enabled)
|
|
35
|
+
* @returns Promise resolving to reasoning result with decided action
|
|
36
|
+
*/
|
|
37
|
+
export async function reasonAndDecide(brain, state, currentStep) {
|
|
38
|
+
// Build context from state
|
|
39
|
+
const actionHistory = state.actionHistory
|
|
40
|
+
.slice(-5) // Last 5 actions for context
|
|
41
|
+
.map(a => `- ${a.description} (${a.success ? 'success' : 'failed'})`)
|
|
42
|
+
.join('\n');
|
|
43
|
+
const recentErrors = state.errors
|
|
44
|
+
.slice(-3) // Last 3 errors
|
|
45
|
+
.map(e => `- ${e.type}: ${e.message}`)
|
|
46
|
+
.join('\n');
|
|
47
|
+
const stepContext = currentStep
|
|
48
|
+
? `
|
|
49
|
+
**Current Plan Step:**
|
|
50
|
+
- Description: ${currentStep.description}
|
|
51
|
+
- Expected Action Type: ${currentStep.expectedActionType}
|
|
52
|
+
- Success Criteria: ${currentStep.successCriteria}
|
|
53
|
+
`
|
|
54
|
+
: '';
|
|
55
|
+
const prompt = `You are an intelligent browser automation agent using the ReAct (Reasoning and Acting) pattern.
|
|
56
|
+
|
|
57
|
+
**Your Goal:**
|
|
58
|
+
${state.overallObjective}
|
|
59
|
+
|
|
60
|
+
**Current State:**
|
|
61
|
+
- URL: ${state.currentUrl}
|
|
62
|
+
- Page Title: ${state.pageTitle}
|
|
63
|
+
- Available Interactive Elements: ${state.availableElements.length}
|
|
64
|
+
- Actions Taken: ${state.actionHistory.length}
|
|
65
|
+
- Goal Achieved: ${state.goalAchieved ? 'Yes' : 'No'}
|
|
66
|
+
- Page Loading: ${state.isLoading ? `Yes (${state.loadingIndicatorCount} indicator(s) visible)` : 'No'}
|
|
67
|
+
|
|
68
|
+
${stepContext}
|
|
69
|
+
|
|
70
|
+
**Recent Action History:**
|
|
71
|
+
${actionHistory || 'No actions taken yet'}
|
|
72
|
+
|
|
73
|
+
**Recent Errors:**
|
|
74
|
+
${recentErrors || 'No errors'}
|
|
75
|
+
|
|
76
|
+
**Available Elements Summary:**
|
|
77
|
+
${state.availableElements.slice(0, 10).map((el, i) => `${i + 1}. ${el.tag} - ${el.text || el.ariaLabel || el.label || 'no text'}`).join('\n')}
|
|
78
|
+
${state.availableElements.length > 10 ? `... and ${state.availableElements.length - 10} more` : ''}
|
|
79
|
+
|
|
80
|
+
**Instructions:**
|
|
81
|
+
1. **Observe**: Analyze the current state - what do you see? What's the situation?
|
|
82
|
+
2. **Think**: What should you do next? Consider:
|
|
83
|
+
- Are you closer to the goal?
|
|
84
|
+
- What actions are available?
|
|
85
|
+
- What worked or didn't work before?
|
|
86
|
+
- What's the best next step?
|
|
87
|
+
3. **Act**: Decide on a specific action to take:
|
|
88
|
+
- navigation: Navigate to a URL
|
|
89
|
+
- click: Click on an element (specify which one in parameters)
|
|
90
|
+
- form: Fill a form field (specify field and value in parameters)
|
|
91
|
+
- assertion: Verify something (specify what to check in parameters)
|
|
92
|
+
- wait: Wait for loading to complete or a specific condition
|
|
93
|
+
* Use wait when you detect loading indicators, need to wait for dynamic content,
|
|
94
|
+
or after actions that might trigger async operations
|
|
95
|
+
* Parameters: waitType ("smart" to detect loaders, "fixed" for fixed timeout, "network" for network idle)
|
|
96
|
+
* duration: fallback timeout in ms (default: 2000)
|
|
97
|
+
* loaderTimeout: max time to wait for loaders (default: 10000)
|
|
98
|
+
- retry: Retry a previous action with modifications
|
|
99
|
+
- abort: Give up if goal seems unachievable
|
|
100
|
+
|
|
101
|
+
**Important**: If you see loading indicators, spinners, or expect dynamic content to load after an action, use a "wait" action. The system will automatically detect and wait for loading indicators to disappear.
|
|
102
|
+
|
|
103
|
+
4. Consider alternatives - what other actions could work?
|
|
104
|
+
5. Assess your confidence in this decision
|
|
105
|
+
|
|
106
|
+
Think step-by-step using the ReAct pattern: Observe → Think → Act.`;
|
|
107
|
+
const result = await generateText({
|
|
108
|
+
model: brain,
|
|
109
|
+
prompt,
|
|
110
|
+
maxRetries: 3,
|
|
111
|
+
output: Output.object({ schema: zReasoningResult, name: 'reasoningResult' }),
|
|
112
|
+
});
|
|
113
|
+
await countTokens(result);
|
|
114
|
+
return result.output;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Validate that a decided action is feasible given the current state
|
|
118
|
+
*
|
|
119
|
+
* @param action - The action to validate
|
|
120
|
+
* @param state - Current agent state
|
|
121
|
+
* @returns Whether the action is feasible and why
|
|
122
|
+
*/
|
|
123
|
+
export function validateAction(action, state) {
|
|
124
|
+
// Check if we've exceeded max actions
|
|
125
|
+
if (state.metadata.stepCount > (state.metadata.stepCount + 100)) {
|
|
126
|
+
return {
|
|
127
|
+
feasible: false,
|
|
128
|
+
reason: 'Maximum action limit reached',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Check if goal is already achieved
|
|
132
|
+
if (state.goalAchieved && action.type !== 'assertion') {
|
|
133
|
+
return {
|
|
134
|
+
feasible: false,
|
|
135
|
+
reason: 'Goal already achieved, no further actions needed',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Validate action-specific requirements
|
|
139
|
+
switch (action.type) {
|
|
140
|
+
case 'navigation':
|
|
141
|
+
if (!action.parameters.url) {
|
|
142
|
+
return {
|
|
143
|
+
feasible: false,
|
|
144
|
+
reason: 'Navigation action requires a URL parameter',
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case 'click':
|
|
149
|
+
if (state.availableElements.length === 0) {
|
|
150
|
+
return {
|
|
151
|
+
feasible: false,
|
|
152
|
+
reason: 'No clickable elements available on the page',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case 'form':
|
|
157
|
+
if (state.availableElements.filter(el => el.tag === 'input' || el.tag === 'textarea' || el.tag === 'select').length === 0) {
|
|
158
|
+
return {
|
|
159
|
+
feasible: false,
|
|
160
|
+
reason: 'No form elements available on the page',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
feasible: true,
|
|
167
|
+
reason: 'Action is feasible',
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sour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+
*/
|
|
6
|
+
import { type LanguageModel } from 'ai';
|
|
7
|
+
import type { ErrorRecord, ActionRecord, AgentState } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Analyze an error and determine recovery strategy
|
|
10
|
+
*
|
|
11
|
+
* @param brain - Language model for recovery planning
|
|
12
|
+
* @param error - The error that occurred
|
|
13
|
+
* @param failedAction - The action that failed
|
|
14
|
+
* @param state - Current agent state
|
|
15
|
+
* @returns Promise resolving to recovery strategy
|
|
16
|
+
*/
|
|
17
|
+
export declare function determineRecoveryStrategy(brain: LanguageModel, error: ErrorRecord, failedAction: ActionRecord, state: AgentState): Promise<{
|
|
18
|
+
shouldRetry: boolean;
|
|
19
|
+
retryAction?: string;
|
|
20
|
+
alternativeApproach?: string;
|
|
21
|
+
skipAndContinue: boolean;
|
|
22
|
+
abort: boolean;
|
|
23
|
+
reasoning: string;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Classify error type for appropriate recovery
|
|
27
|
+
*
|
|
28
|
+
* @param error - The error record
|
|
29
|
+
* @returns Error classification
|
|
30
|
+
*/
|
|
31
|
+
export declare function classifyError(error: ErrorRecord): {
|
|
32
|
+
category: 'transient' | 'permanent' | 'environment' | 'logic' | 'unknown';
|
|
33
|
+
recoverable: boolean;
|
|
34
|
+
suggestedWait?: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Get retry delay based on attempt number
|
|
38
|
+
*
|
|
39
|
+
* Implements exponential backoff for retries.
|
|
40
|
+
*
|
|
41
|
+
* @param attemptNumber - Current retry attempt (1-based)
|
|
42
|
+
* @param baseDelay - Base delay in milliseconds (default: 1000)
|
|
43
|
+
* @returns Delay in milliseconds
|
|
44
|
+
*/
|
|
45
|
+
export declare function getRetryDelay(attemptNumber: number, baseDelay?: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Check if an action should be retried based on error classification
|
|
48
|
+
*
|
|
49
|
+
* @param error - The error that occurred
|
|
50
|
+
* @param retryCount - Number of times this action has been retried
|
|
51
|
+
* @param maxRetries - Maximum number of retries allowed
|
|
52
|
+
* @returns Whether to retry
|
|
53
|
+
*/
|
|
54
|
+
export declare function shouldRetryBasedOnError(error: ErrorRecord, retryCount: number, maxRetries: number): boolean;
|
|
55
|
+
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../src/agentic/recovery.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAwB,MAAM,IAAI,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAexE;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC;IACT,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAkFD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG;IACjD,QAAQ,EAAE,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,OAAO,GAAG,SAAS,CAAC;IAC1E,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CA+DA;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,GAAG,MAAM,CAIrF;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CA4BT"}
|