@kernel.chat/kbot 2.22.3 → 2.23.0
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/a2a.d.ts +131 -0
- package/dist/a2a.d.ts.map +1 -0
- package/dist/a2a.js +504 -0
- package/dist/a2a.js.map +1 -0
- package/dist/guardrails.d.ts +61 -0
- package/dist/guardrails.d.ts.map +1 -0
- package/dist/guardrails.js +447 -0
- package/dist/guardrails.js.map +1 -0
- package/dist/handoffs.d.ts +54 -0
- package/dist/handoffs.d.ts.map +1 -0
- package/dist/handoffs.js +257 -0
- package/dist/handoffs.js.map +1 -0
- package/dist/marketplace.d.ts +55 -0
- package/dist/marketplace.d.ts.map +1 -1
- package/dist/marketplace.js +502 -0
- package/dist/marketplace.js.map +1 -1
- package/dist/tools/browser-agent.d.ts +47 -0
- package/dist/tools/browser-agent.d.ts.map +1 -0
- package/dist/tools/browser-agent.js +509 -0
- package/dist/tools/browser-agent.js.map +1 -0
- package/dist/tools/composio.d.ts +11 -0
- package/dist/tools/composio.d.ts.map +1 -0
- package/dist/tools/composio.js +488 -0
- package/dist/tools/composio.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +9 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/workflows.d.ts +92 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +619 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
// K:BOT Browser Agent — Autonomous browser agent mode
|
|
2
|
+
// The model sees the page, decides actions, and executes them in a loop.
|
|
3
|
+
// Requires: npx playwright install (run once)
|
|
4
|
+
//
|
|
5
|
+
// Usage: kbot "go to hackernews and find the top 3 stories about AI"
|
|
6
|
+
//
|
|
7
|
+
// Flow: navigate → screenshot → model analyzes → action → repeat → result
|
|
8
|
+
import { registerTool } from './index.js';
|
|
9
|
+
import { getByokKey, getByokProvider, getProviderModel, getProvider, } from '../auth.js';
|
|
10
|
+
// ── Playwright management ──
|
|
11
|
+
let browserInstance = null;
|
|
12
|
+
let contextInstance = null;
|
|
13
|
+
let pageInstance = null;
|
|
14
|
+
async function ensureBrowser() {
|
|
15
|
+
if (pageInstance)
|
|
16
|
+
return pageInstance;
|
|
17
|
+
// Try playwright, then playwright-core
|
|
18
|
+
let chromium;
|
|
19
|
+
try {
|
|
20
|
+
const pw = await import('playwright');
|
|
21
|
+
chromium = pw.chromium;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
try {
|
|
25
|
+
const pwCore = await import('playwright-core');
|
|
26
|
+
chromium = pwCore.chromium;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new Error('Browser agent requires playwright. Install with: npm i -g playwright && npx playwright install chromium');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
browserInstance = await chromium.launch({
|
|
33
|
+
headless: true,
|
|
34
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
35
|
+
});
|
|
36
|
+
contextInstance = await browserInstance.newContext({
|
|
37
|
+
viewport: { width: 1280, height: 720 },
|
|
38
|
+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
|
|
39
|
+
});
|
|
40
|
+
pageInstance = await contextInstance.newPage();
|
|
41
|
+
return pageInstance;
|
|
42
|
+
}
|
|
43
|
+
async function closeBrowserAgent() {
|
|
44
|
+
if (browserInstance) {
|
|
45
|
+
await browserInstance.close().catch(() => { });
|
|
46
|
+
browserInstance = null;
|
|
47
|
+
contextInstance = null;
|
|
48
|
+
pageInstance = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// ── Screenshot capture ──
|
|
52
|
+
async function takeScreenshot(page) {
|
|
53
|
+
const buffer = await page.screenshot({ type: 'png' });
|
|
54
|
+
return buffer.toString('base64');
|
|
55
|
+
}
|
|
56
|
+
// ── Action executors ──
|
|
57
|
+
async function executeAction(page, action) {
|
|
58
|
+
switch (action.action) {
|
|
59
|
+
case 'click': {
|
|
60
|
+
try {
|
|
61
|
+
// Try CSS selector first
|
|
62
|
+
await page.click(action.selector, { timeout: 5_000 });
|
|
63
|
+
return `Clicked: ${action.selector}`;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Fall back to text-based click
|
|
67
|
+
try {
|
|
68
|
+
await page.getByText(action.selector, { exact: false }).first().click({ timeout: 5_000 });
|
|
69
|
+
return `Clicked text: ${action.selector}`;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return `Failed to click: ${action.selector} — element not found`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
case 'type': {
|
|
77
|
+
try {
|
|
78
|
+
await page.fill(action.selector, action.text, { timeout: 5_000 });
|
|
79
|
+
return `Typed "${action.text}" into ${action.selector}`;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
try {
|
|
83
|
+
// Try clicking first, then typing
|
|
84
|
+
await page.click(action.selector, { timeout: 3_000 });
|
|
85
|
+
await page.keyboard.type(action.text, { delay: 30 });
|
|
86
|
+
return `Typed "${action.text}" into ${action.selector} (via keyboard)`;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return `Failed to type into: ${action.selector} — element not found`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
case 'navigate': {
|
|
94
|
+
try {
|
|
95
|
+
await page.goto(action.url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
|
|
96
|
+
const title = await page.title();
|
|
97
|
+
return `Navigated to: ${action.url} — Title: ${title}`;
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
return `Navigation failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
case 'scroll': {
|
|
104
|
+
const amount = action.amount ?? 500;
|
|
105
|
+
const delta = action.direction === 'down' ? amount : -amount;
|
|
106
|
+
await page.mouse.wheel(0, delta);
|
|
107
|
+
// Brief wait for scroll to settle and lazy-loaded content
|
|
108
|
+
await page.waitForTimeout(500);
|
|
109
|
+
return `Scrolled ${action.direction} by ${amount}px`;
|
|
110
|
+
}
|
|
111
|
+
case 'extract': {
|
|
112
|
+
try {
|
|
113
|
+
const elements = await page.$$(action.selector);
|
|
114
|
+
if (elements.length === 0) {
|
|
115
|
+
// Try getting full body text as fallback
|
|
116
|
+
if (action.selector === 'body' || action.selector === '*') {
|
|
117
|
+
const text = await page.innerText('body').catch(() => '');
|
|
118
|
+
const truncated = text.length > 3000 ? text.slice(0, 3000) + '\n...(truncated)' : text;
|
|
119
|
+
return `Extracted body text:\n${truncated}`;
|
|
120
|
+
}
|
|
121
|
+
return `No elements found for: ${action.selector}`;
|
|
122
|
+
}
|
|
123
|
+
const texts = [];
|
|
124
|
+
for (const el of elements.slice(0, 20)) {
|
|
125
|
+
const text = await el.innerText().catch(() => '');
|
|
126
|
+
if (text.trim())
|
|
127
|
+
texts.push(text.trim());
|
|
128
|
+
}
|
|
129
|
+
const combined = texts.join('\n---\n');
|
|
130
|
+
const truncated = combined.length > 3000 ? combined.slice(0, 3000) + '\n...(truncated)' : combined;
|
|
131
|
+
return `Extracted ${texts.length} elements from "${action.selector}":\n${truncated}`;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return `Extraction failed for: ${action.selector}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
case 'screenshot': {
|
|
138
|
+
return 'Screenshot taken for analysis';
|
|
139
|
+
}
|
|
140
|
+
case 'done': {
|
|
141
|
+
return action.result;
|
|
142
|
+
}
|
|
143
|
+
default:
|
|
144
|
+
return `Unknown action: ${action.action}`;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ── Model interaction ──
|
|
148
|
+
/** Build the system prompt for the browser agent */
|
|
149
|
+
function buildBrowserAgentPrompt(task) {
|
|
150
|
+
return `You are a browser automation agent. Your task is to interact with web pages to accomplish the user's goal.
|
|
151
|
+
|
|
152
|
+
TASK: ${task}
|
|
153
|
+
|
|
154
|
+
You can see a screenshot of the current page. Analyze it and decide the next action.
|
|
155
|
+
|
|
156
|
+
Respond with EXACTLY ONE JSON object (no markdown, no backticks) choosing one of these actions:
|
|
157
|
+
|
|
158
|
+
{"action":"click","selector":"CSS selector or visible text","description":"why"}
|
|
159
|
+
{"action":"type","selector":"CSS selector for input","text":"text to type","description":"why"}
|
|
160
|
+
{"action":"navigate","url":"https://...","description":"why"}
|
|
161
|
+
{"action":"scroll","direction":"up|down","amount":500,"description":"why"}
|
|
162
|
+
{"action":"extract","selector":"CSS selector","description":"what to extract"}
|
|
163
|
+
{"action":"screenshot","description":"why I need a fresh look"}
|
|
164
|
+
{"action":"done","result":"Final answer or extracted information"}
|
|
165
|
+
|
|
166
|
+
Guidelines:
|
|
167
|
+
- Use CSS selectors when possible (e.g., "input[name=q]", "button.submit", "#search")
|
|
168
|
+
- For clicks, you can also use visible text content as the selector
|
|
169
|
+
- Always extract information before marking as done
|
|
170
|
+
- If the page hasn't loaded or you need to see the current state, use "screenshot"
|
|
171
|
+
- When the task is complete, use "done" with the full result
|
|
172
|
+
- If stuck after several attempts, use "done" with a partial result and explanation
|
|
173
|
+
- Keep descriptions brief — they are for logging only`;
|
|
174
|
+
}
|
|
175
|
+
/** Send screenshot to model and get next action */
|
|
176
|
+
async function getNextAction(screenshotBase64, task, history, provider, apiKey, model) {
|
|
177
|
+
const providerConfig = getProvider(provider);
|
|
178
|
+
const systemPrompt = buildBrowserAgentPrompt(task);
|
|
179
|
+
// Build history context
|
|
180
|
+
const historyText = history.length > 0
|
|
181
|
+
? '\n\nPrevious actions:\n' + history.map(s => `Step ${s.step}: ${s.action.action}${s.action.action !== 'done' ? ` → ${s.outcome}` : ''}`).join('\n')
|
|
182
|
+
: '';
|
|
183
|
+
const userMessage = `Here is the current page screenshot. What should I do next?${historyText}`;
|
|
184
|
+
let responseText;
|
|
185
|
+
if (providerConfig.apiStyle === 'anthropic') {
|
|
186
|
+
responseText = await callAnthropicVision(apiKey, providerConfig.apiUrl, model, systemPrompt, userMessage, screenshotBase64);
|
|
187
|
+
}
|
|
188
|
+
else if (providerConfig.apiStyle === 'openai') {
|
|
189
|
+
responseText = await callOpenAIVision(apiKey, providerConfig.apiUrl, model, systemPrompt, userMessage, screenshotBase64);
|
|
190
|
+
}
|
|
191
|
+
else if (providerConfig.apiStyle === 'google') {
|
|
192
|
+
responseText = await callGoogleVision(apiKey, model, systemPrompt, userMessage, screenshotBase64);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// Fallback: text-only mode using page text instead of screenshot
|
|
196
|
+
responseText = await callTextOnly(apiKey, providerConfig, model, systemPrompt, userMessage);
|
|
197
|
+
}
|
|
198
|
+
return parseAction(responseText);
|
|
199
|
+
}
|
|
200
|
+
/** Parse the model's response into a BrowserAction */
|
|
201
|
+
function parseAction(text) {
|
|
202
|
+
// Strip markdown code fences if present
|
|
203
|
+
const cleaned = text.replace(/^```(?:json)?\s*/m, '').replace(/\s*```\s*$/m, '').trim();
|
|
204
|
+
// Try to find a JSON object in the response
|
|
205
|
+
const jsonMatch = cleaned.match(/\{[\s\S]*\}/);
|
|
206
|
+
if (!jsonMatch) {
|
|
207
|
+
// If no JSON found, treat the whole response as a "done" result
|
|
208
|
+
return { action: 'done', result: `Model returned non-JSON response: ${text.slice(0, 500)}` };
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
212
|
+
// Validate action type
|
|
213
|
+
const validActions = ['click', 'type', 'navigate', 'scroll', 'extract', 'screenshot', 'done'];
|
|
214
|
+
if (!parsed.action || !validActions.includes(parsed.action)) {
|
|
215
|
+
return { action: 'done', result: `Invalid action: ${parsed.action}. Response: ${text.slice(0, 300)}` };
|
|
216
|
+
}
|
|
217
|
+
// Type-specific validation
|
|
218
|
+
switch (parsed.action) {
|
|
219
|
+
case 'click':
|
|
220
|
+
if (!parsed.selector)
|
|
221
|
+
return { action: 'done', result: 'Click action missing selector' };
|
|
222
|
+
return { action: 'click', selector: String(parsed.selector), description: parsed.description };
|
|
223
|
+
case 'type':
|
|
224
|
+
if (!parsed.selector || parsed.text === undefined)
|
|
225
|
+
return { action: 'done', result: 'Type action missing selector or text' };
|
|
226
|
+
return { action: 'type', selector: String(parsed.selector), text: String(parsed.text), description: parsed.description };
|
|
227
|
+
case 'navigate':
|
|
228
|
+
if (!parsed.url)
|
|
229
|
+
return { action: 'done', result: 'Navigate action missing url' };
|
|
230
|
+
return { action: 'navigate', url: String(parsed.url), description: parsed.description };
|
|
231
|
+
case 'scroll':
|
|
232
|
+
return {
|
|
233
|
+
action: 'scroll',
|
|
234
|
+
direction: parsed.direction === 'up' ? 'up' : 'down',
|
|
235
|
+
amount: typeof parsed.amount === 'number' ? parsed.amount : 500,
|
|
236
|
+
description: parsed.description,
|
|
237
|
+
};
|
|
238
|
+
case 'extract':
|
|
239
|
+
if (!parsed.selector)
|
|
240
|
+
return { action: 'done', result: 'Extract action missing selector' };
|
|
241
|
+
return { action: 'extract', selector: String(parsed.selector), description: parsed.description };
|
|
242
|
+
case 'screenshot':
|
|
243
|
+
return { action: 'screenshot', description: parsed.description };
|
|
244
|
+
case 'done':
|
|
245
|
+
return { action: 'done', result: String(parsed.result || 'Task completed (no result provided)') };
|
|
246
|
+
default:
|
|
247
|
+
return { action: 'done', result: `Unknown action: ${parsed.action}` };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return { action: 'done', result: `Failed to parse action JSON: ${text.slice(0, 300)}` };
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// ── Provider-specific vision calls ──
|
|
255
|
+
/** Anthropic Messages API with vision */
|
|
256
|
+
async function callAnthropicVision(apiKey, apiUrl, model, system, userText, screenshotBase64) {
|
|
257
|
+
const res = await fetch(apiUrl, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: {
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
'x-api-key': apiKey,
|
|
262
|
+
'anthropic-version': '2023-06-01',
|
|
263
|
+
},
|
|
264
|
+
body: JSON.stringify({
|
|
265
|
+
model,
|
|
266
|
+
max_tokens: 1024,
|
|
267
|
+
system,
|
|
268
|
+
messages: [{
|
|
269
|
+
role: 'user',
|
|
270
|
+
content: [
|
|
271
|
+
{
|
|
272
|
+
type: 'image',
|
|
273
|
+
source: { type: 'base64', media_type: 'image/png', data: screenshotBase64 },
|
|
274
|
+
},
|
|
275
|
+
{ type: 'text', text: userText },
|
|
276
|
+
],
|
|
277
|
+
}],
|
|
278
|
+
}),
|
|
279
|
+
});
|
|
280
|
+
if (!res.ok) {
|
|
281
|
+
const body = await res.text().catch(() => '');
|
|
282
|
+
throw new Error(`Anthropic API error ${res.status}: ${body.slice(0, 200)}`);
|
|
283
|
+
}
|
|
284
|
+
const data = await res.json();
|
|
285
|
+
const blocks = data.content || [];
|
|
286
|
+
return blocks.filter(b => b.type === 'text').map(b => b.text || '').join('');
|
|
287
|
+
}
|
|
288
|
+
/** OpenAI-compatible vision API */
|
|
289
|
+
async function callOpenAIVision(apiKey, apiUrl, model, system, userText, screenshotBase64) {
|
|
290
|
+
const res = await fetch(apiUrl, {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
headers: {
|
|
293
|
+
'Content-Type': 'application/json',
|
|
294
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
295
|
+
},
|
|
296
|
+
body: JSON.stringify({
|
|
297
|
+
model,
|
|
298
|
+
max_tokens: 1024,
|
|
299
|
+
messages: [
|
|
300
|
+
{ role: 'system', content: system },
|
|
301
|
+
{
|
|
302
|
+
role: 'user',
|
|
303
|
+
content: [
|
|
304
|
+
{
|
|
305
|
+
type: 'image_url',
|
|
306
|
+
image_url: { url: `data:image/png;base64,${screenshotBase64}`, detail: 'low' },
|
|
307
|
+
},
|
|
308
|
+
{ type: 'text', text: userText },
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
}),
|
|
313
|
+
});
|
|
314
|
+
if (!res.ok) {
|
|
315
|
+
const body = await res.text().catch(() => '');
|
|
316
|
+
throw new Error(`OpenAI API error ${res.status}: ${body.slice(0, 200)}`);
|
|
317
|
+
}
|
|
318
|
+
const data = await res.json();
|
|
319
|
+
return data.choices?.[0]?.message?.content || '';
|
|
320
|
+
}
|
|
321
|
+
/** Google Gemini vision API */
|
|
322
|
+
async function callGoogleVision(apiKey, model, system, userText, screenshotBase64) {
|
|
323
|
+
const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`;
|
|
324
|
+
const res = await fetch(url, {
|
|
325
|
+
method: 'POST',
|
|
326
|
+
headers: { 'Content-Type': 'application/json' },
|
|
327
|
+
body: JSON.stringify({
|
|
328
|
+
systemInstruction: { parts: [{ text: system }] },
|
|
329
|
+
contents: [{
|
|
330
|
+
parts: [
|
|
331
|
+
{ inlineData: { mimeType: 'image/png', data: screenshotBase64 } },
|
|
332
|
+
{ text: userText },
|
|
333
|
+
],
|
|
334
|
+
}],
|
|
335
|
+
generationConfig: { maxOutputTokens: 1024 },
|
|
336
|
+
}),
|
|
337
|
+
});
|
|
338
|
+
if (!res.ok) {
|
|
339
|
+
const body = await res.text().catch(() => '');
|
|
340
|
+
throw new Error(`Google API error ${res.status}: ${body.slice(0, 200)}`);
|
|
341
|
+
}
|
|
342
|
+
const data = await res.json();
|
|
343
|
+
return data.candidates?.[0]?.content?.parts?.map(p => p.text || '').join('') || '';
|
|
344
|
+
}
|
|
345
|
+
/** Text-only fallback for providers without vision */
|
|
346
|
+
async function callTextOnly(apiKey, providerConfig, model, system, userText) {
|
|
347
|
+
// OpenAI-compatible text-only
|
|
348
|
+
const res = await fetch(providerConfig.apiUrl, {
|
|
349
|
+
method: 'POST',
|
|
350
|
+
headers: {
|
|
351
|
+
'Content-Type': 'application/json',
|
|
352
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
353
|
+
},
|
|
354
|
+
body: JSON.stringify({
|
|
355
|
+
model,
|
|
356
|
+
max_tokens: 1024,
|
|
357
|
+
messages: [
|
|
358
|
+
{ role: 'system', content: system },
|
|
359
|
+
{ role: 'user', content: userText + '\n\n(Note: screenshot not available — using text-only mode. Describe what you need to do based on context.)' },
|
|
360
|
+
],
|
|
361
|
+
}),
|
|
362
|
+
});
|
|
363
|
+
if (!res.ok) {
|
|
364
|
+
const body = await res.text().catch(() => '');
|
|
365
|
+
throw new Error(`API error ${res.status}: ${body.slice(0, 200)}`);
|
|
366
|
+
}
|
|
367
|
+
const data = await res.json();
|
|
368
|
+
return data.choices?.[0]?.message?.content || '';
|
|
369
|
+
}
|
|
370
|
+
// ── Main agent loop ──
|
|
371
|
+
async function runBrowserAgent(task, startUrl, maxSteps = 10) {
|
|
372
|
+
const provider = getByokProvider();
|
|
373
|
+
const apiKey = getByokKey();
|
|
374
|
+
if (!apiKey) {
|
|
375
|
+
return {
|
|
376
|
+
success: false,
|
|
377
|
+
result: 'No API key configured. Run: kbot auth',
|
|
378
|
+
steps: [],
|
|
379
|
+
totalSteps: 0,
|
|
380
|
+
url: '',
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
const model = getProviderModel(provider, 'default', 'browser vision analysis');
|
|
384
|
+
const steps = [];
|
|
385
|
+
let page;
|
|
386
|
+
try {
|
|
387
|
+
page = await ensureBrowser();
|
|
388
|
+
}
|
|
389
|
+
catch (err) {
|
|
390
|
+
return {
|
|
391
|
+
success: false,
|
|
392
|
+
result: err instanceof Error ? err.message : String(err),
|
|
393
|
+
steps: [],
|
|
394
|
+
totalSteps: 0,
|
|
395
|
+
url: '',
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
try {
|
|
399
|
+
// Navigate to starting URL if provided
|
|
400
|
+
if (startUrl) {
|
|
401
|
+
await page.goto(startUrl, { waitUntil: 'domcontentloaded', timeout: 30_000 });
|
|
402
|
+
}
|
|
403
|
+
for (let step = 1; step <= maxSteps; step++) {
|
|
404
|
+
// Take screenshot for model analysis
|
|
405
|
+
const screenshot = await takeScreenshot(page);
|
|
406
|
+
// Ask model what to do next
|
|
407
|
+
const action = await getNextAction(screenshot, task, steps, provider, apiKey, model);
|
|
408
|
+
// Execute the action
|
|
409
|
+
const outcome = await executeAction(page, action);
|
|
410
|
+
steps.push({
|
|
411
|
+
step,
|
|
412
|
+
action,
|
|
413
|
+
outcome,
|
|
414
|
+
timestamp: new Date().toISOString(),
|
|
415
|
+
});
|
|
416
|
+
// If done, return the result
|
|
417
|
+
if (action.action === 'done') {
|
|
418
|
+
return {
|
|
419
|
+
success: true,
|
|
420
|
+
result: action.result,
|
|
421
|
+
steps,
|
|
422
|
+
totalSteps: step,
|
|
423
|
+
url: page.url(),
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// Max steps reached — take a final screenshot and extract what we can
|
|
428
|
+
const finalUrl = page.url();
|
|
429
|
+
const bodyText = await page.innerText('body').catch(() => '');
|
|
430
|
+
const truncBody = bodyText.length > 2000 ? bodyText.slice(0, 2000) + '...' : bodyText;
|
|
431
|
+
return {
|
|
432
|
+
success: false,
|
|
433
|
+
result: `Reached maximum steps (${maxSteps}). Last page: ${finalUrl}\n\nPage content:\n${truncBody}`,
|
|
434
|
+
steps,
|
|
435
|
+
totalSteps: maxSteps,
|
|
436
|
+
url: finalUrl,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
catch (err) {
|
|
440
|
+
return {
|
|
441
|
+
success: false,
|
|
442
|
+
result: `Browser agent error: ${err instanceof Error ? err.message : String(err)}`,
|
|
443
|
+
steps,
|
|
444
|
+
totalSteps: steps.length,
|
|
445
|
+
url: page?.url?.() || '',
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
finally {
|
|
449
|
+
await closeBrowserAgent();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
// ── Tool registration ──
|
|
453
|
+
export function registerBrowserAgentTools() {
|
|
454
|
+
registerTool({
|
|
455
|
+
name: 'browser_agent',
|
|
456
|
+
description: 'Autonomous browser agent — give it a task in natural language and it will open a browser, ' +
|
|
457
|
+
'navigate pages, click, type, scroll, and extract information to accomplish the goal. ' +
|
|
458
|
+
'The agent sees screenshots of the page and decides actions in a loop until the task is done. ' +
|
|
459
|
+
'Requires playwright to be installed.',
|
|
460
|
+
parameters: {
|
|
461
|
+
task: {
|
|
462
|
+
type: 'string',
|
|
463
|
+
description: 'Natural language description of what to accomplish (e.g., "Go to Hacker News and find the top 3 AI stories")',
|
|
464
|
+
required: true,
|
|
465
|
+
},
|
|
466
|
+
url: {
|
|
467
|
+
type: 'string',
|
|
468
|
+
description: 'Starting URL to navigate to (optional — agent can navigate on its own)',
|
|
469
|
+
},
|
|
470
|
+
max_steps: {
|
|
471
|
+
type: 'number',
|
|
472
|
+
description: 'Maximum number of interaction steps before stopping (default: 10)',
|
|
473
|
+
default: 10,
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
tier: 'free',
|
|
477
|
+
timeout: 600_000, // 10 min — browser tasks can be slow
|
|
478
|
+
maxResultSize: 100_000, // 100KB — browser results can be large
|
|
479
|
+
async execute(args) {
|
|
480
|
+
const task = String(args.task);
|
|
481
|
+
const url = args.url ? String(args.url) : undefined;
|
|
482
|
+
const maxSteps = typeof args.max_steps === 'number' ? args.max_steps : 10;
|
|
483
|
+
const result = await runBrowserAgent(task, url, maxSteps);
|
|
484
|
+
// Format output
|
|
485
|
+
const lines = [];
|
|
486
|
+
lines.push(`Browser Agent — ${result.success ? 'SUCCESS' : 'INCOMPLETE'}`);
|
|
487
|
+
lines.push(`Steps: ${result.totalSteps}`);
|
|
488
|
+
if (result.url)
|
|
489
|
+
lines.push(`Final URL: ${result.url}`);
|
|
490
|
+
lines.push('');
|
|
491
|
+
// Action log
|
|
492
|
+
if (result.steps.length > 0) {
|
|
493
|
+
lines.push('Action Log:');
|
|
494
|
+
for (const step of result.steps) {
|
|
495
|
+
const desc = step.action.action !== 'done' && 'description' in step.action && step.action.description
|
|
496
|
+
? ` — ${step.action.description}`
|
|
497
|
+
: '';
|
|
498
|
+
lines.push(` [${step.step}] ${step.action.action}${desc}`);
|
|
499
|
+
lines.push(` → ${step.outcome.split('\n')[0]}`);
|
|
500
|
+
}
|
|
501
|
+
lines.push('');
|
|
502
|
+
}
|
|
503
|
+
lines.push('Result:');
|
|
504
|
+
lines.push(result.result);
|
|
505
|
+
return lines.join('\n');
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
//# sourceMappingURL=browser-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-agent.js","sourceRoot":"","sources":["../../src/tools/browser-agent.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,yEAAyE;AACzE,8CAA8C;AAC9C,EAAE;AACF,qEAAqE;AACrE,EAAE;AACF,0EAA0E;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EACL,UAAU,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,GAE3D,MAAM,YAAY,CAAA;AA+BnB,8BAA8B;AAE9B,IAAI,eAAe,GAAQ,IAAI,CAAA;AAC/B,IAAI,eAAe,GAAQ,IAAI,CAAA;AAC/B,IAAI,YAAY,GAAQ,IAAI,CAAA;AAE5B,KAAK,UAAU,aAAa;IAC1B,IAAI,YAAY;QAAE,OAAO,YAAY,CAAA;IAErC,uCAAuC;IACvC,IAAI,QAAa,CAAA;IACjB,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAA;QACrC,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,iBAA2B,CAAC,CAAA;YACxD,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M,CAAC,MAAM,CAAC,CAAA;YAEzB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ToolDefinition } from './index.js';
|
|
2
|
+
export declare function registerComposioTools(): void;
|
|
3
|
+
/**
|
|
4
|
+
* Fetch available actions for all connected Composio apps and return them
|
|
5
|
+
* as kbot-compatible ToolDefinition objects. This allows the agent to see
|
|
6
|
+
* Composio actions alongside built-in tools.
|
|
7
|
+
*
|
|
8
|
+
* Call this after registerComposioTools() to dynamically expand the toolset.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getComposioTools(): Promise<ToolDefinition[]>;
|
|
11
|
+
//# sourceMappingURL=composio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composio.d.ts","sourceRoot":"","sources":["../../src/tools/composio.ts"],"names":[],"mappings":"AAWA,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAkM9D,wBAAgB,qBAAqB,IAAI,IAAI,CAuS5C;AAMD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAiFlE"}
|