veil-browser 0.1.7 → 0.1.8
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/dist/ai.js +37 -16
- package/package.json +1 -1
package/dist/ai.js
CHANGED
|
@@ -81,30 +81,51 @@ async function getPageSnapshot(page) {
|
|
|
81
81
|
}
|
|
82
82
|
// Call LLM to get action steps
|
|
83
83
|
async function getActionsFromLLM(instruction, snapshot, pageUrl, llm) {
|
|
84
|
-
|
|
84
|
+
// Load platform-specific guide
|
|
85
|
+
let platformGuide = '';
|
|
86
|
+
if (pageUrl.includes('x.com') || pageUrl.includes('twitter.com')) {
|
|
87
|
+
try {
|
|
88
|
+
const { readFileSync } = await import('fs');
|
|
89
|
+
platformGuide = readFileSync(new URL('../prompts/x-guide.md', import.meta.url), 'utf-8');
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
}
|
|
93
|
+
else if (pageUrl.includes('linkedin.com')) {
|
|
94
|
+
try {
|
|
95
|
+
const { readFileSync } = await import('fs');
|
|
96
|
+
platformGuide = readFileSync(new URL('../prompts/linkedin-guide.md', import.meta.url), 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
catch { }
|
|
99
|
+
}
|
|
100
|
+
const systemPrompt = `You are an expert browser automation assistant. Given a page snapshot and a user instruction, return ONLY a valid JSON array of action steps.
|
|
101
|
+
|
|
102
|
+
${platformGuide ? `\n## Platform-Specific Guide\n${platformGuide}\n` : ''}
|
|
85
103
|
|
|
86
|
-
Available
|
|
87
|
-
- click: { action: "click", selector: "CSS or data-testid selector"
|
|
88
|
-
- type: { action: "type", selector: "...", text: "
|
|
89
|
-
- press: { action: "press", key: "Enter|Tab|Escape|..."
|
|
90
|
-
- navigate: { action: "navigate", url: "https://..."
|
|
91
|
-
- wait: { action: "wait", ms: 1000
|
|
92
|
-
- scroll: { action: "scroll", direction: "down"
|
|
104
|
+
## Available Actions
|
|
105
|
+
- click: { action: "click", selector: "CSS or data-testid selector" }
|
|
106
|
+
- type: { action: "type", selector: "...", text: "text to type" }
|
|
107
|
+
- press: { action: "press", key: "Enter|Tab|Escape|..." }
|
|
108
|
+
- navigate: { action: "navigate", url: "https://..." }
|
|
109
|
+
- wait: { action: "wait", ms: 1000 }
|
|
110
|
+
- scroll: { action: "scroll", direction: "down" }
|
|
93
111
|
|
|
94
|
-
Rules
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
112
|
+
## Rules
|
|
113
|
+
1. Return ONLY valid JSON array, nothing else
|
|
114
|
+
2. Each action MUST have all required fields
|
|
115
|
+
3. Never generate navigate actions unless instruction explicitly says to go to a URL
|
|
116
|
+
4. Add description field to every action
|
|
117
|
+
5. After clicks that open modals/menus, always add 500ms wait
|
|
118
|
+
6. Use data-testid selectors when available (most stable)
|
|
119
|
+
7. For contenteditable areas, click first then type
|
|
120
|
+
8. Always filter posts by visible content before interacting`;
|
|
100
121
|
const userPrompt = `Current URL: ${pageUrl}
|
|
101
122
|
|
|
102
123
|
Page snapshot:
|
|
103
|
-
${snapshot.slice(0,
|
|
124
|
+
${snapshot.slice(0, 3500)}
|
|
104
125
|
|
|
105
126
|
Instruction: ${instruction}
|
|
106
127
|
|
|
107
|
-
Return JSON array of action steps:`;
|
|
128
|
+
Return ONLY a valid JSON array of action steps with no other text:`;
|
|
108
129
|
let response;
|
|
109
130
|
if (llm.provider === 'ollama') {
|
|
110
131
|
const baseUrl = llm.baseUrl ?? 'http://localhost:11434';
|