first commit
This commit is contained in:
116
app/chrome-extension/common/constants.ts
Normal file
116
app/chrome-extension/common/constants.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Chrome Extension Constants
|
||||
* Centralized configuration values and magic constants
|
||||
*/
|
||||
|
||||
// Native Host Configuration
|
||||
export const NATIVE_HOST = {
|
||||
NAME: 'com.chromemcp.nativehost',
|
||||
DEFAULT_PORT: 12306,
|
||||
} as const;
|
||||
|
||||
// Chrome Extension Icons
|
||||
export const ICONS = {
|
||||
NOTIFICATION: 'icon/48.png',
|
||||
} as const;
|
||||
|
||||
// Timeouts and Delays (in milliseconds)
|
||||
export const TIMEOUTS = {
|
||||
DEFAULT_WAIT: 1000,
|
||||
NETWORK_CAPTURE_MAX: 30000,
|
||||
NETWORK_CAPTURE_IDLE: 3000,
|
||||
SCREENSHOT_DELAY: 100,
|
||||
KEYBOARD_DELAY: 50,
|
||||
CLICK_DELAY: 100,
|
||||
} as const;
|
||||
|
||||
// Limits and Thresholds
|
||||
export const LIMITS = {
|
||||
MAX_NETWORK_REQUESTS: 100,
|
||||
MAX_SEARCH_RESULTS: 50,
|
||||
MAX_BOOKMARK_RESULTS: 100,
|
||||
MAX_HISTORY_RESULTS: 100,
|
||||
SIMILARITY_THRESHOLD: 0.1,
|
||||
VECTOR_DIMENSIONS: 384,
|
||||
} as const;
|
||||
|
||||
// Error Messages
|
||||
export const ERROR_MESSAGES = {
|
||||
NATIVE_CONNECTION_FAILED: 'Failed to connect to native host',
|
||||
NATIVE_DISCONNECTED: 'Native connection disconnected',
|
||||
SERVER_STATUS_LOAD_FAILED: 'Failed to load server status',
|
||||
SERVER_STATUS_SAVE_FAILED: 'Failed to save server status',
|
||||
TOOL_EXECUTION_FAILED: 'Tool execution failed',
|
||||
INVALID_PARAMETERS: 'Invalid parameters provided',
|
||||
PERMISSION_DENIED: 'Permission denied',
|
||||
TAB_NOT_FOUND: 'Tab not found',
|
||||
ELEMENT_NOT_FOUND: 'Element not found',
|
||||
NETWORK_ERROR: 'Network error occurred',
|
||||
} as const;
|
||||
|
||||
// Success Messages
|
||||
export const SUCCESS_MESSAGES = {
|
||||
TOOL_EXECUTED: 'Tool executed successfully',
|
||||
CONNECTION_ESTABLISHED: 'Connection established',
|
||||
SERVER_STARTED: 'Server started successfully',
|
||||
SERVER_STOPPED: 'Server stopped successfully',
|
||||
} as const;
|
||||
|
||||
// File Extensions and MIME Types
|
||||
export const FILE_TYPES = {
|
||||
STATIC_EXTENSIONS: [
|
||||
'.css',
|
||||
'.js',
|
||||
'.png',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.gif',
|
||||
'.svg',
|
||||
'.ico',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.ttf',
|
||||
],
|
||||
FILTERED_MIME_TYPES: ['text/html', 'text/css', 'text/javascript', 'application/javascript'],
|
||||
IMAGE_FORMATS: ['png', 'jpeg', 'webp'] as const,
|
||||
} as const;
|
||||
|
||||
// Network Filtering
|
||||
export const NETWORK_FILTERS = {
|
||||
EXCLUDED_DOMAINS: [
|
||||
'google-analytics.com',
|
||||
'googletagmanager.com',
|
||||
'facebook.com',
|
||||
'doubleclick.net',
|
||||
'googlesyndication.com',
|
||||
],
|
||||
STATIC_RESOURCE_TYPES: ['stylesheet', 'image', 'font', 'media', 'other'],
|
||||
} as const;
|
||||
|
||||
// Semantic Similarity Configuration
|
||||
export const SEMANTIC_CONFIG = {
|
||||
DEFAULT_MODEL: 'sentence-transformers/all-MiniLM-L6-v2',
|
||||
CHUNK_SIZE: 512,
|
||||
CHUNK_OVERLAP: 50,
|
||||
BATCH_SIZE: 32,
|
||||
CACHE_SIZE: 1000,
|
||||
} as const;
|
||||
|
||||
// Storage Keys
|
||||
export const STORAGE_KEYS = {
|
||||
SERVER_STATUS: 'serverStatus',
|
||||
SEMANTIC_MODEL: 'selectedModel',
|
||||
USER_PREFERENCES: 'userPreferences',
|
||||
VECTOR_INDEX: 'vectorIndex',
|
||||
} as const;
|
||||
|
||||
// Notification Configuration
|
||||
export const NOTIFICATIONS = {
|
||||
PRIORITY: 2,
|
||||
TYPE: 'basic' as const,
|
||||
} as const;
|
||||
|
||||
export enum ExecutionWorld {
|
||||
ISOLATED = 'ISOLATED',
|
||||
MAIN = 'MAIN',
|
||||
}
|
114
app/chrome-extension/common/message-types.ts
Normal file
114
app/chrome-extension/common/message-types.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Consolidated message type constants for Chrome extension communication
|
||||
* Note: Native message types are imported from the shared package
|
||||
*/
|
||||
|
||||
// Message targets for routing
|
||||
export enum MessageTarget {
|
||||
Offscreen = 'offscreen',
|
||||
ContentScript = 'content_script',
|
||||
Background = 'background',
|
||||
}
|
||||
|
||||
// Background script message types
|
||||
export const BACKGROUND_MESSAGE_TYPES = {
|
||||
SWITCH_SEMANTIC_MODEL: 'switch_semantic_model',
|
||||
GET_MODEL_STATUS: 'get_model_status',
|
||||
UPDATE_MODEL_STATUS: 'update_model_status',
|
||||
GET_STORAGE_STATS: 'get_storage_stats',
|
||||
CLEAR_ALL_DATA: 'clear_all_data',
|
||||
GET_SERVER_STATUS: 'get_server_status',
|
||||
REFRESH_SERVER_STATUS: 'refresh_server_status',
|
||||
SERVER_STATUS_CHANGED: 'server_status_changed',
|
||||
INITIALIZE_SEMANTIC_ENGINE: 'initialize_semantic_engine',
|
||||
} as const;
|
||||
|
||||
// Offscreen message types
|
||||
export const OFFSCREEN_MESSAGE_TYPES = {
|
||||
SIMILARITY_ENGINE_INIT: 'similarityEngineInit',
|
||||
SIMILARITY_ENGINE_COMPUTE: 'similarityEngineCompute',
|
||||
SIMILARITY_ENGINE_BATCH_COMPUTE: 'similarityEngineBatchCompute',
|
||||
SIMILARITY_ENGINE_STATUS: 'similarityEngineStatus',
|
||||
} as const;
|
||||
|
||||
// Content script message types
|
||||
export const CONTENT_MESSAGE_TYPES = {
|
||||
WEB_FETCHER_GET_TEXT_CONTENT: 'webFetcherGetTextContent',
|
||||
WEB_FETCHER_GET_HTML_CONTENT: 'getHtmlContent',
|
||||
NETWORK_CAPTURE_PING: 'network_capture_ping',
|
||||
CLICK_HELPER_PING: 'click_helper_ping',
|
||||
FILL_HELPER_PING: 'fill_helper_ping',
|
||||
KEYBOARD_HELPER_PING: 'keyboard_helper_ping',
|
||||
SCREENSHOT_HELPER_PING: 'screenshot_helper_ping',
|
||||
INTERACTIVE_ELEMENTS_HELPER_PING: 'interactive_elements_helper_ping',
|
||||
} as const;
|
||||
|
||||
// Tool action message types (for chrome.runtime.sendMessage)
|
||||
export const TOOL_MESSAGE_TYPES = {
|
||||
// Screenshot related
|
||||
SCREENSHOT_PREPARE_PAGE_FOR_CAPTURE: 'preparePageForCapture',
|
||||
SCREENSHOT_GET_PAGE_DETAILS: 'getPageDetails',
|
||||
SCREENSHOT_GET_ELEMENT_DETAILS: 'getElementDetails',
|
||||
SCREENSHOT_SCROLL_PAGE: 'scrollPage',
|
||||
SCREENSHOT_RESET_PAGE_AFTER_CAPTURE: 'resetPageAfterCapture',
|
||||
|
||||
// Web content fetching
|
||||
WEB_FETCHER_GET_HTML_CONTENT: 'getHtmlContent',
|
||||
WEB_FETCHER_GET_TEXT_CONTENT: 'getTextContent',
|
||||
|
||||
// User interactions
|
||||
CLICK_ELEMENT: 'clickElement',
|
||||
FILL_ELEMENT: 'fillElement',
|
||||
SIMULATE_KEYBOARD: 'simulateKeyboard',
|
||||
|
||||
// Interactive elements
|
||||
GET_INTERACTIVE_ELEMENTS: 'getInteractiveElements',
|
||||
|
||||
// Network requests
|
||||
NETWORK_SEND_REQUEST: 'sendPureNetworkRequest',
|
||||
|
||||
// Semantic similarity engine
|
||||
SIMILARITY_ENGINE_INIT: 'similarityEngineInit',
|
||||
SIMILARITY_ENGINE_COMPUTE_BATCH: 'similarityEngineComputeBatch',
|
||||
} as const;
|
||||
|
||||
// Type unions for type safety
|
||||
export type BackgroundMessageType =
|
||||
(typeof BACKGROUND_MESSAGE_TYPES)[keyof typeof BACKGROUND_MESSAGE_TYPES];
|
||||
export type OffscreenMessageType =
|
||||
(typeof OFFSCREEN_MESSAGE_TYPES)[keyof typeof OFFSCREEN_MESSAGE_TYPES];
|
||||
export type ContentMessageType = (typeof CONTENT_MESSAGE_TYPES)[keyof typeof CONTENT_MESSAGE_TYPES];
|
||||
export type ToolMessageType = (typeof TOOL_MESSAGE_TYPES)[keyof typeof TOOL_MESSAGE_TYPES];
|
||||
|
||||
// Legacy enum for backward compatibility (will be deprecated)
|
||||
export enum SendMessageType {
|
||||
// Screenshot related message types
|
||||
ScreenshotPreparePageForCapture = 'preparePageForCapture',
|
||||
ScreenshotGetPageDetails = 'getPageDetails',
|
||||
ScreenshotGetElementDetails = 'getElementDetails',
|
||||
ScreenshotScrollPage = 'scrollPage',
|
||||
ScreenshotResetPageAfterCapture = 'resetPageAfterCapture',
|
||||
|
||||
// Web content fetching related message types
|
||||
WebFetcherGetHtmlContent = 'getHtmlContent',
|
||||
WebFetcherGetTextContent = 'getTextContent',
|
||||
|
||||
// Click related message types
|
||||
ClickElement = 'clickElement',
|
||||
|
||||
// Input filling related message types
|
||||
FillElement = 'fillElement',
|
||||
|
||||
// Interactive elements related message types
|
||||
GetInteractiveElements = 'getInteractiveElements',
|
||||
|
||||
// Network request capture related message types
|
||||
NetworkSendRequest = 'sendPureNetworkRequest',
|
||||
|
||||
// Keyboard event related message types
|
||||
SimulateKeyboard = 'simulateKeyboard',
|
||||
|
||||
// Semantic similarity engine related message types
|
||||
SimilarityEngineInit = 'similarityEngineInit',
|
||||
SimilarityEngineComputeBatch = 'similarityEngineComputeBatch',
|
||||
}
|
24
app/chrome-extension/common/tool-handler.ts
Normal file
24
app/chrome-extension/common/tool-handler.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { CallToolResult, TextContent, ImageContent } from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
export interface ToolResult extends CallToolResult {
|
||||
content: (TextContent | ImageContent)[];
|
||||
isError: boolean;
|
||||
}
|
||||
|
||||
export interface ToolExecutor {
|
||||
execute(args: any): Promise<ToolResult>;
|
||||
}
|
||||
|
||||
export const createErrorResponse = (
|
||||
message: string = 'Unknown error, please try again',
|
||||
): ToolResult => {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: message,
|
||||
},
|
||||
],
|
||||
isError: true,
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user