mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-21 12:55:09 +00:00
* clean-up bunch of files for re-write * more clean-up and adding basic agent * Minor fix moved types into respective files. * Deleted bunch of old files backup Update gitignore Deleted a bunch of files Remove message manager Deleted old docs Update rules rename Profiler to profiler * Temporarily adding old code * Adding two small things back * backup * Implemented LangChainProvider and updated cursor rules backup LangChainProvider curosr rules * Implement tests for LangChainProvider -- unit test and integration test integration test passes integration test backup * Tool Design Tools Desing tools design * NavigationTool ready NavigationTool ready NavigationTool ready NaivgationTool ready backup * MessageManager MessageManager backup * Fixed integration test * Agent design new Updated agent design and added bunch of /NTN commands agent new design * Delete old agent design * MessageManagerReadOnly class * PlannerTool ready PlannerTool almost ready * ToolManager and DoneTool * Integration of BrowserAgent * BrowserAgent implementation v0.1 * BrowserAgent small fix v0.2 * Tool calling design too call design tool design claude * Update agent tool design with // NTN * add zod-to-json npm install * BrowserAGent v0.3 * BrowserAgent v0.4 * BrowserAgent v0.5 * fixes * Build error fixes in my NEWLY added code build errors fix * Build error fixes in old code (integration work) backup * Comment StreamEventProcessor for now, it is not used * Small build error fix * Small rename * Added integration test to check structuredLLM and changed to 4o-mini change default to nxtscape integration test * Small docstring * Simplified BrowserAgent code and added integration test Simplified BrowserAgent code BrowserAGent integrationt est * Update CLAUDE.md with project memory and instructions on how to write code Update CLAUDE.md with project memory and instructions on how to write code Project Memory * Just a mova.. Moved ToolManager outside. Build works. * TabOperations tool TabOperations Tool and fixing some test tab operations * Update CLAUDE.md * Added ClassificationTool classifiction tool classification prommpt * Refactored and simplified PlannerTool unit test and integration test * Updated Plnnaer tool * Update CLAUDE.md * BrowserAgent modified to do classification BrowserAgent with classification * minor fix to ToolManager * Instead of ToolCall and ToolResult -- just updating message manager once * minor fix to BrowserAgent integration test * Changed done to "done_tool" * Updated CLAUDE.md to reflect understanding of claude * Uncommented stream event processor * Renamed EventBus to StreamEventBus * Commented StreamEventProcessor * Event Processor * Integrated EventProcessor with BrowserAgent Added EventProcessor to BrowserAgetn * Renamed StreamEventBus to EventBus * Made EventBus required parameter in ExecutionContext * PlanGenerator rewrite PlanGenerator rewrite backup * For simple task, explicitly tell it to call done tool * Max attempts for simple task * backup * Revert "backup" This reverts commit 7d79a3d4d5774bfef79ec9827878b74edad3593f. * Consolidating where EventBus and EventProcessor are created and initialized backup * Update CLAUDE.md Update CLAUDE.md * Improving agent loop code Cleaned up processTooCall classification task * Create test-writer subAgent test-agent-prompt test agent prompt test-agent-prompt Update test-writer.md * BrowserAgent test Browseragent test BrowserAgent test * BrowserAgent refactor backup backup * Minor fixes * Minor fix * minor change -- NEW AGENT LOOP IS WORKING WELL * Update cursor rules * Small change * Improved BrowserAgent integration test Improved BrowserAgent integration test * Small change * Update CLAUDE.md * Different tools * FindElementTool is ready Find element update backup find element backup * Updated to test strings to say "tests..." * ScrollTool is ready * RefreshStateTool is updated as well * MessageManager updated * SearchTool is ready backup * Interaction Element is also ready * Add debugMessage emitter * ValidatorTool ready and tests are passing Validation Tool validator tool backup backup * GroupTabs tool ready * Registered all the tools * Planning changed to 5 steps * BrowserAgent integration test fix * Minor string changes * backup * Removed too many confusing events in EventProcessor -- there is only event.info right now * Abort control implemented backup Abort * Formatter for toolResult Formatter for toolResult backup * Always render using Markdown * Minor fix --------- Co-authored-by: Nikhil Sonti <nikhilsv92@gmail.com>
204 lines
5.7 KiB
TypeScript
204 lines
5.7 KiB
TypeScript
import { z } from 'zod';
|
|
import { NxtscapeTool } from '../base/NxtscapeTool';
|
|
import { ToolConfig } from '../base/ToolConfig';
|
|
import { ExecutionContext } from '@/lib/runtime/ExecutionContext';
|
|
import { getBookmarkBar, getFolderPath } from './common';
|
|
|
|
/**
|
|
* Input schema for bookmark management tool
|
|
*/
|
|
export const BookmarkManagementInputSchema = z.object({
|
|
operationType: z.enum(['get']), // The operation to perform
|
|
|
|
// For 'get'
|
|
folder_id: z.string().optional() // Which folder to get bookmarks from (defaults to bookmark bar)
|
|
});
|
|
|
|
export type BookmarkManagementInput = z.infer<typeof BookmarkManagementInputSchema>;
|
|
|
|
/**
|
|
* Output schema for bookmark management tool
|
|
*/
|
|
export const BookmarkManagementOutputSchema = z.object({
|
|
success: z.boolean(),
|
|
message: z.string()
|
|
});
|
|
|
|
export type BookmarkManagementOutput = z.infer<typeof BookmarkManagementOutputSchema>;
|
|
|
|
/**
|
|
* Tool for managing existing bookmarks - get and move operations
|
|
*/
|
|
export class BookmarkManagementTool extends NxtscapeTool<BookmarkManagementInput, BookmarkManagementOutput> {
|
|
constructor(executionContext: ExecutionContext) {
|
|
const config: ToolConfig<BookmarkManagementInput, BookmarkManagementOutput> = {
|
|
name: 'bookmark_management',
|
|
description: 'List existing bookmarks. Operation: "get" (list bookmarks from a folder recursively). Use folder_id to specify a folder, or leave empty for bookmark bar.',
|
|
category: 'bookmarks',
|
|
version: '1.0.0',
|
|
inputSchema: BookmarkManagementInputSchema,
|
|
outputSchema: BookmarkManagementOutputSchema,
|
|
examples: [
|
|
// Get operations
|
|
{
|
|
description: 'Get all bookmarks from bookmark bar to see what\'s saved',
|
|
input: {
|
|
operationType: 'get'
|
|
},
|
|
output: {
|
|
success: true,
|
|
message: 'Found 47 bookmarks in bookmark bar'
|
|
}
|
|
},
|
|
{
|
|
description: 'Get bookmarks from Work folder to find project resources',
|
|
input: {
|
|
operationType: 'get',
|
|
folder_id: 'folder_work_2341'
|
|
},
|
|
output: {
|
|
success: true,
|
|
message: 'Found 23 bookmarks in Work folder'
|
|
}
|
|
},
|
|
{
|
|
description: 'Get bookmarks from Development Resources folder',
|
|
input: {
|
|
operationType: 'get',
|
|
folder_id: 'folder_dev_8765'
|
|
},
|
|
output: {
|
|
success: true,
|
|
message: 'Found 156 bookmarks in Development Resources folder'
|
|
}
|
|
}
|
|
],
|
|
streamingConfig: {
|
|
displayName: 'Bookmark Management',
|
|
icon: '📚',
|
|
progressMessage: 'Processing bookmark operation...'
|
|
}
|
|
};
|
|
|
|
super(config, executionContext);
|
|
}
|
|
|
|
/**
|
|
* Override: Generate contextual display message
|
|
*/
|
|
getProgressMessage(args: BookmarkManagementInput): string {
|
|
try {
|
|
// Note: args should already be parsed by StreamEventProcessor
|
|
|
|
const operationType = args?.operationType;
|
|
|
|
switch (operationType) {
|
|
case 'get':
|
|
return 'Getting bookmarks...';
|
|
|
|
default:
|
|
return 'Processing bookmark operation...';
|
|
}
|
|
} catch {
|
|
return 'Processing bookmark operation...';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Override: Format result for display
|
|
*/
|
|
FormatResultForUI(output: BookmarkManagementOutput): string {
|
|
if (output.success) {
|
|
return `✅ ${output.message}`;
|
|
}
|
|
return `❌ ${output.message}`;
|
|
}
|
|
|
|
protected async execute(input: BookmarkManagementInput): Promise<BookmarkManagementOutput> {
|
|
try {
|
|
switch (input.operationType) {
|
|
case 'get':
|
|
return await this.executeGet(input);
|
|
default:
|
|
return {
|
|
success: false,
|
|
message: 'Invalid operation type'
|
|
};
|
|
}
|
|
} catch (error) {
|
|
console.error('[bookmark_management] Error:', error);
|
|
return {
|
|
success: false,
|
|
message: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Execute get operation - always recursive
|
|
*/
|
|
private async executeGet(input: BookmarkManagementInput): Promise<BookmarkManagementOutput> {
|
|
const folderId = input.folder_id;
|
|
|
|
let startFolder: chrome.bookmarks.BookmarkTreeNode;
|
|
let folderName: string;
|
|
|
|
if (folderId) {
|
|
try {
|
|
const folders = await chrome.bookmarks.get(folderId);
|
|
startFolder = folders[0];
|
|
if (startFolder.url) {
|
|
return {
|
|
success: false,
|
|
message: 'Specified ID is not a folder'
|
|
};
|
|
}
|
|
folderName = startFolder.title;
|
|
} catch {
|
|
return {
|
|
success: false,
|
|
message: 'Folder not found'
|
|
};
|
|
}
|
|
} else {
|
|
const bookmarkBar = await getBookmarkBar();
|
|
if (!bookmarkBar) {
|
|
return {
|
|
success: false,
|
|
message: 'Could not find bookmark bar'
|
|
};
|
|
}
|
|
startFolder = bookmarkBar;
|
|
folderName = 'bookmark bar';
|
|
}
|
|
|
|
// Collect bookmarks recursively
|
|
const bookmarkCount = await this.countBookmarksRecursively(startFolder);
|
|
|
|
return {
|
|
success: true,
|
|
message: `Found ${bookmarkCount} bookmark${bookmarkCount === 1 ? '' : 's'} in ${folderName}`
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Count bookmarks recursively
|
|
*/
|
|
private async countBookmarksRecursively(folder: chrome.bookmarks.BookmarkTreeNode): Promise<number> {
|
|
let count = 0;
|
|
const children = await chrome.bookmarks.getChildren(folder.id);
|
|
|
|
for (const child of children) {
|
|
if (child.url) {
|
|
// It's a bookmark
|
|
count++;
|
|
} else {
|
|
// It's a folder - recurse
|
|
count += await this.countBookmarksRecursively(child);
|
|
}
|
|
}
|
|
|
|
return count;
|
|
}
|
|
}
|