mirror of
https://github.com/aaronjmars/opendia.git
synced 2025-12-29 16:16:00 +00:00
more tools
This commit is contained in:
@@ -195,6 +195,33 @@ function formatToolResult(toolName, result) {
|
||||
)}`
|
||||
);
|
||||
|
||||
case "get_history":
|
||||
return formatHistoryResult(result, metadata);
|
||||
|
||||
case "get_selected_text":
|
||||
return formatSelectedTextResult(result, metadata);
|
||||
|
||||
case "page_scroll":
|
||||
return formatScrollResult(result, metadata);
|
||||
|
||||
case "get_page_links":
|
||||
return formatLinksResult(result, metadata);
|
||||
|
||||
case "tab_create":
|
||||
return formatTabCreateResult(result, metadata);
|
||||
|
||||
case "tab_close":
|
||||
return formatTabCloseResult(result, metadata);
|
||||
|
||||
case "tab_list":
|
||||
return formatTabListResult(result, metadata);
|
||||
|
||||
case "tab_switch":
|
||||
return formatTabSwitchResult(result, metadata);
|
||||
|
||||
case "element_get_state":
|
||||
return formatElementStateResult(result, metadata);
|
||||
|
||||
default:
|
||||
// Legacy tools or unknown tools
|
||||
return JSON.stringify(result, null, 2);
|
||||
@@ -354,6 +381,237 @@ function formatElementFillResult(result, metadata) {
|
||||
return `${fillResult}\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatHistoryResult(result, metadata) {
|
||||
if (!result.history_items || result.history_items.length === 0) {
|
||||
return `🕒 No history items found matching the criteria\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
const summary = `🕒 Found ${result.history_items.length} history items (${result.metadata.total_found} total matches):\n\n`;
|
||||
|
||||
const items = result.history_items.map((item, index) => {
|
||||
const visitInfo = `Visits: ${item.visit_count}`;
|
||||
const timeInfo = new Date(item.last_visit_time).toLocaleDateString();
|
||||
const domainInfo = `[${item.domain}]`;
|
||||
|
||||
return `${index + 1}. **${item.title}**\n ${domainInfo} ${visitInfo} | Last: ${timeInfo}\n URL: ${item.url}`;
|
||||
}).join('\n\n');
|
||||
|
||||
const searchSummary = result.metadata.search_params.keywords ?
|
||||
`\n🔍 Search: "${result.metadata.search_params.keywords}"` : '';
|
||||
const dateSummary = result.metadata.search_params.date_range ?
|
||||
`\n📅 Date range: ${result.metadata.search_params.date_range}` : '';
|
||||
const domainSummary = result.metadata.search_params.domains ?
|
||||
`\n🌐 Domains: ${result.metadata.search_params.domains.join(', ')}` : '';
|
||||
const visitSummary = result.metadata.search_params.min_visit_count > 1 ?
|
||||
`\n📊 Min visits: ${result.metadata.search_params.min_visit_count}` : '';
|
||||
|
||||
return `${summary}${items}${searchSummary}${dateSummary}${domainSummary}${visitSummary}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatSelectedTextResult(result, metadata) {
|
||||
if (!result.has_selection) {
|
||||
return `📝 No text selected\n\n${result.message || "No text is currently selected on the page"}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
const textPreview = result.selected_text.length > 200
|
||||
? result.selected_text.substring(0, 200) + "..."
|
||||
: result.selected_text;
|
||||
|
||||
let summary = `📝 Selected Text (${result.character_count} characters):\n\n"${textPreview}"`;
|
||||
|
||||
if (result.truncated) {
|
||||
summary += `\n\n⚠️ Text was truncated to fit length limit`;
|
||||
}
|
||||
|
||||
if (result.selection_metadata) {
|
||||
const meta = result.selection_metadata;
|
||||
summary += `\n\n📊 Selection Details:`;
|
||||
summary += `\n• Word count: ${meta.word_count}`;
|
||||
summary += `\n• Line count: ${meta.line_count}`;
|
||||
summary += `\n• Position: ${Math.round(meta.position.x)}, ${Math.round(meta.position.y)}`;
|
||||
|
||||
if (meta.parent_element.tag_name) {
|
||||
summary += `\n• Parent element: <${meta.parent_element.tag_name}>`;
|
||||
if (meta.parent_element.class_name) {
|
||||
summary += ` class="${meta.parent_element.class_name}"`;
|
||||
}
|
||||
}
|
||||
|
||||
if (meta.page_info) {
|
||||
summary += `\n• Page: ${meta.page_info.title}`;
|
||||
summary += `\n• Domain: ${meta.page_info.domain}`;
|
||||
}
|
||||
}
|
||||
|
||||
return `${summary}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatScrollResult(result, metadata) {
|
||||
if (!result.success) {
|
||||
return `📜 Scroll failed: ${result.error || "Unknown error"}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
let summary = `📜 Page scrolled successfully`;
|
||||
|
||||
if (result.direction) {
|
||||
summary += ` ${result.direction}`;
|
||||
}
|
||||
|
||||
if (result.amount && result.amount !== "custom") {
|
||||
summary += ` (${result.amount})`;
|
||||
} else if (result.pixels) {
|
||||
summary += ` (${result.pixels}px)`;
|
||||
}
|
||||
|
||||
if (result.element_scrolled) {
|
||||
summary += `\n🎯 Scrolled to element: ${result.element_scrolled}`;
|
||||
}
|
||||
|
||||
if (result.scroll_position) {
|
||||
summary += `\n📍 New position: x=${result.scroll_position.x}, y=${result.scroll_position.y}`;
|
||||
}
|
||||
|
||||
if (result.page_dimensions) {
|
||||
const { width, height, scrollWidth, scrollHeight } = result.page_dimensions;
|
||||
summary += `\n📐 Page size: ${width}x${height} (scrollable: ${scrollWidth}x${scrollHeight})`;
|
||||
}
|
||||
|
||||
if (result.wait_time) {
|
||||
summary += `\n⏱️ Waited ${result.wait_time}ms after scroll`;
|
||||
}
|
||||
|
||||
return `${summary}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatLinksResult(result, metadata) {
|
||||
if (!result.links || result.links.length === 0) {
|
||||
return `🔗 No links found on the page\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
const summary = `🔗 Found ${result.returned} links (${result.total_found} total on page):\n`;
|
||||
const currentDomain = result.current_domain ? `\n🌐 Current domain: ${result.current_domain}` : '';
|
||||
|
||||
const linksList = result.links.map((link, index) => {
|
||||
const typeIcon = link.type === 'internal' ? '🏠' : '🌐';
|
||||
const linkText = link.text.length > 50 ? link.text.substring(0, 50) + '...' : link.text;
|
||||
const displayText = linkText || '[No text]';
|
||||
const title = link.title ? `\n Title: ${link.title}` : '';
|
||||
const domain = link.domain ? ` [${link.domain}]` : '';
|
||||
|
||||
return `${index + 1}. ${typeIcon} **${displayText}**${domain}${title}\n URL: ${link.url}`;
|
||||
}).join('\n\n');
|
||||
|
||||
const filterInfo = [];
|
||||
if (result.links.some(l => l.type === 'internal') && result.links.some(l => l.type === 'external')) {
|
||||
const internal = result.links.filter(l => l.type === 'internal').length;
|
||||
const external = result.links.filter(l => l.type === 'external').length;
|
||||
filterInfo.push(`📊 Internal: ${internal}, External: ${external}`);
|
||||
}
|
||||
|
||||
const filterSummary = filterInfo.length > 0 ? `\n${filterInfo.join('\n')}` : '';
|
||||
|
||||
return `${summary}${currentDomain}${filterSummary}\n\n${linksList}\n\n${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatTabCreateResult(result, metadata) {
|
||||
if (result.success) {
|
||||
return `✅ New tab created successfully
|
||||
🆔 Tab ID: ${result.tab_id}
|
||||
🌐 URL: ${result.url || 'about:blank'}
|
||||
🎯 Active: ${result.active ? 'Yes' : 'No'}
|
||||
📝 Title: ${result.title || 'New Tab'}
|
||||
${result.warning ? `⚠️ Warning: ${result.warning}` : ''}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
} else {
|
||||
return `❌ Failed to create tab: ${result.error || 'Unknown error'}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function formatTabCloseResult(result, metadata) {
|
||||
if (result.success) {
|
||||
const tabText = result.count === 1 ? 'tab' : 'tabs';
|
||||
return `✅ Successfully closed ${result.count} ${tabText}
|
||||
🆔 Closed tab IDs: ${result.closed_tabs.join(', ')}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
} else {
|
||||
return `❌ Failed to close tabs: ${result.error || 'Unknown error'}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function formatTabListResult(result, metadata) {
|
||||
if (!result.success || !result.tabs || result.tabs.length === 0) {
|
||||
return `📋 No tabs found
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
const summary = `📋 Found ${result.count} open tabs:
|
||||
🎯 Active tab: ${result.active_tab || 'None'}
|
||||
|
||||
`;
|
||||
|
||||
const tabsList = result.tabs.map((tab, index) => {
|
||||
const activeIcon = tab.active ? '🟢' : '⚪';
|
||||
const statusInfo = tab.status ? ` [${tab.status}]` : '';
|
||||
const pinnedInfo = tab.pinned ? ' 📌' : '';
|
||||
|
||||
return `${index + 1}. ${activeIcon} **${tab.title}**${pinnedInfo}${statusInfo}
|
||||
🆔 ID: ${tab.id} | 🌐 ${tab.url}`;
|
||||
}).join('\n\n');
|
||||
|
||||
return `${summary}${tabsList}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
function formatTabSwitchResult(result, metadata) {
|
||||
if (result.success) {
|
||||
return `✅ Successfully switched to tab
|
||||
🆔 Tab ID: ${result.tab_id}
|
||||
📝 Title: ${result.title}
|
||||
🌐 URL: ${result.url}
|
||||
🏠 Window ID: ${result.window_id}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
} else {
|
||||
return `❌ Failed to switch tabs: ${result.error || 'Unknown error'}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function formatElementStateResult(result, metadata) {
|
||||
const element = result.element_name || result.element_id || 'Unknown element';
|
||||
const state = result.state || {};
|
||||
|
||||
let summary = `🔍 Element State: ${element}
|
||||
|
||||
📊 **Interaction Readiness**: ${state.interaction_ready ? '✅ Ready' : '❌ Not Ready'}
|
||||
|
||||
**Detailed State:**
|
||||
• Disabled: ${state.disabled ? '❌ Yes' : '✅ No'}
|
||||
• Visible: ${state.visible ? '✅ Yes' : '❌ No'}
|
||||
• Clickable: ${state.clickable ? '✅ Yes' : '❌ No'}
|
||||
• Focusable: ${state.focusable ? '✅ Yes' : '❌ No'}
|
||||
• Has Text: ${state.hasText ? '✅ Yes' : '❌ No'}
|
||||
• Is Empty: ${state.isEmpty ? '❌ Yes' : '✅ No'}`;
|
||||
|
||||
if (result.current_value) {
|
||||
summary += `
|
||||
📝 **Current Value**: "${result.current_value}"`;
|
||||
}
|
||||
|
||||
return `${summary}
|
||||
|
||||
${JSON.stringify(metadata, null, 2)}`;
|
||||
}
|
||||
|
||||
// Enhanced fallback tools when extension is not connected
|
||||
function getFallbackTools() {
|
||||
return [
|
||||
@@ -514,6 +772,100 @@ function getFallbackTools() {
|
||||
required: ["url"],
|
||||
},
|
||||
},
|
||||
// Tab Management Tools
|
||||
{
|
||||
name: "tab_create",
|
||||
description: "🆕 Create a new tab with optional URL and activation (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
url: {
|
||||
type: "string",
|
||||
description: "URL to open in the new tab (optional)"
|
||||
},
|
||||
active: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Whether to activate the new tab"
|
||||
},
|
||||
wait_for: {
|
||||
type: "string",
|
||||
description: "CSS selector to wait for after tab creation (if URL provided)"
|
||||
},
|
||||
timeout: {
|
||||
type: "number",
|
||||
default: 10000,
|
||||
description: "Maximum wait time in milliseconds"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "tab_close",
|
||||
description: "❌ Close specific tab(s) by ID or close current tab (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
tab_id: {
|
||||
type: "number",
|
||||
description: "Specific tab ID to close (optional, closes current tab if not provided)"
|
||||
},
|
||||
tab_ids: {
|
||||
type: "array",
|
||||
items: { type: "number" },
|
||||
description: "Array of tab IDs to close multiple tabs"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "tab_list",
|
||||
description: "📋 Get list of all open tabs with their details (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
current_window_only: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Only return tabs from the current window"
|
||||
},
|
||||
include_details: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Include additional tab details (title, favicon, etc.)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "tab_switch",
|
||||
description: "🔄 Switch to a specific tab by ID (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
tab_id: {
|
||||
type: "number",
|
||||
description: "Tab ID to switch to"
|
||||
}
|
||||
},
|
||||
required: ["tab_id"]
|
||||
}
|
||||
},
|
||||
// Element State Tools
|
||||
{
|
||||
name: "element_get_state",
|
||||
description: "🔍 Get detailed state information for a specific element (disabled, clickable, etc.) (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
element_id: {
|
||||
type: "string",
|
||||
description: "Element ID from page_analyze"
|
||||
}
|
||||
},
|
||||
required: ["element_id"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "browser_execute_script",
|
||||
description:
|
||||
@@ -526,6 +878,180 @@ function getFallbackTools() {
|
||||
required: ["code"],
|
||||
},
|
||||
},
|
||||
// Workspace and Reference Management Tools
|
||||
{
|
||||
name: "get_bookmarks",
|
||||
description: "Get all bookmarks or search for specific bookmarks (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
query: {
|
||||
type: "string",
|
||||
description: "Search query for bookmarks (optional)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "add_bookmark",
|
||||
description: "Add a new bookmark (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
title: {
|
||||
type: "string",
|
||||
description: "Title of the bookmark"
|
||||
},
|
||||
url: {
|
||||
type: "string",
|
||||
description: "URL of the bookmark"
|
||||
},
|
||||
parentId: {
|
||||
type: "string",
|
||||
description: "ID of the parent folder (optional)"
|
||||
}
|
||||
},
|
||||
required: ["title", "url"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "get_history",
|
||||
description: "🕒 Search browser history with comprehensive filters for finding previous work (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
keywords: {
|
||||
type: "string",
|
||||
description: "Search keywords to match in page titles and URLs"
|
||||
},
|
||||
start_date: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
description: "Start date for history search (ISO 8601 format)"
|
||||
},
|
||||
end_date: {
|
||||
type: "string",
|
||||
format: "date-time",
|
||||
description: "End date for history search (ISO 8601 format)"
|
||||
},
|
||||
domains: {
|
||||
type: "array",
|
||||
items: { type: "string" },
|
||||
description: "Filter by specific domains"
|
||||
},
|
||||
min_visit_count: {
|
||||
type: "number",
|
||||
default: 1,
|
||||
description: "Minimum visit count threshold"
|
||||
},
|
||||
max_results: {
|
||||
type: "number",
|
||||
default: 50,
|
||||
maximum: 500,
|
||||
description: "Maximum number of results to return"
|
||||
},
|
||||
sort_by: {
|
||||
type: "string",
|
||||
enum: ["visit_time", "visit_count", "title"],
|
||||
default: "visit_time",
|
||||
description: "Sort results by visit time, visit count, or title"
|
||||
},
|
||||
sort_order: {
|
||||
type: "string",
|
||||
enum: ["desc", "asc"],
|
||||
default: "desc",
|
||||
description: "Sort order"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "get_selected_text",
|
||||
description: "📝 Get the currently selected text on the page (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
include_metadata: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Include metadata about the selection (element info, position, etc.)"
|
||||
},
|
||||
max_length: {
|
||||
type: "number",
|
||||
default: 10000,
|
||||
description: "Maximum length of text to return"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "page_scroll",
|
||||
description: "📜 Scroll the page in various directions - critical for long pages (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
direction: {
|
||||
type: "string",
|
||||
enum: ["up", "down", "left", "right", "top", "bottom"],
|
||||
default: "down",
|
||||
description: "Direction to scroll"
|
||||
},
|
||||
amount: {
|
||||
type: "string",
|
||||
enum: ["small", "medium", "large", "page", "custom"],
|
||||
default: "medium",
|
||||
description: "Amount to scroll"
|
||||
},
|
||||
pixels: {
|
||||
type: "number",
|
||||
description: "Custom pixel amount (when amount is 'custom')"
|
||||
},
|
||||
smooth: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Use smooth scrolling animation"
|
||||
},
|
||||
element_id: {
|
||||
type: "string",
|
||||
description: "Scroll to specific element (overrides direction/amount)"
|
||||
},
|
||||
wait_after: {
|
||||
type: "number",
|
||||
default: 500,
|
||||
description: "Milliseconds to wait after scrolling"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "get_page_links",
|
||||
description: "🔗 Get all hyperlinks on the current page with smart filtering (Extension required)",
|
||||
inputSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
include_internal: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Include internal links (same domain)"
|
||||
},
|
||||
include_external: {
|
||||
type: "boolean",
|
||||
default: true,
|
||||
description: "Include external links (different domains)"
|
||||
},
|
||||
domain_filter: {
|
||||
type: "string",
|
||||
description: "Filter links to include only specific domain(s)"
|
||||
},
|
||||
max_results: {
|
||||
type: "number",
|
||||
default: 100,
|
||||
maximum: 500,
|
||||
description: "Maximum number of links to return"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user