Skip to content

Commit f0e3e3c

Browse files
Merge pull request #3 from auto-browse/feature_test_step
Feature: Wrapped tools in playwright steps to improve playwright results readability
2 parents dc2b4ea + 270046e commit f0e3e3c

24 files changed

+790
-609
lines changed

.github/workflows/publish.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish
2+
on:
3+
release:
4+
types: [published]
5+
jobs:
6+
publish-npm:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: read
10+
id-token: write
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: 18
16+
registry-url: https://registry.npmjs.org/
17+
cache: 'npm'
18+
19+
- run: npm ci
20+
- run: npm run build
21+
22+
- name: Lint
23+
run: npm run lint
24+
- name: Format check
25+
run: npm run format
26+
27+
- name: Check package version
28+
run: |
29+
PKG_VERSION=$(node -p "require('./package.json').version")
30+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
31+
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
32+
echo "Package version ($PKG_VERSION) does not match tag version ($TAG_VERSION)"
33+
exit 1
34+
fi
35+
36+
- run: npm publish --access public
37+
env:
38+
NODE_AUTH_TOKEN: ${{secrets.NPM}}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@auto-browse/auto-browse",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "AI-powered browser automation",
55
"author": "auto-browse",
66
"homepage": "https://www.auto-browse.com/",

src/auto.ts

+49-29
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
import { test as base } from '@playwright/test';
22
import { AutoConfig } from './types';
33
import { sessionManager, context } from './browser';
4-
import { createReactAgent } from "@langchain/langgraph/prebuilt";
5-
import { HumanMessage } from "@langchain/core/messages";
4+
import { createReactAgent } from '@langchain/langgraph/prebuilt';
5+
import { HumanMessage } from '@langchain/core/messages';
66
import { createLLMModel } from './llm';
77
import {
8-
browser_click, browser_type, browser_get_text, browser_navigate, browser_snapshot,
9-
browser_hover, browser_drag, browser_select_option, browser_take_screenshot,
10-
browser_go_back, browser_wait, browser_press_key, browser_save_pdf, browser_choose_file,
11-
browser_go_forward, browser_assert
8+
browser_click,
9+
browser_type,
10+
browser_get_text,
11+
browser_navigate,
12+
browser_snapshot,
13+
browser_hover,
14+
browser_drag,
15+
browser_select_option,
16+
browser_take_screenshot,
17+
browser_go_back,
18+
browser_wait,
19+
browser_press_key,
20+
browser_save_pdf,
21+
browser_choose_file,
22+
browser_go_forward,
23+
browser_assert,
1224
} from './tools';
1325

1426
// Extend base test to automatically track page
1527
export const test = base.extend({
1628
page: async ({ page }, use) => {
1729
sessionManager.setPage(page);
1830
await use(page);
19-
}
31+
},
2032
});
2133

2234
// Initialize the LangChain agent with more detailed instructions
2335
const initializeAgent = () => {
2436
const model = createLLMModel();
2537

26-
const prompt =
27-
`You are a web automation assistant. When given a natural language instruction:
38+
const prompt = `You are a web automation assistant. When given a natural language instruction:
2839
- Always call the snapshot tool first to analyze the page structure and elements, so you can understand the context ad the elements available on the page to perform the requested action
2940
- For "get" or "get text" instructions, use the getText tool to retrieve content
3041
- For "click" instructions, use the click tool to interact with elements
@@ -46,32 +57,43 @@ const initializeAgent = () => {
4657
const agent = createReactAgent({
4758
llm: model,
4859
tools: [
49-
browser_click, browser_type, browser_get_text, browser_navigate, browser_snapshot,
50-
browser_hover, browser_drag, browser_select_option, browser_take_screenshot,
51-
browser_go_back, browser_wait, browser_press_key, browser_save_pdf, browser_choose_file, browser_assert,
52-
browser_go_forward
60+
browser_click,
61+
browser_type,
62+
browser_get_text,
63+
browser_navigate,
64+
browser_snapshot,
65+
browser_hover,
66+
browser_drag,
67+
browser_select_option,
68+
browser_take_screenshot,
69+
browser_go_back,
70+
browser_wait,
71+
browser_press_key,
72+
browser_save_pdf,
73+
browser_choose_file,
74+
browser_assert,
75+
browser_go_forward,
5376
],
54-
stateModifier: prompt
77+
stateModifier: prompt,
5578
});
5679

5780
return { agent };
5881
};
5982

6083
// Main auto function that processes instructions
61-
export async function auto(instruction: string, config?: AutoConfig): Promise<any> {
84+
export async function auto(
85+
instruction: string,
86+
config?: AutoConfig,
87+
): Promise<any> {
6288
console.log(`[Auto] Processing instruction: "${instruction}"`);
6389

64-
if (config?.page)
65-
{
90+
if (config?.page) {
6691
sessionManager.setPage(config.page);
6792
console.log(`[Auto] Page set from config`);
68-
} else
69-
{
70-
try
71-
{
93+
} else {
94+
try {
7295
sessionManager.getPage();
73-
} catch
74-
{
96+
} catch {
7597
// In standalone mode, create a new page
7698
console.log(`[Auto] No existing page, creating new page`);
7799
await context.createPage();
@@ -82,19 +104,17 @@ export async function auto(instruction: string, config?: AutoConfig): Promise<an
82104
console.log(`[Auto] Creating agent for instruction`);
83105
const { agent } = initializeAgent();
84106
const result = await agent.invoke({
85-
messages: [new HumanMessage(instruction)]
107+
messages: [new HumanMessage(instruction)],
86108
});
87109

88-
console.log("Agent result:", result);
110+
console.log('Agent result:', result);
89111
// Process agent result
90112
const response = result.messages?.[-1]?.content;
91113
console.log(`[Auto] Agent response:`, response);
92114

93-
if (typeof response === 'string')
94-
{
115+
if (typeof response === 'string') {
95116
// If it's a success message, return null to match original behavior
96-
if (response.startsWith('Successfully'))
97-
{
117+
if (response.startsWith('Successfully')) {
98118
console.log(`[Auto] Detected success message, returning null`);
99119
return null;
100120
}

0 commit comments

Comments
 (0)