first commit
This commit is contained in:
BIN
releases/chrome-extension/latest/chrome-mcp-server-lastest.zip
Normal file
BIN
releases/chrome-extension/latest/chrome-mcp-server-lastest.zip
Normal file
Binary file not shown.
@@ -0,0 +1,446 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "chrome-mcp-server",
|
||||
"description": "Extension name"
|
||||
},
|
||||
"extensionDescription": {
|
||||
"message": "Exposes browser capabilities with your own chrome",
|
||||
"description": "Extension description"
|
||||
},
|
||||
"nativeServerConfigLabel": {
|
||||
"message": "Native Server Configuration",
|
||||
"description": "Main section header for native server settings"
|
||||
},
|
||||
"semanticEngineLabel": {
|
||||
"message": "Semantic Engine",
|
||||
"description": "Main section header for semantic engine"
|
||||
},
|
||||
"embeddingModelLabel": {
|
||||
"message": "Embedding Model",
|
||||
"description": "Main section header for model selection"
|
||||
},
|
||||
"indexDataManagementLabel": {
|
||||
"message": "Index Data Management",
|
||||
"description": "Main section header for data management"
|
||||
},
|
||||
"modelCacheManagementLabel": {
|
||||
"message": "Model Cache Management",
|
||||
"description": "Main section header for cache management"
|
||||
},
|
||||
"statusLabel": {
|
||||
"message": "Status",
|
||||
"description": "Generic status label"
|
||||
},
|
||||
"runningStatusLabel": {
|
||||
"message": "Running Status",
|
||||
"description": "Server running status label"
|
||||
},
|
||||
"connectionStatusLabel": {
|
||||
"message": "Connection Status",
|
||||
"description": "Connection status label"
|
||||
},
|
||||
"lastUpdatedLabel": {
|
||||
"message": "Last Updated:",
|
||||
"description": "Last updated timestamp label"
|
||||
},
|
||||
"connectButton": {
|
||||
"message": "Connect",
|
||||
"description": "Connect button text"
|
||||
},
|
||||
"disconnectButton": {
|
||||
"message": "Disconnect",
|
||||
"description": "Disconnect button text"
|
||||
},
|
||||
"connectingStatus": {
|
||||
"message": "Connecting...",
|
||||
"description": "Connecting status message"
|
||||
},
|
||||
"connectedStatus": {
|
||||
"message": "Connected",
|
||||
"description": "Connected status message"
|
||||
},
|
||||
"disconnectedStatus": {
|
||||
"message": "Disconnected",
|
||||
"description": "Disconnected status message"
|
||||
},
|
||||
"detectingStatus": {
|
||||
"message": "Detecting...",
|
||||
"description": "Detecting status message"
|
||||
},
|
||||
"serviceRunningStatus": {
|
||||
"message": "Service Running (Port: $PORT$)",
|
||||
"description": "Service running with port number",
|
||||
"placeholders": {
|
||||
"port": {
|
||||
"content": "$1",
|
||||
"example": "12306"
|
||||
}
|
||||
}
|
||||
},
|
||||
"serviceNotConnectedStatus": {
|
||||
"message": "Service Not Connected",
|
||||
"description": "Service not connected status"
|
||||
},
|
||||
"connectedServiceNotStartedStatus": {
|
||||
"message": "Connected, Service Not Started",
|
||||
"description": "Connected but service not started status"
|
||||
},
|
||||
"mcpServerConfigLabel": {
|
||||
"message": "MCP Server Configuration",
|
||||
"description": "MCP server configuration section label"
|
||||
},
|
||||
"connectionPortLabel": {
|
||||
"message": "Connection Port",
|
||||
"description": "Connection port input label"
|
||||
},
|
||||
"refreshStatusButton": {
|
||||
"message": "Refresh Status",
|
||||
"description": "Refresh status button tooltip"
|
||||
},
|
||||
"copyConfigButton": {
|
||||
"message": "Copy Configuration",
|
||||
"description": "Copy configuration button text"
|
||||
},
|
||||
"retryButton": {
|
||||
"message": "Retry",
|
||||
"description": "Retry button text"
|
||||
},
|
||||
"cancelButton": {
|
||||
"message": "Cancel",
|
||||
"description": "Cancel button text"
|
||||
},
|
||||
"confirmButton": {
|
||||
"message": "Confirm",
|
||||
"description": "Confirm button text"
|
||||
},
|
||||
"saveButton": {
|
||||
"message": "Save",
|
||||
"description": "Save button text"
|
||||
},
|
||||
"closeButton": {
|
||||
"message": "Close",
|
||||
"description": "Close button text"
|
||||
},
|
||||
"resetButton": {
|
||||
"message": "Reset",
|
||||
"description": "Reset button text"
|
||||
},
|
||||
"initializingStatus": {
|
||||
"message": "Initializing...",
|
||||
"description": "Initializing progress message"
|
||||
},
|
||||
"processingStatus": {
|
||||
"message": "Processing...",
|
||||
"description": "Processing progress message"
|
||||
},
|
||||
"loadingStatus": {
|
||||
"message": "Loading...",
|
||||
"description": "Loading progress message"
|
||||
},
|
||||
"clearingStatus": {
|
||||
"message": "Clearing...",
|
||||
"description": "Clearing progress message"
|
||||
},
|
||||
"cleaningStatus": {
|
||||
"message": "Cleaning...",
|
||||
"description": "Cleaning progress message"
|
||||
},
|
||||
"downloadingStatus": {
|
||||
"message": "Downloading...",
|
||||
"description": "Downloading progress message"
|
||||
},
|
||||
"semanticEngineReadyStatus": {
|
||||
"message": "Semantic Engine Ready",
|
||||
"description": "Semantic engine ready status"
|
||||
},
|
||||
"semanticEngineInitializingStatus": {
|
||||
"message": "Semantic Engine Initializing...",
|
||||
"description": "Semantic engine initializing status"
|
||||
},
|
||||
"semanticEngineInitFailedStatus": {
|
||||
"message": "Semantic Engine Initialization Failed",
|
||||
"description": "Semantic engine initialization failed status"
|
||||
},
|
||||
"semanticEngineNotInitStatus": {
|
||||
"message": "Semantic Engine Not Initialized",
|
||||
"description": "Semantic engine not initialized status"
|
||||
},
|
||||
"initSemanticEngineButton": {
|
||||
"message": "Initialize Semantic Engine",
|
||||
"description": "Initialize semantic engine button text"
|
||||
},
|
||||
"reinitializeButton": {
|
||||
"message": "Reinitialize",
|
||||
"description": "Reinitialize button text"
|
||||
},
|
||||
"downloadingModelStatus": {
|
||||
"message": "Downloading Model... $PROGRESS$%",
|
||||
"description": "Model download progress with percentage",
|
||||
"placeholders": {
|
||||
"progress": {
|
||||
"content": "$1",
|
||||
"example": "50"
|
||||
}
|
||||
}
|
||||
},
|
||||
"switchingModelStatus": {
|
||||
"message": "Switching Model...",
|
||||
"description": "Model switching progress message"
|
||||
},
|
||||
"modelLoadedStatus": {
|
||||
"message": "Model Loaded",
|
||||
"description": "Model successfully loaded status"
|
||||
},
|
||||
"modelFailedStatus": {
|
||||
"message": "Model Failed to Load",
|
||||
"description": "Model failed to load status"
|
||||
},
|
||||
"lightweightModelDescription": {
|
||||
"message": "Lightweight Multilingual Model",
|
||||
"description": "Description for lightweight model option"
|
||||
},
|
||||
"betterThanSmallDescription": {
|
||||
"message": "Slightly larger than e5-small, but better performance",
|
||||
"description": "Description for medium model option"
|
||||
},
|
||||
"multilingualModelDescription": {
|
||||
"message": "Multilingual Semantic Model",
|
||||
"description": "Description for multilingual model option"
|
||||
},
|
||||
"fastPerformance": {
|
||||
"message": "Fast",
|
||||
"description": "Fast performance indicator"
|
||||
},
|
||||
"balancedPerformance": {
|
||||
"message": "Balanced",
|
||||
"description": "Balanced performance indicator"
|
||||
},
|
||||
"accuratePerformance": {
|
||||
"message": "Accurate",
|
||||
"description": "Accurate performance indicator"
|
||||
},
|
||||
"networkErrorMessage": {
|
||||
"message": "Network connection error, please check network and retry",
|
||||
"description": "Network connection error message"
|
||||
},
|
||||
"modelCorruptedErrorMessage": {
|
||||
"message": "Model file corrupted or incomplete, please retry download",
|
||||
"description": "Model corruption error message"
|
||||
},
|
||||
"unknownErrorMessage": {
|
||||
"message": "Unknown error, please check if your network can access HuggingFace",
|
||||
"description": "Unknown error fallback message"
|
||||
},
|
||||
"permissionDeniedErrorMessage": {
|
||||
"message": "Permission denied",
|
||||
"description": "Permission denied error message"
|
||||
},
|
||||
"timeoutErrorMessage": {
|
||||
"message": "Operation timed out",
|
||||
"description": "Timeout error message"
|
||||
},
|
||||
"indexedPagesLabel": {
|
||||
"message": "Indexed Pages",
|
||||
"description": "Number of indexed pages label"
|
||||
},
|
||||
"indexSizeLabel": {
|
||||
"message": "Index Size",
|
||||
"description": "Index size label"
|
||||
},
|
||||
"activeTabsLabel": {
|
||||
"message": "Active Tabs",
|
||||
"description": "Number of active tabs label"
|
||||
},
|
||||
"vectorDocumentsLabel": {
|
||||
"message": "Vector Documents",
|
||||
"description": "Number of vector documents label"
|
||||
},
|
||||
"cacheSizeLabel": {
|
||||
"message": "Cache Size",
|
||||
"description": "Cache size label"
|
||||
},
|
||||
"cacheEntriesLabel": {
|
||||
"message": "Cache Entries",
|
||||
"description": "Number of cache entries label"
|
||||
},
|
||||
"clearAllDataButton": {
|
||||
"message": "Clear All Data",
|
||||
"description": "Clear all data button text"
|
||||
},
|
||||
"clearAllCacheButton": {
|
||||
"message": "Clear All Cache",
|
||||
"description": "Clear all cache button text"
|
||||
},
|
||||
"cleanExpiredCacheButton": {
|
||||
"message": "Clean Expired Cache",
|
||||
"description": "Clean expired cache button text"
|
||||
},
|
||||
"exportDataButton": {
|
||||
"message": "Export Data",
|
||||
"description": "Export data button text"
|
||||
},
|
||||
"importDataButton": {
|
||||
"message": "Import Data",
|
||||
"description": "Import data button text"
|
||||
},
|
||||
"confirmClearDataTitle": {
|
||||
"message": "Confirm Clear Data",
|
||||
"description": "Clear data confirmation dialog title"
|
||||
},
|
||||
"settingsTitle": {
|
||||
"message": "Settings",
|
||||
"description": "Settings dialog title"
|
||||
},
|
||||
"aboutTitle": {
|
||||
"message": "About",
|
||||
"description": "About dialog title"
|
||||
},
|
||||
"helpTitle": {
|
||||
"message": "Help",
|
||||
"description": "Help dialog title"
|
||||
},
|
||||
"clearDataWarningMessage": {
|
||||
"message": "This operation will clear all indexed webpage content and vector data, including:",
|
||||
"description": "Clear data warning message"
|
||||
},
|
||||
"clearDataList1": {
|
||||
"message": "All webpage text content index",
|
||||
"description": "First item in clear data list"
|
||||
},
|
||||
"clearDataList2": {
|
||||
"message": "Vector embedding data",
|
||||
"description": "Second item in clear data list"
|
||||
},
|
||||
"clearDataList3": {
|
||||
"message": "Search history and cache",
|
||||
"description": "Third item in clear data list"
|
||||
},
|
||||
"clearDataIrreversibleWarning": {
|
||||
"message": "This operation is irreversible! After clearing, you need to browse webpages again to rebuild the index.",
|
||||
"description": "Irreversible operation warning"
|
||||
},
|
||||
"confirmClearButton": {
|
||||
"message": "Confirm Clear",
|
||||
"description": "Confirm clear action button"
|
||||
},
|
||||
"cacheDetailsLabel": {
|
||||
"message": "Cache Details",
|
||||
"description": "Cache details section label"
|
||||
},
|
||||
"noCacheDataMessage": {
|
||||
"message": "No cache data",
|
||||
"description": "No cache data available message"
|
||||
},
|
||||
"loadingCacheInfoStatus": {
|
||||
"message": "Loading cache information...",
|
||||
"description": "Loading cache information status"
|
||||
},
|
||||
"processingCacheStatus": {
|
||||
"message": "Processing cache...",
|
||||
"description": "Processing cache status"
|
||||
},
|
||||
"expiredLabel": {
|
||||
"message": "Expired",
|
||||
"description": "Expired item label"
|
||||
},
|
||||
"bookmarksBarLabel": {
|
||||
"message": "Bookmarks Bar",
|
||||
"description": "Bookmarks bar folder name"
|
||||
},
|
||||
"newTabLabel": {
|
||||
"message": "New Tab",
|
||||
"description": "New tab label"
|
||||
},
|
||||
"currentPageLabel": {
|
||||
"message": "Current Page",
|
||||
"description": "Current page label"
|
||||
},
|
||||
"menuLabel": {
|
||||
"message": "Menu",
|
||||
"description": "Menu accessibility label"
|
||||
},
|
||||
"navigationLabel": {
|
||||
"message": "Navigation",
|
||||
"description": "Navigation accessibility label"
|
||||
},
|
||||
"mainContentLabel": {
|
||||
"message": "Main Content",
|
||||
"description": "Main content accessibility label"
|
||||
},
|
||||
"languageSelectorLabel": {
|
||||
"message": "Language",
|
||||
"description": "Language selector label"
|
||||
},
|
||||
"themeLabel": {
|
||||
"message": "Theme",
|
||||
"description": "Theme selector label"
|
||||
},
|
||||
"lightTheme": {
|
||||
"message": "Light",
|
||||
"description": "Light theme option"
|
||||
},
|
||||
"darkTheme": {
|
||||
"message": "Dark",
|
||||
"description": "Dark theme option"
|
||||
},
|
||||
"autoTheme": {
|
||||
"message": "Auto",
|
||||
"description": "Auto theme option"
|
||||
},
|
||||
"advancedSettingsLabel": {
|
||||
"message": "Advanced Settings",
|
||||
"description": "Advanced settings section label"
|
||||
},
|
||||
"debugModeLabel": {
|
||||
"message": "Debug Mode",
|
||||
"description": "Debug mode toggle label"
|
||||
},
|
||||
"verboseLoggingLabel": {
|
||||
"message": "Verbose Logging",
|
||||
"description": "Verbose logging toggle label"
|
||||
},
|
||||
"successNotification": {
|
||||
"message": "Operation completed successfully",
|
||||
"description": "Generic success notification"
|
||||
},
|
||||
"warningNotification": {
|
||||
"message": "Warning: Please review before proceeding",
|
||||
"description": "Generic warning notification"
|
||||
},
|
||||
"infoNotification": {
|
||||
"message": "Information",
|
||||
"description": "Generic info notification"
|
||||
},
|
||||
"configCopiedNotification": {
|
||||
"message": "Configuration copied to clipboard",
|
||||
"description": "Configuration copied success message"
|
||||
},
|
||||
"dataClearedNotification": {
|
||||
"message": "Data cleared successfully",
|
||||
"description": "Data cleared success message"
|
||||
},
|
||||
"bytesUnit": {
|
||||
"message": "bytes",
|
||||
"description": "Bytes unit"
|
||||
},
|
||||
"kilobytesUnit": {
|
||||
"message": "KB",
|
||||
"description": "Kilobytes unit"
|
||||
},
|
||||
"megabytesUnit": {
|
||||
"message": "MB",
|
||||
"description": "Megabytes unit"
|
||||
},
|
||||
"gigabytesUnit": {
|
||||
"message": "GB",
|
||||
"description": "Gigabytes unit"
|
||||
},
|
||||
"itemsUnit": {
|
||||
"message": "items",
|
||||
"description": "Items count unit"
|
||||
},
|
||||
"pagesUnit": {
|
||||
"message": "pages",
|
||||
"description": "Pages count unit"
|
||||
}
|
||||
}
|
@@ -0,0 +1,446 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "chrome-mcp-server",
|
||||
"description": "扩展名称"
|
||||
},
|
||||
"extensionDescription": {
|
||||
"message": "使用你自己的 Chrome 浏览器暴露浏览器功能",
|
||||
"description": "扩展描述"
|
||||
},
|
||||
"nativeServerConfigLabel": {
|
||||
"message": "Native Server 配置",
|
||||
"description": "本地服务器设置的主要节标题"
|
||||
},
|
||||
"semanticEngineLabel": {
|
||||
"message": "语义引擎",
|
||||
"description": "语义引擎的主要节标题"
|
||||
},
|
||||
"embeddingModelLabel": {
|
||||
"message": "Embedding模型",
|
||||
"description": "模型选择的主要节标题"
|
||||
},
|
||||
"indexDataManagementLabel": {
|
||||
"message": "索引数据管理",
|
||||
"description": "数据管理的主要节标题"
|
||||
},
|
||||
"modelCacheManagementLabel": {
|
||||
"message": "模型缓存管理",
|
||||
"description": "缓存管理的主要节标题"
|
||||
},
|
||||
"statusLabel": {
|
||||
"message": "状态",
|
||||
"description": "通用状态标签"
|
||||
},
|
||||
"runningStatusLabel": {
|
||||
"message": "运行状态",
|
||||
"description": "服务器运行状态标签"
|
||||
},
|
||||
"connectionStatusLabel": {
|
||||
"message": "连接状态",
|
||||
"description": "连接状态标签"
|
||||
},
|
||||
"lastUpdatedLabel": {
|
||||
"message": "最后更新:",
|
||||
"description": "最后更新时间戳标签"
|
||||
},
|
||||
"connectButton": {
|
||||
"message": "连接",
|
||||
"description": "连接按钮文本"
|
||||
},
|
||||
"disconnectButton": {
|
||||
"message": "断开",
|
||||
"description": "断开连接按钮文本"
|
||||
},
|
||||
"connectingStatus": {
|
||||
"message": "连接中...",
|
||||
"description": "连接状态消息"
|
||||
},
|
||||
"connectedStatus": {
|
||||
"message": "已连接",
|
||||
"description": "已连接状态消息"
|
||||
},
|
||||
"disconnectedStatus": {
|
||||
"message": "已断开",
|
||||
"description": "已断开状态消息"
|
||||
},
|
||||
"detectingStatus": {
|
||||
"message": "检测中...",
|
||||
"description": "检测状态消息"
|
||||
},
|
||||
"serviceRunningStatus": {
|
||||
"message": "服务运行中 (端口: $PORT$)",
|
||||
"description": "带端口号的服务运行状态",
|
||||
"placeholders": {
|
||||
"port": {
|
||||
"content": "$1",
|
||||
"example": "12306"
|
||||
}
|
||||
}
|
||||
},
|
||||
"serviceNotConnectedStatus": {
|
||||
"message": "服务未连接",
|
||||
"description": "服务未连接状态"
|
||||
},
|
||||
"connectedServiceNotStartedStatus": {
|
||||
"message": "已连接,服务未启动",
|
||||
"description": "已连接但服务未启动状态"
|
||||
},
|
||||
"mcpServerConfigLabel": {
|
||||
"message": "MCP 服务器配置",
|
||||
"description": "MCP 服务器配置节标签"
|
||||
},
|
||||
"connectionPortLabel": {
|
||||
"message": "连接端口",
|
||||
"description": "连接端口输入标签"
|
||||
},
|
||||
"refreshStatusButton": {
|
||||
"message": "刷新状态",
|
||||
"description": "刷新状态按钮提示"
|
||||
},
|
||||
"copyConfigButton": {
|
||||
"message": "复制配置",
|
||||
"description": "复制配置按钮文本"
|
||||
},
|
||||
"retryButton": {
|
||||
"message": "重试",
|
||||
"description": "重试按钮文本"
|
||||
},
|
||||
"cancelButton": {
|
||||
"message": "取消",
|
||||
"description": "取消按钮文本"
|
||||
},
|
||||
"confirmButton": {
|
||||
"message": "确认",
|
||||
"description": "确认按钮文本"
|
||||
},
|
||||
"saveButton": {
|
||||
"message": "保存",
|
||||
"description": "保存按钮文本"
|
||||
},
|
||||
"closeButton": {
|
||||
"message": "关闭",
|
||||
"description": "关闭按钮文本"
|
||||
},
|
||||
"resetButton": {
|
||||
"message": "重置",
|
||||
"description": "重置按钮文本"
|
||||
},
|
||||
"initializingStatus": {
|
||||
"message": "初始化中...",
|
||||
"description": "初始化进度消息"
|
||||
},
|
||||
"processingStatus": {
|
||||
"message": "处理中...",
|
||||
"description": "处理进度消息"
|
||||
},
|
||||
"loadingStatus": {
|
||||
"message": "加载中...",
|
||||
"description": "加载进度消息"
|
||||
},
|
||||
"clearingStatus": {
|
||||
"message": "清空中...",
|
||||
"description": "清空进度消息"
|
||||
},
|
||||
"cleaningStatus": {
|
||||
"message": "清理中...",
|
||||
"description": "清理进度消息"
|
||||
},
|
||||
"downloadingStatus": {
|
||||
"message": "下载中...",
|
||||
"description": "下载进度消息"
|
||||
},
|
||||
"semanticEngineReadyStatus": {
|
||||
"message": "语义引擎已就绪",
|
||||
"description": "语义引擎就绪状态"
|
||||
},
|
||||
"semanticEngineInitializingStatus": {
|
||||
"message": "语义引擎初始化中...",
|
||||
"description": "语义引擎初始化状态"
|
||||
},
|
||||
"semanticEngineInitFailedStatus": {
|
||||
"message": "语义引擎初始化失败",
|
||||
"description": "语义引擎初始化失败状态"
|
||||
},
|
||||
"semanticEngineNotInitStatus": {
|
||||
"message": "语义引擎未初始化",
|
||||
"description": "语义引擎未初始化状态"
|
||||
},
|
||||
"initSemanticEngineButton": {
|
||||
"message": "初始化语义引擎",
|
||||
"description": "初始化语义引擎按钮文本"
|
||||
},
|
||||
"reinitializeButton": {
|
||||
"message": "重新初始化",
|
||||
"description": "重新初始化按钮文本"
|
||||
},
|
||||
"downloadingModelStatus": {
|
||||
"message": "下载模型中... $PROGRESS$%",
|
||||
"description": "带百分比的模型下载进度",
|
||||
"placeholders": {
|
||||
"progress": {
|
||||
"content": "$1",
|
||||
"example": "50"
|
||||
}
|
||||
}
|
||||
},
|
||||
"switchingModelStatus": {
|
||||
"message": "切换模型中...",
|
||||
"description": "模型切换进度消息"
|
||||
},
|
||||
"modelLoadedStatus": {
|
||||
"message": "模型已加载",
|
||||
"description": "模型成功加载状态"
|
||||
},
|
||||
"modelFailedStatus": {
|
||||
"message": "模型加载失败",
|
||||
"description": "模型加载失败状态"
|
||||
},
|
||||
"lightweightModelDescription": {
|
||||
"message": "轻量级多语言模型",
|
||||
"description": "轻量级模型选项的描述"
|
||||
},
|
||||
"betterThanSmallDescription": {
|
||||
"message": "比e5-small稍大,但效果更好",
|
||||
"description": "中等模型选项的描述"
|
||||
},
|
||||
"multilingualModelDescription": {
|
||||
"message": "多语言语义模型",
|
||||
"description": "多语言模型选项的描述"
|
||||
},
|
||||
"fastPerformance": {
|
||||
"message": "快速",
|
||||
"description": "快速性能指示器"
|
||||
},
|
||||
"balancedPerformance": {
|
||||
"message": "平衡",
|
||||
"description": "平衡性能指示器"
|
||||
},
|
||||
"accuratePerformance": {
|
||||
"message": "精确",
|
||||
"description": "精确性能指示器"
|
||||
},
|
||||
"networkErrorMessage": {
|
||||
"message": "网络连接错误,请检查网络连接后重试",
|
||||
"description": "网络连接错误消息"
|
||||
},
|
||||
"modelCorruptedErrorMessage": {
|
||||
"message": "模型文件损坏或不完整,请重试下载",
|
||||
"description": "模型损坏错误消息"
|
||||
},
|
||||
"unknownErrorMessage": {
|
||||
"message": "未知错误,请检查你的网络是否可以访问HuggingFace",
|
||||
"description": "未知错误回退消息"
|
||||
},
|
||||
"permissionDeniedErrorMessage": {
|
||||
"message": "权限被拒绝",
|
||||
"description": "权限被拒绝错误消息"
|
||||
},
|
||||
"timeoutErrorMessage": {
|
||||
"message": "操作超时",
|
||||
"description": "超时错误消息"
|
||||
},
|
||||
"indexedPagesLabel": {
|
||||
"message": "已索引页面",
|
||||
"description": "已索引页面数量标签"
|
||||
},
|
||||
"indexSizeLabel": {
|
||||
"message": "索引大小",
|
||||
"description": "索引大小标签"
|
||||
},
|
||||
"activeTabsLabel": {
|
||||
"message": "活跃标签页",
|
||||
"description": "活跃标签页数量标签"
|
||||
},
|
||||
"vectorDocumentsLabel": {
|
||||
"message": "向量文档",
|
||||
"description": "向量文档数量标签"
|
||||
},
|
||||
"cacheSizeLabel": {
|
||||
"message": "缓存大小",
|
||||
"description": "缓存大小标签"
|
||||
},
|
||||
"cacheEntriesLabel": {
|
||||
"message": "缓存条目",
|
||||
"description": "缓存条目数量标签"
|
||||
},
|
||||
"clearAllDataButton": {
|
||||
"message": "清空所有数据",
|
||||
"description": "清空所有数据按钮文本"
|
||||
},
|
||||
"clearAllCacheButton": {
|
||||
"message": "清空所有缓存",
|
||||
"description": "清空所有缓存按钮文本"
|
||||
},
|
||||
"cleanExpiredCacheButton": {
|
||||
"message": "清理过期缓存",
|
||||
"description": "清理过期缓存按钮文本"
|
||||
},
|
||||
"exportDataButton": {
|
||||
"message": "导出数据",
|
||||
"description": "导出数据按钮文本"
|
||||
},
|
||||
"importDataButton": {
|
||||
"message": "导入数据",
|
||||
"description": "导入数据按钮文本"
|
||||
},
|
||||
"confirmClearDataTitle": {
|
||||
"message": "确认清空数据",
|
||||
"description": "清空数据确认对话框标题"
|
||||
},
|
||||
"settingsTitle": {
|
||||
"message": "设置",
|
||||
"description": "设置对话框标题"
|
||||
},
|
||||
"aboutTitle": {
|
||||
"message": "关于",
|
||||
"description": "关于对话框标题"
|
||||
},
|
||||
"helpTitle": {
|
||||
"message": "帮助",
|
||||
"description": "帮助对话框标题"
|
||||
},
|
||||
"clearDataWarningMessage": {
|
||||
"message": "此操作将清空所有已索引的网页内容和向量数据,包括:",
|
||||
"description": "清空数据警告消息"
|
||||
},
|
||||
"clearDataList1": {
|
||||
"message": "所有网页的文本内容索引",
|
||||
"description": "清空数据列表第一项"
|
||||
},
|
||||
"clearDataList2": {
|
||||
"message": "向量嵌入数据",
|
||||
"description": "清空数据列表第二项"
|
||||
},
|
||||
"clearDataList3": {
|
||||
"message": "搜索历史和缓存",
|
||||
"description": "清空数据列表第三项"
|
||||
},
|
||||
"clearDataIrreversibleWarning": {
|
||||
"message": "此操作不可撤销!清空后需要重新浏览网页来重建索引。",
|
||||
"description": "不可逆操作警告"
|
||||
},
|
||||
"confirmClearButton": {
|
||||
"message": "确认清空",
|
||||
"description": "确认清空操作按钮"
|
||||
},
|
||||
"cacheDetailsLabel": {
|
||||
"message": "缓存详情",
|
||||
"description": "缓存详情节标签"
|
||||
},
|
||||
"noCacheDataMessage": {
|
||||
"message": "暂无缓存数据",
|
||||
"description": "无缓存数据可用消息"
|
||||
},
|
||||
"loadingCacheInfoStatus": {
|
||||
"message": "正在加载缓存信息...",
|
||||
"description": "加载缓存信息状态"
|
||||
},
|
||||
"processingCacheStatus": {
|
||||
"message": "处理缓存中...",
|
||||
"description": "处理缓存状态"
|
||||
},
|
||||
"expiredLabel": {
|
||||
"message": "已过期",
|
||||
"description": "过期项标签"
|
||||
},
|
||||
"bookmarksBarLabel": {
|
||||
"message": "书签栏",
|
||||
"description": "书签栏文件夹名称"
|
||||
},
|
||||
"newTabLabel": {
|
||||
"message": "新标签页",
|
||||
"description": "新标签页标签"
|
||||
},
|
||||
"currentPageLabel": {
|
||||
"message": "当前页面",
|
||||
"description": "当前页面标签"
|
||||
},
|
||||
"menuLabel": {
|
||||
"message": "菜单",
|
||||
"description": "菜单辅助功能标签"
|
||||
},
|
||||
"navigationLabel": {
|
||||
"message": "导航",
|
||||
"description": "导航辅助功能标签"
|
||||
},
|
||||
"mainContentLabel": {
|
||||
"message": "主要内容",
|
||||
"description": "主要内容辅助功能标签"
|
||||
},
|
||||
"languageSelectorLabel": {
|
||||
"message": "语言",
|
||||
"description": "语言选择器标签"
|
||||
},
|
||||
"themeLabel": {
|
||||
"message": "主题",
|
||||
"description": "主题选择器标签"
|
||||
},
|
||||
"lightTheme": {
|
||||
"message": "浅色",
|
||||
"description": "浅色主题选项"
|
||||
},
|
||||
"darkTheme": {
|
||||
"message": "深色",
|
||||
"description": "深色主题选项"
|
||||
},
|
||||
"autoTheme": {
|
||||
"message": "自动",
|
||||
"description": "自动主题选项"
|
||||
},
|
||||
"advancedSettingsLabel": {
|
||||
"message": "高级设置",
|
||||
"description": "高级设置节标签"
|
||||
},
|
||||
"debugModeLabel": {
|
||||
"message": "调试模式",
|
||||
"description": "调试模式切换标签"
|
||||
},
|
||||
"verboseLoggingLabel": {
|
||||
"message": "详细日志",
|
||||
"description": "详细日志切换标签"
|
||||
},
|
||||
"successNotification": {
|
||||
"message": "操作成功完成",
|
||||
"description": "通用成功通知"
|
||||
},
|
||||
"warningNotification": {
|
||||
"message": "警告:请在继续之前检查",
|
||||
"description": "通用警告通知"
|
||||
},
|
||||
"infoNotification": {
|
||||
"message": "信息",
|
||||
"description": "通用信息通知"
|
||||
},
|
||||
"configCopiedNotification": {
|
||||
"message": "配置已复制到剪贴板",
|
||||
"description": "配置复制成功消息"
|
||||
},
|
||||
"dataClearedNotification": {
|
||||
"message": "数据清空成功",
|
||||
"description": "数据清空成功消息"
|
||||
},
|
||||
"bytesUnit": {
|
||||
"message": "字节",
|
||||
"description": "字节单位"
|
||||
},
|
||||
"kilobytesUnit": {
|
||||
"message": "KB",
|
||||
"description": "千字节单位"
|
||||
},
|
||||
"megabytesUnit": {
|
||||
"message": "MB",
|
||||
"description": "兆字节单位"
|
||||
},
|
||||
"gigabytesUnit": {
|
||||
"message": "GB",
|
||||
"description": "吉字节单位"
|
||||
},
|
||||
"itemsUnit": {
|
||||
"message": "项",
|
||||
"description": "项目计数单位"
|
||||
},
|
||||
"pagesUnit": {
|
||||
"message": "页",
|
||||
"description": "页面计数单位"
|
||||
}
|
||||
}
|
@@ -0,0 +1,446 @@
|
||||
{
|
||||
"extensionName": {
|
||||
"message": "chrome-mcp-server",
|
||||
"description": "扩展名称"
|
||||
},
|
||||
"extensionDescription": {
|
||||
"message": "使用你自己的 Chrome 浏览器暴露浏览器功能",
|
||||
"description": "扩展描述"
|
||||
},
|
||||
"nativeServerConfigLabel": {
|
||||
"message": "Native Server 配置",
|
||||
"description": "本地服务器设置的主要节标题"
|
||||
},
|
||||
"semanticEngineLabel": {
|
||||
"message": "语义引擎",
|
||||
"description": "语义引擎的主要节标题"
|
||||
},
|
||||
"embeddingModelLabel": {
|
||||
"message": "Embedding模型",
|
||||
"description": "模型选择的主要节标题"
|
||||
},
|
||||
"indexDataManagementLabel": {
|
||||
"message": "索引数据管理",
|
||||
"description": "数据管理的主要节标题"
|
||||
},
|
||||
"modelCacheManagementLabel": {
|
||||
"message": "模型缓存管理",
|
||||
"description": "缓存管理的主要节标题"
|
||||
},
|
||||
"statusLabel": {
|
||||
"message": "状态",
|
||||
"description": "通用状态标签"
|
||||
},
|
||||
"runningStatusLabel": {
|
||||
"message": "运行状态",
|
||||
"description": "服务器运行状态标签"
|
||||
},
|
||||
"connectionStatusLabel": {
|
||||
"message": "连接状态",
|
||||
"description": "连接状态标签"
|
||||
},
|
||||
"lastUpdatedLabel": {
|
||||
"message": "最后更新:",
|
||||
"description": "最后更新时间戳标签"
|
||||
},
|
||||
"connectButton": {
|
||||
"message": "连接",
|
||||
"description": "连接按钮文本"
|
||||
},
|
||||
"disconnectButton": {
|
||||
"message": "断开",
|
||||
"description": "断开连接按钮文本"
|
||||
},
|
||||
"connectingStatus": {
|
||||
"message": "连接中...",
|
||||
"description": "连接状态消息"
|
||||
},
|
||||
"connectedStatus": {
|
||||
"message": "已连接",
|
||||
"description": "已连接状态消息"
|
||||
},
|
||||
"disconnectedStatus": {
|
||||
"message": "已断开",
|
||||
"description": "已断开状态消息"
|
||||
},
|
||||
"detectingStatus": {
|
||||
"message": "检测中...",
|
||||
"description": "检测状态消息"
|
||||
},
|
||||
"serviceRunningStatus": {
|
||||
"message": "服务运行中 (端口: $PORT$)",
|
||||
"description": "带端口号的服务运行状态",
|
||||
"placeholders": {
|
||||
"port": {
|
||||
"content": "$1",
|
||||
"example": "12306"
|
||||
}
|
||||
}
|
||||
},
|
||||
"serviceNotConnectedStatus": {
|
||||
"message": "服务未连接",
|
||||
"description": "服务未连接状态"
|
||||
},
|
||||
"connectedServiceNotStartedStatus": {
|
||||
"message": "已连接,服务未启动",
|
||||
"description": "已连接但服务未启动状态"
|
||||
},
|
||||
"mcpServerConfigLabel": {
|
||||
"message": "MCP 服务器配置",
|
||||
"description": "MCP 服务器配置节标签"
|
||||
},
|
||||
"connectionPortLabel": {
|
||||
"message": "连接端口",
|
||||
"description": "连接端口输入标签"
|
||||
},
|
||||
"refreshStatusButton": {
|
||||
"message": "刷新状态",
|
||||
"description": "刷新状态按钮提示"
|
||||
},
|
||||
"copyConfigButton": {
|
||||
"message": "复制配置",
|
||||
"description": "复制配置按钮文本"
|
||||
},
|
||||
"retryButton": {
|
||||
"message": "重试",
|
||||
"description": "重试按钮文本"
|
||||
},
|
||||
"cancelButton": {
|
||||
"message": "取消",
|
||||
"description": "取消按钮文本"
|
||||
},
|
||||
"confirmButton": {
|
||||
"message": "确认",
|
||||
"description": "确认按钮文本"
|
||||
},
|
||||
"saveButton": {
|
||||
"message": "保存",
|
||||
"description": "保存按钮文本"
|
||||
},
|
||||
"closeButton": {
|
||||
"message": "关闭",
|
||||
"description": "关闭按钮文本"
|
||||
},
|
||||
"resetButton": {
|
||||
"message": "重置",
|
||||
"description": "重置按钮文本"
|
||||
},
|
||||
"initializingStatus": {
|
||||
"message": "初始化中...",
|
||||
"description": "初始化进度消息"
|
||||
},
|
||||
"processingStatus": {
|
||||
"message": "处理中...",
|
||||
"description": "处理进度消息"
|
||||
},
|
||||
"loadingStatus": {
|
||||
"message": "加载中...",
|
||||
"description": "加载进度消息"
|
||||
},
|
||||
"clearingStatus": {
|
||||
"message": "清空中...",
|
||||
"description": "清空进度消息"
|
||||
},
|
||||
"cleaningStatus": {
|
||||
"message": "清理中...",
|
||||
"description": "清理进度消息"
|
||||
},
|
||||
"downloadingStatus": {
|
||||
"message": "下载中...",
|
||||
"description": "下载进度消息"
|
||||
},
|
||||
"semanticEngineReadyStatus": {
|
||||
"message": "语义引擎已就绪",
|
||||
"description": "语义引擎就绪状态"
|
||||
},
|
||||
"semanticEngineInitializingStatus": {
|
||||
"message": "语义引擎初始化中...",
|
||||
"description": "语义引擎初始化状态"
|
||||
},
|
||||
"semanticEngineInitFailedStatus": {
|
||||
"message": "语义引擎初始化失败",
|
||||
"description": "语义引擎初始化失败状态"
|
||||
},
|
||||
"semanticEngineNotInitStatus": {
|
||||
"message": "语义引擎未初始化",
|
||||
"description": "语义引擎未初始化状态"
|
||||
},
|
||||
"initSemanticEngineButton": {
|
||||
"message": "初始化语义引擎",
|
||||
"description": "初始化语义引擎按钮文本"
|
||||
},
|
||||
"reinitializeButton": {
|
||||
"message": "重新初始化",
|
||||
"description": "重新初始化按钮文本"
|
||||
},
|
||||
"downloadingModelStatus": {
|
||||
"message": "下载模型中... $PROGRESS$%",
|
||||
"description": "带百分比的模型下载进度",
|
||||
"placeholders": {
|
||||
"progress": {
|
||||
"content": "$1",
|
||||
"example": "50"
|
||||
}
|
||||
}
|
||||
},
|
||||
"switchingModelStatus": {
|
||||
"message": "切换模型中...",
|
||||
"description": "模型切换进度消息"
|
||||
},
|
||||
"modelLoadedStatus": {
|
||||
"message": "模型已加载",
|
||||
"description": "模型成功加载状态"
|
||||
},
|
||||
"modelFailedStatus": {
|
||||
"message": "模型加载失败",
|
||||
"description": "模型加载失败状态"
|
||||
},
|
||||
"lightweightModelDescription": {
|
||||
"message": "轻量级多语言模型",
|
||||
"description": "轻量级模型选项的描述"
|
||||
},
|
||||
"betterThanSmallDescription": {
|
||||
"message": "比e5-small稍大,但效果更好",
|
||||
"description": "中等模型选项的描述"
|
||||
},
|
||||
"multilingualModelDescription": {
|
||||
"message": "多语言语义模型",
|
||||
"description": "多语言模型选项的描述"
|
||||
},
|
||||
"fastPerformance": {
|
||||
"message": "快速",
|
||||
"description": "快速性能指示器"
|
||||
},
|
||||
"balancedPerformance": {
|
||||
"message": "平衡",
|
||||
"description": "平衡性能指示器"
|
||||
},
|
||||
"accuratePerformance": {
|
||||
"message": "精确",
|
||||
"description": "精确性能指示器"
|
||||
},
|
||||
"networkErrorMessage": {
|
||||
"message": "网络连接错误,请检查网络连接后重试",
|
||||
"description": "网络连接错误消息"
|
||||
},
|
||||
"modelCorruptedErrorMessage": {
|
||||
"message": "模型文件损坏或不完整,请重试下载",
|
||||
"description": "模型损坏错误消息"
|
||||
},
|
||||
"unknownErrorMessage": {
|
||||
"message": "未知错误,请检查你的网络是否可以访问HuggingFace",
|
||||
"description": "未知错误回退消息"
|
||||
},
|
||||
"permissionDeniedErrorMessage": {
|
||||
"message": "权限被拒绝",
|
||||
"description": "权限被拒绝错误消息"
|
||||
},
|
||||
"timeoutErrorMessage": {
|
||||
"message": "操作超时",
|
||||
"description": "超时错误消息"
|
||||
},
|
||||
"indexedPagesLabel": {
|
||||
"message": "已索引页面",
|
||||
"description": "已索引页面数量标签"
|
||||
},
|
||||
"indexSizeLabel": {
|
||||
"message": "索引大小",
|
||||
"description": "索引大小标签"
|
||||
},
|
||||
"activeTabsLabel": {
|
||||
"message": "活跃标签页",
|
||||
"description": "活跃标签页数量标签"
|
||||
},
|
||||
"vectorDocumentsLabel": {
|
||||
"message": "向量文档",
|
||||
"description": "向量文档数量标签"
|
||||
},
|
||||
"cacheSizeLabel": {
|
||||
"message": "缓存大小",
|
||||
"description": "缓存大小标签"
|
||||
},
|
||||
"cacheEntriesLabel": {
|
||||
"message": "缓存条目",
|
||||
"description": "缓存条目数量标签"
|
||||
},
|
||||
"clearAllDataButton": {
|
||||
"message": "清空所有数据",
|
||||
"description": "清空所有数据按钮文本"
|
||||
},
|
||||
"clearAllCacheButton": {
|
||||
"message": "清空所有缓存",
|
||||
"description": "清空所有缓存按钮文本"
|
||||
},
|
||||
"cleanExpiredCacheButton": {
|
||||
"message": "清理过期缓存",
|
||||
"description": "清理过期缓存按钮文本"
|
||||
},
|
||||
"exportDataButton": {
|
||||
"message": "导出数据",
|
||||
"description": "导出数据按钮文本"
|
||||
},
|
||||
"importDataButton": {
|
||||
"message": "导入数据",
|
||||
"description": "导入数据按钮文本"
|
||||
},
|
||||
"confirmClearDataTitle": {
|
||||
"message": "确认清空数据",
|
||||
"description": "清空数据确认对话框标题"
|
||||
},
|
||||
"settingsTitle": {
|
||||
"message": "设置",
|
||||
"description": "设置对话框标题"
|
||||
},
|
||||
"aboutTitle": {
|
||||
"message": "关于",
|
||||
"description": "关于对话框标题"
|
||||
},
|
||||
"helpTitle": {
|
||||
"message": "帮助",
|
||||
"description": "帮助对话框标题"
|
||||
},
|
||||
"clearDataWarningMessage": {
|
||||
"message": "此操作将清空所有已索引的网页内容和向量数据,包括:",
|
||||
"description": "清空数据警告消息"
|
||||
},
|
||||
"clearDataList1": {
|
||||
"message": "所有网页的文本内容索引",
|
||||
"description": "清空数据列表第一项"
|
||||
},
|
||||
"clearDataList2": {
|
||||
"message": "向量嵌入数据",
|
||||
"description": "清空数据列表第二项"
|
||||
},
|
||||
"clearDataList3": {
|
||||
"message": "搜索历史和缓存",
|
||||
"description": "清空数据列表第三项"
|
||||
},
|
||||
"clearDataIrreversibleWarning": {
|
||||
"message": "此操作不可撤销!清空后需要重新浏览网页来重建索引。",
|
||||
"description": "不可逆操作警告"
|
||||
},
|
||||
"confirmClearButton": {
|
||||
"message": "确认清空",
|
||||
"description": "确认清空操作按钮"
|
||||
},
|
||||
"cacheDetailsLabel": {
|
||||
"message": "缓存详情",
|
||||
"description": "缓存详情节标签"
|
||||
},
|
||||
"noCacheDataMessage": {
|
||||
"message": "暂无缓存数据",
|
||||
"description": "无缓存数据可用消息"
|
||||
},
|
||||
"loadingCacheInfoStatus": {
|
||||
"message": "正在加载缓存信息...",
|
||||
"description": "加载缓存信息状态"
|
||||
},
|
||||
"processingCacheStatus": {
|
||||
"message": "处理缓存中...",
|
||||
"description": "处理缓存状态"
|
||||
},
|
||||
"expiredLabel": {
|
||||
"message": "已过期",
|
||||
"description": "过期项标签"
|
||||
},
|
||||
"bookmarksBarLabel": {
|
||||
"message": "书签栏",
|
||||
"description": "书签栏文件夹名称"
|
||||
},
|
||||
"newTabLabel": {
|
||||
"message": "新标签页",
|
||||
"description": "新标签页标签"
|
||||
},
|
||||
"currentPageLabel": {
|
||||
"message": "当前页面",
|
||||
"description": "当前页面标签"
|
||||
},
|
||||
"menuLabel": {
|
||||
"message": "菜单",
|
||||
"description": "菜单辅助功能标签"
|
||||
},
|
||||
"navigationLabel": {
|
||||
"message": "导航",
|
||||
"description": "导航辅助功能标签"
|
||||
},
|
||||
"mainContentLabel": {
|
||||
"message": "主要内容",
|
||||
"description": "主要内容辅助功能标签"
|
||||
},
|
||||
"languageSelectorLabel": {
|
||||
"message": "语言",
|
||||
"description": "语言选择器标签"
|
||||
},
|
||||
"themeLabel": {
|
||||
"message": "主题",
|
||||
"description": "主题选择器标签"
|
||||
},
|
||||
"lightTheme": {
|
||||
"message": "浅色",
|
||||
"description": "浅色主题选项"
|
||||
},
|
||||
"darkTheme": {
|
||||
"message": "深色",
|
||||
"description": "深色主题选项"
|
||||
},
|
||||
"autoTheme": {
|
||||
"message": "自动",
|
||||
"description": "自动主题选项"
|
||||
},
|
||||
"advancedSettingsLabel": {
|
||||
"message": "高级设置",
|
||||
"description": "高级设置节标签"
|
||||
},
|
||||
"debugModeLabel": {
|
||||
"message": "调试模式",
|
||||
"description": "调试模式切换标签"
|
||||
},
|
||||
"verboseLoggingLabel": {
|
||||
"message": "详细日志",
|
||||
"description": "详细日志切换标签"
|
||||
},
|
||||
"successNotification": {
|
||||
"message": "操作成功完成",
|
||||
"description": "通用成功通知"
|
||||
},
|
||||
"warningNotification": {
|
||||
"message": "警告:请在继续之前检查",
|
||||
"description": "通用警告通知"
|
||||
},
|
||||
"infoNotification": {
|
||||
"message": "信息",
|
||||
"description": "通用信息通知"
|
||||
},
|
||||
"configCopiedNotification": {
|
||||
"message": "配置已复制到剪贴板",
|
||||
"description": "配置复制成功消息"
|
||||
},
|
||||
"dataClearedNotification": {
|
||||
"message": "数据清空成功",
|
||||
"description": "数据清空成功消息"
|
||||
},
|
||||
"bytesUnit": {
|
||||
"message": "字节",
|
||||
"description": "字节单位"
|
||||
},
|
||||
"kilobytesUnit": {
|
||||
"message": "KB",
|
||||
"description": "千字节单位"
|
||||
},
|
||||
"megabytesUnit": {
|
||||
"message": "MB",
|
||||
"description": "兆字节单位"
|
||||
},
|
||||
"gigabytesUnit": {
|
||||
"message": "GB",
|
||||
"description": "吉字节单位"
|
||||
},
|
||||
"itemsUnit": {
|
||||
"message": "项",
|
||||
"description": "项目计数单位"
|
||||
},
|
||||
"pagesUnit": {
|
||||
"message": "页",
|
||||
"description": "页面计数单位"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
35155
releases/chrome-extension/latest/chrome-mcp-server-lastest/background.js
Normal file
35155
releases/chrome-extension/latest/chrome-mcp-server-lastest/background.js
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,295 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __async = (__this, __arguments, generator) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fulfilled = (value) => {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var rejected = (value) => {
|
||||
try {
|
||||
step(generator.throw(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||||
step((generator = generator.apply(__this, __arguments)).next());
|
||||
});
|
||||
};
|
||||
import { M as MessageTarget, O as OFFSCREEN_MESSAGE_TYPES, S as SendMessageType, a as SemanticSimilarityEngine, B as BACKGROUND_MESSAGE_TYPES } from "./semantic-similarity-engine-D0u7zDKx.js";
|
||||
let similarityEngine = null;
|
||||
chrome.runtime.onMessage.addListener(
|
||||
(message, _sender, sendResponse) => {
|
||||
if (message.target !== MessageTarget.Offscreen) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
switch (message.type) {
|
||||
case SendMessageType.SimilarityEngineInit:
|
||||
case OFFSCREEN_MESSAGE_TYPES.SIMILARITY_ENGINE_INIT: {
|
||||
const initMsg = message;
|
||||
console.log("Offscreen: Received similarity engine init message:", message.type);
|
||||
handleSimilarityEngineInit(initMsg.config).then(() => sendResponse({ success: true })).catch((error) => sendResponse({ success: false, error: error.message }));
|
||||
break;
|
||||
}
|
||||
case SendMessageType.SimilarityEngineComputeBatch: {
|
||||
const computeMsg = message;
|
||||
handleComputeSimilarityBatch(computeMsg.pairs, computeMsg.options).then((similarities) => sendResponse({ success: true, similarities })).catch((error) => sendResponse({ success: false, error: error.message }));
|
||||
break;
|
||||
}
|
||||
case OFFSCREEN_MESSAGE_TYPES.SIMILARITY_ENGINE_COMPUTE: {
|
||||
const embeddingMsg = message;
|
||||
handleGetEmbedding(embeddingMsg.text, embeddingMsg.options).then((embedding) => {
|
||||
console.log("Offscreen: Sending embedding response:", {
|
||||
length: embedding.length,
|
||||
type: typeof embedding,
|
||||
constructor: embedding.constructor.name,
|
||||
isFloat32Array: embedding instanceof Float32Array,
|
||||
firstFewValues: Array.from(embedding.slice(0, 5))
|
||||
});
|
||||
const embeddingArray = Array.from(embedding);
|
||||
console.log("Offscreen: Converted to array:", {
|
||||
length: embeddingArray.length,
|
||||
type: typeof embeddingArray,
|
||||
isArray: Array.isArray(embeddingArray),
|
||||
firstFewValues: embeddingArray.slice(0, 5)
|
||||
});
|
||||
sendResponse({ success: true, embedding: embeddingArray });
|
||||
}).catch((error) => sendResponse({ success: false, error: error.message }));
|
||||
break;
|
||||
}
|
||||
case OFFSCREEN_MESSAGE_TYPES.SIMILARITY_ENGINE_BATCH_COMPUTE: {
|
||||
const batchMsg = message;
|
||||
handleGetEmbeddingsBatch(batchMsg.texts, batchMsg.options).then(
|
||||
(embeddings) => sendResponse({
|
||||
success: true,
|
||||
embeddings: embeddings.map((emb) => Array.from(emb))
|
||||
})
|
||||
).catch((error) => sendResponse({ success: false, error: error.message }));
|
||||
break;
|
||||
}
|
||||
case OFFSCREEN_MESSAGE_TYPES.SIMILARITY_ENGINE_STATUS: {
|
||||
handleGetEngineStatus().then((status) => sendResponse(__spreadValues({ success: true }, status))).catch((error) => sendResponse({ success: false, error: error.message }));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sendResponse({ error: `Unknown message type: ${message.type}` });
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
sendResponse({ error: error.message });
|
||||
} else {
|
||||
sendResponse({ error: "Unknown error occurred" });
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
);
|
||||
let currentModelConfig = null;
|
||||
function needsReinitialization(newConfig) {
|
||||
if (!similarityEngine || !currentModelConfig) {
|
||||
return true;
|
||||
}
|
||||
const keyFields = ["modelPreset", "modelVersion", "modelIdentifier", "dimension"];
|
||||
for (const field of keyFields) {
|
||||
if (newConfig[field] !== currentModelConfig[field]) {
|
||||
console.log(
|
||||
`Offscreen: ${field} changed from ${currentModelConfig[field]} to ${newConfig[field]}`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function handleSimilarityEngineInit(config) {
|
||||
return __async(this, null, function* () {
|
||||
console.log("Offscreen: Initializing semantic similarity engine with config:", config);
|
||||
console.log("Offscreen: Config useLocalFiles:", config.useLocalFiles);
|
||||
console.log("Offscreen: Config modelPreset:", config.modelPreset);
|
||||
console.log("Offscreen: Config modelVersion:", config.modelVersion);
|
||||
console.log("Offscreen: Config modelDimension:", config.modelDimension);
|
||||
console.log("Offscreen: Config modelIdentifier:", config.modelIdentifier);
|
||||
const needsReinit = needsReinitialization(config);
|
||||
console.log("Offscreen: Needs reinitialization:", needsReinit);
|
||||
if (!needsReinit) {
|
||||
console.log("Offscreen: Using existing engine (no changes detected)");
|
||||
yield updateModelStatus("ready", 100);
|
||||
return;
|
||||
}
|
||||
if (similarityEngine) {
|
||||
console.log("Offscreen: Cleaning up existing engine for model switch...");
|
||||
try {
|
||||
yield similarityEngine.dispose();
|
||||
console.log("Offscreen: Previous engine disposed successfully");
|
||||
} catch (error) {
|
||||
console.warn("Offscreen: Failed to dispose previous engine:", error);
|
||||
}
|
||||
similarityEngine = null;
|
||||
currentModelConfig = null;
|
||||
try {
|
||||
console.log("Offscreen: Clearing IndexedDB vector data for model switch...");
|
||||
yield clearVectorIndexedDB();
|
||||
console.log("Offscreen: IndexedDB vector data cleared successfully");
|
||||
} catch (error) {
|
||||
console.warn("Offscreen: Failed to clear IndexedDB vector data:", error);
|
||||
}
|
||||
}
|
||||
try {
|
||||
yield updateModelStatus("initializing", 10);
|
||||
const progressCallback = (progress) => __async(null, null, function* () {
|
||||
console.log("Offscreen: Progress update:", progress);
|
||||
yield updateModelStatus(progress.status, progress.progress);
|
||||
});
|
||||
similarityEngine = new SemanticSimilarityEngine(config);
|
||||
console.log("Offscreen: Starting engine initialization with progress tracking...");
|
||||
if (typeof similarityEngine.initializeWithProgress === "function") {
|
||||
yield similarityEngine.initializeWithProgress(progressCallback);
|
||||
} else {
|
||||
console.log("Offscreen: Using standard initialization (no progress callback support)");
|
||||
yield updateModelStatus("downloading", 30);
|
||||
yield similarityEngine.initialize();
|
||||
yield updateModelStatus("ready", 100);
|
||||
}
|
||||
currentModelConfig = __spreadValues({}, config);
|
||||
console.log("Offscreen: Semantic similarity engine initialized successfully");
|
||||
} catch (error) {
|
||||
console.error("Offscreen: Failed to initialize semantic similarity engine:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : "Unknown initialization error";
|
||||
const errorType = analyzeErrorType(errorMessage);
|
||||
yield updateModelStatus("error", 0, errorMessage, errorType);
|
||||
similarityEngine = null;
|
||||
currentModelConfig = null;
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
function clearVectorIndexedDB() {
|
||||
return __async(this, null, function* () {
|
||||
try {
|
||||
const dbNames = ["VectorSearchDB", "ContentIndexerDB", "SemanticSimilarityDB"];
|
||||
for (const dbName of dbNames) {
|
||||
try {
|
||||
const deleteRequest = indexedDB.deleteDatabase(dbName);
|
||||
yield new Promise((resolve, _reject) => {
|
||||
deleteRequest.onsuccess = () => {
|
||||
console.log(`Offscreen: Successfully deleted database: ${dbName}`);
|
||||
resolve();
|
||||
};
|
||||
deleteRequest.onerror = () => {
|
||||
console.warn(`Offscreen: Failed to delete database: ${dbName}`, deleteRequest.error);
|
||||
resolve();
|
||||
};
|
||||
deleteRequest.onblocked = () => {
|
||||
console.warn(`Offscreen: Database deletion blocked: ${dbName}`);
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn(`Offscreen: Error deleting database ${dbName}:`, error);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Offscreen: Failed to clear vector IndexedDB:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
}
|
||||
function analyzeErrorType(errorMessage) {
|
||||
const message = errorMessage.toLowerCase();
|
||||
if (message.includes("network") || message.includes("fetch") || message.includes("timeout") || message.includes("connection") || message.includes("cors") || message.includes("failed to fetch")) {
|
||||
return "network";
|
||||
}
|
||||
if (message.includes("corrupt") || message.includes("invalid") || message.includes("format") || message.includes("parse") || message.includes("decode") || message.includes("onnx")) {
|
||||
return "file";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function updateModelStatus(status, progress, errorMessage, errorType) {
|
||||
return __async(this, null, function* () {
|
||||
try {
|
||||
const modelState = {
|
||||
status,
|
||||
downloadProgress: progress,
|
||||
isDownloading: status === "downloading" || status === "initializing",
|
||||
lastUpdated: Date.now(),
|
||||
errorMessage: errorMessage || "",
|
||||
errorType: errorType || ""
|
||||
};
|
||||
if (typeof chrome !== "undefined" && chrome.storage && chrome.storage.local) {
|
||||
yield chrome.storage.local.set({ modelState });
|
||||
} else {
|
||||
console.log("Offscreen: chrome.storage not available, sending message to background");
|
||||
try {
|
||||
yield chrome.runtime.sendMessage({
|
||||
type: BACKGROUND_MESSAGE_TYPES.UPDATE_MODEL_STATUS,
|
||||
modelState
|
||||
});
|
||||
} catch (messageError) {
|
||||
console.error("Offscreen: Failed to send status update message:", messageError);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Offscreen: Failed to update model status:", error);
|
||||
}
|
||||
});
|
||||
}
|
||||
function handleComputeSimilarityBatch(_0) {
|
||||
return __async(this, arguments, function* (pairs, options = {}) {
|
||||
if (!similarityEngine) {
|
||||
throw new Error("Similarity engine not initialized. Please reinitialize the engine.");
|
||||
}
|
||||
console.log(`Offscreen: Computing similarities for ${pairs.length} pairs`);
|
||||
const similarities = yield similarityEngine.computeSimilarityBatch(pairs, options);
|
||||
console.log("Offscreen: Similarity computation completed");
|
||||
return similarities;
|
||||
});
|
||||
}
|
||||
function handleGetEmbedding(_0) {
|
||||
return __async(this, arguments, function* (text, options = {}) {
|
||||
if (!similarityEngine) {
|
||||
throw new Error("Similarity engine not initialized. Please reinitialize the engine.");
|
||||
}
|
||||
console.log(`Offscreen: Getting embedding for text: "${text.substring(0, 50)}..."`);
|
||||
const embedding = yield similarityEngine.getEmbedding(text, options);
|
||||
console.log("Offscreen: Embedding computation completed");
|
||||
return embedding;
|
||||
});
|
||||
}
|
||||
function handleGetEmbeddingsBatch(_0) {
|
||||
return __async(this, arguments, function* (texts, options = {}) {
|
||||
if (!similarityEngine) {
|
||||
throw new Error("Similarity engine not initialized. Please reinitialize the engine.");
|
||||
}
|
||||
console.log(`Offscreen: Getting embeddings for ${texts.length} texts`);
|
||||
const embeddings = yield similarityEngine.getEmbeddingsBatch(texts, options);
|
||||
console.log("Offscreen: Batch embedding computation completed");
|
||||
return embeddings;
|
||||
});
|
||||
}
|
||||
function handleGetEngineStatus() {
|
||||
return __async(this, null, function* () {
|
||||
return {
|
||||
isInitialized: !!similarityEngine,
|
||||
currentConfig: currentModelConfig
|
||||
};
|
||||
});
|
||||
}
|
||||
console.log("Offscreen: Semantic similarity engine handler loaded");
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,302 @@
|
||||
var content = function() {
|
||||
"use strict";var __defProp = Object.defineProperty;
|
||||
var __defProps = Object.defineProperties;
|
||||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
||||
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
||||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
||||
var __spreadValues = (a, b) => {
|
||||
for (var prop in b || (b = {}))
|
||||
if (__hasOwnProp.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
if (__getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(b)) {
|
||||
if (__propIsEnum.call(b, prop))
|
||||
__defNormalProp(a, prop, b[prop]);
|
||||
}
|
||||
return a;
|
||||
};
|
||||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
||||
var __objRest = (source, exclude) => {
|
||||
var target = {};
|
||||
for (var prop in source)
|
||||
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
||||
target[prop] = source[prop];
|
||||
if (source != null && __getOwnPropSymbols)
|
||||
for (var prop of __getOwnPropSymbols(source)) {
|
||||
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
||||
target[prop] = source[prop];
|
||||
}
|
||||
return target;
|
||||
};
|
||||
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
||||
var __async = (__this, __arguments, generator) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fulfilled = (value) => {
|
||||
try {
|
||||
step(generator.next(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var rejected = (value) => {
|
||||
try {
|
||||
step(generator.throw(value));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
};
|
||||
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||||
step((generator = generator.apply(__this, __arguments)).next());
|
||||
});
|
||||
};
|
||||
|
||||
var _a, _b;
|
||||
function defineContentScript(definition2) {
|
||||
return definition2;
|
||||
}
|
||||
const definition = defineContentScript({
|
||||
matches: ["*://*.google.com/*"],
|
||||
main() {
|
||||
}
|
||||
});
|
||||
content;
|
||||
const browser$1 = ((_b = (_a = globalThis.browser) == null ? void 0 : _a.runtime) == null ? void 0 : _b.id) ? globalThis.browser : globalThis.chrome;
|
||||
const browser = browser$1;
|
||||
function print$1(method, ...args) {
|
||||
return;
|
||||
}
|
||||
const logger$1 = {
|
||||
debug: (...args) => print$1(console.debug, ...args),
|
||||
log: (...args) => print$1(console.log, ...args),
|
||||
warn: (...args) => print$1(console.warn, ...args),
|
||||
error: (...args) => print$1(console.error, ...args)
|
||||
};
|
||||
const _WxtLocationChangeEvent = class _WxtLocationChangeEvent extends Event {
|
||||
constructor(newUrl, oldUrl) {
|
||||
super(_WxtLocationChangeEvent.EVENT_NAME, {});
|
||||
this.newUrl = newUrl;
|
||||
this.oldUrl = oldUrl;
|
||||
}
|
||||
};
|
||||
__publicField(_WxtLocationChangeEvent, "EVENT_NAME", getUniqueEventName("wxt:locationchange"));
|
||||
let WxtLocationChangeEvent = _WxtLocationChangeEvent;
|
||||
function getUniqueEventName(eventName) {
|
||||
var _a2;
|
||||
return `${(_a2 = browser == null ? void 0 : browser.runtime) == null ? void 0 : _a2.id}:${"content"}:${eventName}`;
|
||||
}
|
||||
function createLocationWatcher(ctx) {
|
||||
let interval;
|
||||
let oldUrl;
|
||||
return {
|
||||
/**
|
||||
* Ensure the location watcher is actively looking for URL changes. If it's already watching,
|
||||
* this is a noop.
|
||||
*/
|
||||
run() {
|
||||
if (interval != null) return;
|
||||
oldUrl = new URL(location.href);
|
||||
interval = ctx.setInterval(() => {
|
||||
let newUrl = new URL(location.href);
|
||||
if (newUrl.href !== oldUrl.href) {
|
||||
window.dispatchEvent(new WxtLocationChangeEvent(newUrl, oldUrl));
|
||||
oldUrl = newUrl;
|
||||
}
|
||||
}, 1e3);
|
||||
}
|
||||
};
|
||||
}
|
||||
const _ContentScriptContext = class _ContentScriptContext {
|
||||
constructor(contentScriptName, options) {
|
||||
__publicField(this, "isTopFrame", window.self === window.top);
|
||||
__publicField(this, "abortController");
|
||||
__publicField(this, "locationWatcher", createLocationWatcher(this));
|
||||
__publicField(this, "receivedMessageIds", /* @__PURE__ */ new Set());
|
||||
this.contentScriptName = contentScriptName;
|
||||
this.options = options;
|
||||
this.abortController = new AbortController();
|
||||
if (this.isTopFrame) {
|
||||
this.listenForNewerScripts({ ignoreFirstEvent: true });
|
||||
this.stopOldScripts();
|
||||
} else {
|
||||
this.listenForNewerScripts();
|
||||
}
|
||||
}
|
||||
get signal() {
|
||||
return this.abortController.signal;
|
||||
}
|
||||
abort(reason) {
|
||||
return this.abortController.abort(reason);
|
||||
}
|
||||
get isInvalid() {
|
||||
if (browser.runtime.id == null) {
|
||||
this.notifyInvalidated();
|
||||
}
|
||||
return this.signal.aborted;
|
||||
}
|
||||
get isValid() {
|
||||
return !this.isInvalid;
|
||||
}
|
||||
/**
|
||||
* Add a listener that is called when the content script's context is invalidated.
|
||||
*
|
||||
* @returns A function to remove the listener.
|
||||
*
|
||||
* @example
|
||||
* browser.runtime.onMessage.addListener(cb);
|
||||
* const removeInvalidatedListener = ctx.onInvalidated(() => {
|
||||
* browser.runtime.onMessage.removeListener(cb);
|
||||
* })
|
||||
* // ...
|
||||
* removeInvalidatedListener();
|
||||
*/
|
||||
onInvalidated(cb) {
|
||||
this.signal.addEventListener("abort", cb);
|
||||
return () => this.signal.removeEventListener("abort", cb);
|
||||
}
|
||||
/**
|
||||
* Return a promise that never resolves. Useful if you have an async function that shouldn't run
|
||||
* after the context is expired.
|
||||
*
|
||||
* @example
|
||||
* const getValueFromStorage = async () => {
|
||||
* if (ctx.isInvalid) return ctx.block();
|
||||
*
|
||||
* // ...
|
||||
* }
|
||||
*/
|
||||
block() {
|
||||
return new Promise(() => {
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Wrapper around `window.setInterval` that automatically clears the interval when invalidated.
|
||||
*/
|
||||
setInterval(handler, timeout) {
|
||||
const id = setInterval(() => {
|
||||
if (this.isValid) handler();
|
||||
}, timeout);
|
||||
this.onInvalidated(() => clearInterval(id));
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Wrapper around `window.setTimeout` that automatically clears the interval when invalidated.
|
||||
*/
|
||||
setTimeout(handler, timeout) {
|
||||
const id = setTimeout(() => {
|
||||
if (this.isValid) handler();
|
||||
}, timeout);
|
||||
this.onInvalidated(() => clearTimeout(id));
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Wrapper around `window.requestAnimationFrame` that automatically cancels the request when
|
||||
* invalidated.
|
||||
*/
|
||||
requestAnimationFrame(callback) {
|
||||
const id = requestAnimationFrame((...args) => {
|
||||
if (this.isValid) callback(...args);
|
||||
});
|
||||
this.onInvalidated(() => cancelAnimationFrame(id));
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Wrapper around `window.requestIdleCallback` that automatically cancels the request when
|
||||
* invalidated.
|
||||
*/
|
||||
requestIdleCallback(callback, options) {
|
||||
const id = requestIdleCallback((...args) => {
|
||||
if (!this.signal.aborted) callback(...args);
|
||||
}, options);
|
||||
this.onInvalidated(() => cancelIdleCallback(id));
|
||||
return id;
|
||||
}
|
||||
addEventListener(target, type, handler, options) {
|
||||
var _a2;
|
||||
if (type === "wxt:locationchange") {
|
||||
if (this.isValid) this.locationWatcher.run();
|
||||
}
|
||||
(_a2 = target.addEventListener) == null ? void 0 : _a2.call(
|
||||
target,
|
||||
type.startsWith("wxt:") ? getUniqueEventName(type) : type,
|
||||
handler,
|
||||
__spreadProps(__spreadValues({}, options), {
|
||||
signal: this.signal
|
||||
})
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* Abort the abort controller and execute all `onInvalidated` listeners.
|
||||
*/
|
||||
notifyInvalidated() {
|
||||
this.abort("Content script context invalidated");
|
||||
logger$1.debug(
|
||||
`Content script "${this.contentScriptName}" context invalidated`
|
||||
);
|
||||
}
|
||||
stopOldScripts() {
|
||||
window.postMessage(
|
||||
{
|
||||
type: _ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE,
|
||||
contentScriptName: this.contentScriptName,
|
||||
messageId: Math.random().toString(36).slice(2)
|
||||
},
|
||||
"*"
|
||||
);
|
||||
}
|
||||
verifyScriptStartedEvent(event) {
|
||||
var _a2, _b2, _c;
|
||||
const isScriptStartedEvent = ((_a2 = event.data) == null ? void 0 : _a2.type) === _ContentScriptContext.SCRIPT_STARTED_MESSAGE_TYPE;
|
||||
const isSameContentScript = ((_b2 = event.data) == null ? void 0 : _b2.contentScriptName) === this.contentScriptName;
|
||||
const isNotDuplicate = !this.receivedMessageIds.has((_c = event.data) == null ? void 0 : _c.messageId);
|
||||
return isScriptStartedEvent && isSameContentScript && isNotDuplicate;
|
||||
}
|
||||
listenForNewerScripts(options) {
|
||||
let isFirst = true;
|
||||
const cb = (event) => {
|
||||
if (this.verifyScriptStartedEvent(event)) {
|
||||
this.receivedMessageIds.add(event.data.messageId);
|
||||
const wasFirst = isFirst;
|
||||
isFirst = false;
|
||||
if (wasFirst && (options == null ? void 0 : options.ignoreFirstEvent)) return;
|
||||
this.notifyInvalidated();
|
||||
}
|
||||
};
|
||||
addEventListener("message", cb);
|
||||
this.onInvalidated(() => removeEventListener("message", cb));
|
||||
}
|
||||
};
|
||||
__publicField(_ContentScriptContext, "SCRIPT_STARTED_MESSAGE_TYPE", getUniqueEventName(
|
||||
"wxt:content-script-started"
|
||||
));
|
||||
let ContentScriptContext = _ContentScriptContext;
|
||||
function initPlugins() {
|
||||
}
|
||||
function print(method, ...args) {
|
||||
return;
|
||||
}
|
||||
const logger = {
|
||||
debug: (...args) => print(console.debug, ...args),
|
||||
log: (...args) => print(console.log, ...args),
|
||||
warn: (...args) => print(console.warn, ...args),
|
||||
error: (...args) => print(console.error, ...args)
|
||||
};
|
||||
const result = (() => __async(null, null, function* () {
|
||||
try {
|
||||
initPlugins();
|
||||
const _a2 = definition, { main } = _a2, options = __objRest(_a2, ["main"]);
|
||||
const ctx = new ContentScriptContext("content", options);
|
||||
return yield main(ctx);
|
||||
} catch (err) {
|
||||
logger.error(
|
||||
`The content script "${"content"}" crashed on startup!`,
|
||||
err
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
}))();
|
||||
return result;
|
||||
}();
|
||||
content;
|
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
@@ -0,0 +1,236 @@
|
||||
/* eslint-disable */
|
||||
// click-helper.js
|
||||
// This script is injected into the page to handle click operations
|
||||
|
||||
if (window.__CLICK_HELPER_INITIALIZED__) {
|
||||
// Already initialized, skip
|
||||
} else {
|
||||
window.__CLICK_HELPER_INITIALIZED__ = true;
|
||||
/**
|
||||
* Click on an element matching the selector or at specific coordinates
|
||||
* @param {string} selector - CSS selector for the element to click
|
||||
* @param {boolean} waitForNavigation - Whether to wait for navigation to complete after click
|
||||
* @param {number} timeout - Timeout in milliseconds for waiting for the element or navigation
|
||||
* @param {Object} coordinates - Optional coordinates for clicking at a specific position
|
||||
* @param {number} coordinates.x - X coordinate relative to the viewport
|
||||
* @param {number} coordinates.y - Y coordinate relative to the viewport
|
||||
* @returns {Promise<Object>} - Result of the click operation
|
||||
*/
|
||||
async function clickElement(
|
||||
selector,
|
||||
waitForNavigation = false,
|
||||
timeout = 5000,
|
||||
coordinates = null,
|
||||
) {
|
||||
try {
|
||||
let element = null;
|
||||
let elementInfo = null;
|
||||
let clickX, clickY;
|
||||
|
||||
if (coordinates && typeof coordinates.x === 'number' && typeof coordinates.y === 'number') {
|
||||
clickX = coordinates.x;
|
||||
clickY = coordinates.y;
|
||||
|
||||
element = document.elementFromPoint(clickX, clickY);
|
||||
|
||||
if (element) {
|
||||
const rect = element.getBoundingClientRect();
|
||||
elementInfo = {
|
||||
tagName: element.tagName,
|
||||
id: element.id,
|
||||
className: element.className,
|
||||
text: element.textContent?.trim().substring(0, 100) || '',
|
||||
href: element.href || null,
|
||||
type: element.type || null,
|
||||
isVisible: true,
|
||||
rect: {
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
top: rect.top,
|
||||
right: rect.right,
|
||||
bottom: rect.bottom,
|
||||
left: rect.left,
|
||||
},
|
||||
clickMethod: 'coordinates',
|
||||
clickPosition: { x: clickX, y: clickY },
|
||||
};
|
||||
} else {
|
||||
elementInfo = {
|
||||
clickMethod: 'coordinates',
|
||||
clickPosition: { x: clickX, y: clickY },
|
||||
warning: 'No element found at the specified coordinates',
|
||||
};
|
||||
}
|
||||
} else {
|
||||
element = document.querySelector(selector);
|
||||
if (!element) {
|
||||
return {
|
||||
error: `Element with selector "${selector}" not found`,
|
||||
};
|
||||
}
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
elementInfo = {
|
||||
tagName: element.tagName,
|
||||
id: element.id,
|
||||
className: element.className,
|
||||
text: element.textContent?.trim().substring(0, 100) || '',
|
||||
href: element.href || null,
|
||||
type: element.type || null,
|
||||
isVisible: isElementVisible(element),
|
||||
rect: {
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
top: rect.top,
|
||||
right: rect.right,
|
||||
bottom: rect.bottom,
|
||||
left: rect.left,
|
||||
},
|
||||
clickMethod: 'selector',
|
||||
};
|
||||
|
||||
if (!elementInfo.isVisible) {
|
||||
return {
|
||||
error: `Element with selector "${selector}" is not visible`,
|
||||
elementInfo,
|
||||
};
|
||||
}
|
||||
|
||||
clickX = rect.left + rect.width / 2;
|
||||
clickY = rect.top + rect.height / 2;
|
||||
|
||||
element.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'center' });
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
const updatedRect = element.getBoundingClientRect();
|
||||
clickX = updatedRect.left + updatedRect.width / 2;
|
||||
clickY = updatedRect.top + updatedRect.height / 2;
|
||||
}
|
||||
|
||||
let navigationPromise;
|
||||
if (waitForNavigation) {
|
||||
navigationPromise = new Promise((resolve) => {
|
||||
const beforeUnloadListener = () => {
|
||||
window.removeEventListener('beforeunload', beforeUnloadListener);
|
||||
resolve(true);
|
||||
};
|
||||
window.addEventListener('beforeunload', beforeUnloadListener);
|
||||
|
||||
setTimeout(() => {
|
||||
window.removeEventListener('beforeunload', beforeUnloadListener);
|
||||
resolve(false);
|
||||
}, timeout);
|
||||
});
|
||||
}
|
||||
|
||||
if (element && elementInfo.clickMethod === 'selector') {
|
||||
element.click();
|
||||
} else {
|
||||
simulateClick(clickX, clickY);
|
||||
}
|
||||
|
||||
// Wait for navigation if needed
|
||||
let navigationOccurred = false;
|
||||
if (waitForNavigation) {
|
||||
navigationOccurred = await navigationPromise;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Element clicked successfully',
|
||||
elementInfo,
|
||||
navigationOccurred,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
error: `Error clicking element: ${error.message}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a mouse click at specific coordinates
|
||||
* @param {number} x - X coordinate relative to the viewport
|
||||
* @param {number} y - Y coordinate relative to the viewport
|
||||
*/
|
||||
function simulateClick(x, y) {
|
||||
const clickEvent = new MouseEvent('click', {
|
||||
view: window,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
});
|
||||
|
||||
const element = document.elementFromPoint(x, y);
|
||||
|
||||
if (element) {
|
||||
element.dispatchEvent(clickEvent);
|
||||
} else {
|
||||
document.dispatchEvent(clickEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an element is visible
|
||||
* @param {Element} element - The element to check
|
||||
* @returns {boolean} - Whether the element is visible
|
||||
*/
|
||||
function isElementVisible(element) {
|
||||
if (!element) return false;
|
||||
|
||||
const style = window.getComputedStyle(element);
|
||||
if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
if (rect.width === 0 || rect.height === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
rect.bottom < 0 ||
|
||||
rect.top > window.innerHeight ||
|
||||
rect.right < 0 ||
|
||||
rect.left > window.innerWidth
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const centerX = rect.left + rect.width / 2;
|
||||
const centerY = rect.top + rect.height / 2;
|
||||
|
||||
const elementAtPoint = document.elementFromPoint(centerX, centerY);
|
||||
if (!elementAtPoint) return false;
|
||||
|
||||
return element === elementAtPoint || element.contains(elementAtPoint);
|
||||
}
|
||||
|
||||
// Listen for messages from the extension
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
if (request.action === 'clickElement') {
|
||||
clickElement(
|
||||
request.selector,
|
||||
request.waitForNavigation,
|
||||
request.timeout,
|
||||
request.coordinates,
|
||||
)
|
||||
.then(sendResponse)
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
error: `Unexpected error: ${error.message}`,
|
||||
});
|
||||
});
|
||||
return true; // Indicates async response
|
||||
} else if (request.action === 'chrome_click_element_ping') {
|
||||
sendResponse({ status: 'pong' });
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
@@ -0,0 +1,205 @@
|
||||
/* eslint-disable */
|
||||
// fill-helper.js
|
||||
// This script is injected into the page to handle form filling operations
|
||||
|
||||
if (window.__FILL_HELPER_INITIALIZED__) {
|
||||
// Already initialized, skip
|
||||
} else {
|
||||
window.__FILL_HELPER_INITIALIZED__ = true;
|
||||
/**
|
||||
* Fill an input element with the specified value
|
||||
* @param {string} selector - CSS selector for the element to fill
|
||||
* @param {string} value - Value to fill into the element
|
||||
* @returns {Promise<Object>} - Result of the fill operation
|
||||
*/
|
||||
async function fillElement(selector, value) {
|
||||
try {
|
||||
// Find the element
|
||||
const element = document.querySelector(selector);
|
||||
if (!element) {
|
||||
return {
|
||||
error: `Element with selector "${selector}" not found`,
|
||||
};
|
||||
}
|
||||
|
||||
// Get element information
|
||||
const rect = element.getBoundingClientRect();
|
||||
const elementInfo = {
|
||||
tagName: element.tagName,
|
||||
id: element.id,
|
||||
className: element.className,
|
||||
type: element.type || null,
|
||||
isVisible: isElementVisible(element),
|
||||
rect: {
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
top: rect.top,
|
||||
right: rect.right,
|
||||
bottom: rect.bottom,
|
||||
left: rect.left,
|
||||
},
|
||||
};
|
||||
|
||||
// Check if element is visible
|
||||
if (!elementInfo.isVisible) {
|
||||
return {
|
||||
error: `Element with selector "${selector}" is not visible`,
|
||||
elementInfo,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if element is an input, textarea, or select
|
||||
const validTags = ['INPUT', 'TEXTAREA', 'SELECT'];
|
||||
const validInputTypes = [
|
||||
'text',
|
||||
'email',
|
||||
'password',
|
||||
'number',
|
||||
'search',
|
||||
'tel',
|
||||
'url',
|
||||
'date',
|
||||
'datetime-local',
|
||||
'month',
|
||||
'time',
|
||||
'week',
|
||||
'color',
|
||||
];
|
||||
|
||||
if (!validTags.includes(element.tagName)) {
|
||||
return {
|
||||
error: `Element with selector "${selector}" is not a fillable element (must be INPUT, TEXTAREA, or SELECT)`,
|
||||
elementInfo,
|
||||
};
|
||||
}
|
||||
|
||||
// For input elements, check if the type is valid
|
||||
if (
|
||||
element.tagName === 'INPUT' &&
|
||||
!validInputTypes.includes(element.type) &&
|
||||
element.type !== null
|
||||
) {
|
||||
return {
|
||||
error: `Input element with selector "${selector}" has type "${element.type}" which is not fillable`,
|
||||
elementInfo,
|
||||
};
|
||||
}
|
||||
|
||||
// Scroll element into view
|
||||
element.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'center' });
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
// Focus the element
|
||||
element.focus();
|
||||
|
||||
// Fill the element based on its type
|
||||
if (element.tagName === 'SELECT') {
|
||||
// For select elements, find the option with matching value or text
|
||||
let optionFound = false;
|
||||
for (const option of element.options) {
|
||||
if (option.value === value || option.text === value) {
|
||||
element.value = option.value;
|
||||
optionFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!optionFound) {
|
||||
return {
|
||||
error: `No option with value or text "${value}" found in select element`,
|
||||
elementInfo,
|
||||
};
|
||||
}
|
||||
|
||||
// Trigger change event
|
||||
element.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
} else {
|
||||
// For input and textarea elements
|
||||
|
||||
// Clear the current value
|
||||
element.value = '';
|
||||
element.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
|
||||
// Set the new value
|
||||
element.value = value;
|
||||
|
||||
// Trigger input and change events
|
||||
element.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
element.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
|
||||
// Blur the element
|
||||
element.blur();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Element filled successfully',
|
||||
elementInfo: {
|
||||
...elementInfo,
|
||||
value: element.value, // Include the final value in the response
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
error: `Error filling element: ${error.message}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an element is visible
|
||||
* @param {Element} element - The element to check
|
||||
* @returns {boolean} - Whether the element is visible
|
||||
*/
|
||||
function isElementVisible(element) {
|
||||
if (!element) return false;
|
||||
|
||||
const style = window.getComputedStyle(element);
|
||||
if (style.display === 'none' || style.visibility === 'hidden' || style.opacity === '0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
if (rect.width === 0 || rect.height === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if element is within viewport
|
||||
if (
|
||||
rect.bottom < 0 ||
|
||||
rect.top > window.innerHeight ||
|
||||
rect.right < 0 ||
|
||||
rect.left > window.innerWidth
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if element is actually visible at its center point
|
||||
const centerX = rect.left + rect.width / 2;
|
||||
const centerY = rect.top + rect.height / 2;
|
||||
|
||||
const elementAtPoint = document.elementFromPoint(centerX, centerY);
|
||||
if (!elementAtPoint) return false;
|
||||
|
||||
return element === elementAtPoint || element.contains(elementAtPoint);
|
||||
}
|
||||
|
||||
// Listen for messages from the extension
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
if (request.action === 'fillElement') {
|
||||
fillElement(request.selector, request.value)
|
||||
.then(sendResponse)
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
error: `Unexpected error: ${error.message}`,
|
||||
});
|
||||
});
|
||||
return true; // Indicates async response
|
||||
} else if (request.action === 'chrome_fill_or_select_ping') {
|
||||
sendResponse({ status: 'pong' });
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/* eslint-disable */
|
||||
|
||||
(() => {
|
||||
// Prevent duplicate injection of the bridge itself.
|
||||
if (window.__INJECT_SCRIPT_TOOL_UNIVERSAL_BRIDGE_LOADED__) return;
|
||||
window.__INJECT_SCRIPT_TOOL_UNIVERSAL_BRIDGE_LOADED__ = true;
|
||||
const EVENT_NAME = {
|
||||
RESPONSE: 'chrome-mcp:response',
|
||||
CLEANUP: 'chrome-mcp:cleanup',
|
||||
EXECUTE: 'chrome-mcp:execute',
|
||||
};
|
||||
const pendingRequests = new Map();
|
||||
|
||||
const messageHandler = (request, _sender, sendResponse) => {
|
||||
// --- Lifecycle Command ---
|
||||
if (request.type === EVENT_NAME.CLEANUP) {
|
||||
window.dispatchEvent(new CustomEvent(EVENT_NAME.CLEANUP));
|
||||
// Acknowledge cleanup signal received, but don't hold the connection.
|
||||
sendResponse({ success: true });
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- Execution Command for MAIN world ---
|
||||
if (request.targetWorld === 'MAIN') {
|
||||
const requestId = `req-${Date.now()}-${Math.random()}`;
|
||||
pendingRequests.set(requestId, sendResponse);
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent(EVENT_NAME.EXECUTE, {
|
||||
detail: {
|
||||
action: request.action,
|
||||
payload: request.payload,
|
||||
requestId: requestId,
|
||||
},
|
||||
}),
|
||||
);
|
||||
return true; // Async response is expected.
|
||||
}
|
||||
// Note: Requests for ISOLATED world are handled by the user's isolatedWorldCode script directly.
|
||||
// This listener won't process them unless it's the only script in ISOLATED world.
|
||||
};
|
||||
|
||||
chrome.runtime.onMessage.addListener(messageHandler);
|
||||
|
||||
// Listen for responses coming back from the MAIN world.
|
||||
const responseHandler = (event) => {
|
||||
const { requestId, data, error } = event.detail;
|
||||
if (pendingRequests.has(requestId)) {
|
||||
const sendResponse = pendingRequests.get(requestId);
|
||||
sendResponse({ data, error });
|
||||
pendingRequests.delete(requestId);
|
||||
}
|
||||
};
|
||||
window.addEventListener(EVENT_NAME.RESPONSE, responseHandler);
|
||||
|
||||
// --- Self Cleanup ---
|
||||
// When the cleanup signal arrives, this bridge must also clean itself up.
|
||||
const cleanupHandler = () => {
|
||||
chrome.runtime.onMessage.removeListener(messageHandler);
|
||||
window.removeEventListener(EVENT_NAME.RESPONSE, responseHandler);
|
||||
window.removeEventListener(EVENT_NAME.CLEANUP, cleanupHandler);
|
||||
delete window.__INJECT_SCRIPT_TOOL_UNIVERSAL_BRIDGE_LOADED__;
|
||||
};
|
||||
window.addEventListener(EVENT_NAME.CLEANUP, cleanupHandler);
|
||||
})();
|
@@ -0,0 +1,354 @@
|
||||
/* eslint-disable */
|
||||
// interactive-elements-helper.js
|
||||
// This script is injected into the page to find interactive elements.
|
||||
// Final version by Calvin, featuring a multi-layered fallback strategy
|
||||
// and comprehensive element support, built on a performant and reliable core.
|
||||
|
||||
(function () {
|
||||
// Prevent re-initialization
|
||||
if (window.__INTERACTIVE_ELEMENTS_HELPER_INITIALIZED__) {
|
||||
return;
|
||||
}
|
||||
window.__INTERACTIVE_ELEMENTS_HELPER_INITIALIZED__ = true;
|
||||
|
||||
/**
|
||||
* @typedef {Object} ElementInfo
|
||||
* @property {string} type - The type of the element (e.g., 'button', 'link').
|
||||
* @property {string} selector - A CSS selector to uniquely identify the element.
|
||||
* @property {string} text - The visible text or accessible name of the element.
|
||||
* @property {boolean} isInteractive - Whether the element is currently interactive.
|
||||
* @property {Object} [coordinates] - The coordinates of the element if requested.
|
||||
* @property {boolean} [disabled] - For elements that can be disabled.
|
||||
* @property {string} [href] - For links.
|
||||
* @property {boolean} [checked] - for checkboxes and radio buttons.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration for element types and their corresponding selectors.
|
||||
* Now more comprehensive with common ARIA roles.
|
||||
*/
|
||||
const ELEMENT_CONFIG = {
|
||||
button: 'button, input[type="button"], input[type="submit"], [role="button"]',
|
||||
link: 'a[href], [role="link"]',
|
||||
input:
|
||||
'input:not([type="button"]):not([type="submit"]):not([type="checkbox"]):not([type="radio"])',
|
||||
checkbox: 'input[type="checkbox"], [role="checkbox"]',
|
||||
radio: 'input[type="radio"], [role="radio"]',
|
||||
textarea: 'textarea',
|
||||
select: 'select',
|
||||
tab: '[role="tab"]',
|
||||
// Generic interactive elements: combines tabindex, common roles, and explicit handlers.
|
||||
// This is the key to finding custom-built interactive components.
|
||||
interactive: `[onclick], [tabindex]:not([tabindex^="-"]), [role="menuitem"], [role="slider"], [role="option"], [role="treeitem"]`,
|
||||
};
|
||||
|
||||
// A combined selector for ANY interactive element, used in the fallback logic.
|
||||
const ANY_INTERACTIVE_SELECTOR = Object.values(ELEMENT_CONFIG).join(', ');
|
||||
|
||||
// --- Core Helper Functions ---
|
||||
|
||||
/**
|
||||
* Checks if an element is genuinely visible on the page.
|
||||
* "Visible" means it's not styled with display:none, visibility:hidden, etc.
|
||||
* This check intentionally IGNORES whether the element is within the current viewport.
|
||||
* @param {Element} el The element to check.
|
||||
* @returns {boolean} True if the element is visible.
|
||||
*/
|
||||
function isElementVisible(el) {
|
||||
if (!el || !el.isConnected) return false;
|
||||
|
||||
const style = window.getComputedStyle(el);
|
||||
if (
|
||||
style.display === 'none' ||
|
||||
style.visibility === 'hidden' ||
|
||||
parseFloat(style.opacity) === 0
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rect = el.getBoundingClientRect();
|
||||
return rect.width > 0 || rect.height > 0 || el.tagName === 'A'; // Allow zero-size anchors as they can still be navigated
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an element is considered interactive (not disabled or hidden from accessibility).
|
||||
* @param {Element} el The element to check.
|
||||
* @returns {boolean} True if the element is interactive.
|
||||
*/
|
||||
function isElementInteractive(el) {
|
||||
if (el.hasAttribute('disabled') || el.getAttribute('aria-disabled') === 'true') {
|
||||
return false;
|
||||
}
|
||||
if (el.closest('[aria-hidden="true"]')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a reasonably stable CSS selector for a given element.
|
||||
* @param {Element} el The element.
|
||||
* @returns {string} A CSS selector.
|
||||
*/
|
||||
function generateSelector(el) {
|
||||
if (!(el instanceof Element)) return '';
|
||||
|
||||
if (el.id) {
|
||||
const idSelector = `#${CSS.escape(el.id)}`;
|
||||
if (document.querySelectorAll(idSelector).length === 1) return idSelector;
|
||||
}
|
||||
|
||||
for (const attr of ['data-testid', 'data-cy', 'name']) {
|
||||
const attrValue = el.getAttribute(attr);
|
||||
if (attrValue) {
|
||||
const attrSelector = `[${attr}="${CSS.escape(attrValue)}"]`;
|
||||
if (document.querySelectorAll(attrSelector).length === 1) return attrSelector;
|
||||
}
|
||||
}
|
||||
|
||||
let path = '';
|
||||
let current = el;
|
||||
while (current && current.nodeType === Node.ELEMENT_NODE && current.tagName !== 'BODY') {
|
||||
let selector = current.tagName.toLowerCase();
|
||||
const parent = current.parentElement;
|
||||
if (parent) {
|
||||
const siblings = Array.from(parent.children).filter(
|
||||
(child) => child.tagName === current.tagName,
|
||||
);
|
||||
if (siblings.length > 1) {
|
||||
const index = siblings.indexOf(current) + 1;
|
||||
selector += `:nth-of-type(${index})`;
|
||||
}
|
||||
}
|
||||
path = path ? `${selector} > ${path}` : selector;
|
||||
current = parent;
|
||||
}
|
||||
return path ? `body > ${path}` : 'body';
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the accessible name for an element (label, aria-label, etc.).
|
||||
* @param {Element} el The element.
|
||||
* @returns {string} The accessible name.
|
||||
*/
|
||||
function getAccessibleName(el) {
|
||||
const labelledby = el.getAttribute('aria-labelledby');
|
||||
if (labelledby) {
|
||||
const labelElement = document.getElementById(labelledby);
|
||||
if (labelElement) return labelElement.textContent?.trim() || '';
|
||||
}
|
||||
const ariaLabel = el.getAttribute('aria-label');
|
||||
if (ariaLabel) return ariaLabel.trim();
|
||||
if (el.id) {
|
||||
const label = document.querySelector(`label[for="${el.id}"]`);
|
||||
if (label) return label.textContent?.trim() || '';
|
||||
}
|
||||
const parentLabel = el.closest('label');
|
||||
if (parentLabel) return parentLabel.textContent?.trim() || '';
|
||||
return (
|
||||
el.getAttribute('placeholder') ||
|
||||
el.getAttribute('value') ||
|
||||
el.textContent?.trim() ||
|
||||
el.getAttribute('title') ||
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple subsequence matching for fuzzy search.
|
||||
* @param {string} text The text to search within.
|
||||
* @param {string} query The query subsequence.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function fuzzyMatch(text, query) {
|
||||
if (!text || !query) return false;
|
||||
const lowerText = text.toLowerCase();
|
||||
const lowerQuery = query.toLowerCase();
|
||||
let textIndex = 0;
|
||||
let queryIndex = 0;
|
||||
while (textIndex < lowerText.length && queryIndex < lowerQuery.length) {
|
||||
if (lowerText[textIndex] === lowerQuery[queryIndex]) {
|
||||
queryIndex++;
|
||||
}
|
||||
textIndex++;
|
||||
}
|
||||
return queryIndex === lowerQuery.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the standardized info object for an element.
|
||||
* Modified to handle the new 'text' type from the final fallback.
|
||||
*/
|
||||
function createElementInfo(el, type, includeCoordinates, isInteractiveOverride = null) {
|
||||
const isActuallyInteractive = isElementInteractive(el);
|
||||
const info = {
|
||||
type,
|
||||
selector: generateSelector(el),
|
||||
text: getAccessibleName(el) || el.textContent?.trim(),
|
||||
isInteractive: isInteractiveOverride !== null ? isInteractiveOverride : isActuallyInteractive,
|
||||
disabled: el.hasAttribute('disabled') || el.getAttribute('aria-disabled') === 'true',
|
||||
};
|
||||
if (includeCoordinates) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
info.coordinates = {
|
||||
x: rect.left + rect.width / 2,
|
||||
y: rect.top + rect.height / 2,
|
||||
rect: {
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
top: rect.top,
|
||||
right: rect.right,
|
||||
bottom: rect.bottom,
|
||||
left: rect.left,
|
||||
},
|
||||
};
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* [CORE UTILITY] Finds interactive elements based on a set of types.
|
||||
* This is our high-performance Layer 1 search function.
|
||||
*/
|
||||
function findInteractiveElements(options = {}) {
|
||||
const { textQuery, includeCoordinates = true, types = Object.keys(ELEMENT_CONFIG) } = options;
|
||||
|
||||
const selectorsToFind = types
|
||||
.map((type) => ELEMENT_CONFIG[type])
|
||||
.filter(Boolean)
|
||||
.join(', ');
|
||||
if (!selectorsToFind) return [];
|
||||
|
||||
const targetElements = Array.from(document.querySelectorAll(selectorsToFind));
|
||||
const uniqueElements = new Set(targetElements);
|
||||
const results = [];
|
||||
|
||||
for (const el of uniqueElements) {
|
||||
if (!isElementVisible(el) || !isElementInteractive(el)) continue;
|
||||
|
||||
const accessibleName = getAccessibleName(el);
|
||||
if (textQuery && !fuzzyMatch(accessibleName, textQuery)) continue;
|
||||
|
||||
let elementType = 'unknown';
|
||||
for (const [type, typeSelector] of Object.entries(ELEMENT_CONFIG)) {
|
||||
if (el.matches(typeSelector)) {
|
||||
elementType = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
results.push(createElementInfo(el, elementType, includeCoordinates));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* [ORCHESTRATOR] The main entry point that implements the 3-layer fallback logic.
|
||||
* @param {object} options - The main search options.
|
||||
* @returns {ElementInfo[]}
|
||||
*/
|
||||
function findElementsByTextWithFallback(options = {}) {
|
||||
const { textQuery, includeCoordinates = true } = options;
|
||||
|
||||
if (!textQuery) {
|
||||
return findInteractiveElements({ ...options, types: Object.keys(ELEMENT_CONFIG) });
|
||||
}
|
||||
|
||||
// --- Layer 1: High-reliability search for interactive elements matching text ---
|
||||
let results = findInteractiveElements({ ...options, types: Object.keys(ELEMENT_CONFIG) });
|
||||
if (results.length > 0) {
|
||||
return results;
|
||||
}
|
||||
|
||||
// --- Layer 2: Find text, then find its interactive ancestor ---
|
||||
const lowerCaseText = textQuery.toLowerCase();
|
||||
const xPath = `//text()[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '${lowerCaseText}')]`;
|
||||
const textNodes = document.evaluate(
|
||||
xPath,
|
||||
document,
|
||||
null,
|
||||
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
|
||||
null,
|
||||
);
|
||||
|
||||
const interactiveElements = new Set();
|
||||
if (textNodes.snapshotLength > 0) {
|
||||
for (let i = 0; i < textNodes.snapshotLength; i++) {
|
||||
const parentElement = textNodes.snapshotItem(i).parentElement;
|
||||
if (parentElement) {
|
||||
const interactiveAncestor = parentElement.closest(ANY_INTERACTIVE_SELECTOR);
|
||||
if (
|
||||
interactiveAncestor &&
|
||||
isElementVisible(interactiveAncestor) &&
|
||||
isElementInteractive(interactiveAncestor)
|
||||
) {
|
||||
interactiveElements.add(interactiveAncestor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (interactiveElements.size > 0) {
|
||||
return Array.from(interactiveElements).map((el) => {
|
||||
let elementType = 'interactive';
|
||||
for (const [type, typeSelector] of Object.entries(ELEMENT_CONFIG)) {
|
||||
if (el.matches(typeSelector)) {
|
||||
elementType = type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return createElementInfo(el, elementType, includeCoordinates);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// --- Layer 3: Final fallback, return any element containing the text ---
|
||||
const leafElements = new Set();
|
||||
for (let i = 0; i < textNodes.snapshotLength; i++) {
|
||||
const parentElement = textNodes.snapshotItem(i).parentElement;
|
||||
if (parentElement && isElementVisible(parentElement)) {
|
||||
leafElements.add(parentElement);
|
||||
}
|
||||
}
|
||||
|
||||
const finalElements = Array.from(leafElements).filter((el) => {
|
||||
return ![...leafElements].some((otherEl) => el !== otherEl && el.contains(otherEl));
|
||||
});
|
||||
|
||||
return finalElements.map((el) => createElementInfo(el, 'text', includeCoordinates, true));
|
||||
}
|
||||
|
||||
// --- Chrome Message Listener ---
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
if (request.action === 'getInteractiveElements') {
|
||||
try {
|
||||
let elements;
|
||||
if (request.selector) {
|
||||
// If a selector is provided, bypass the text-based logic and use a direct query.
|
||||
const foundEls = Array.from(document.querySelectorAll(request.selector));
|
||||
elements = foundEls.map((el) =>
|
||||
createElementInfo(
|
||||
el,
|
||||
'selected',
|
||||
request.includeCoordinates !== false,
|
||||
isElementInteractive(el),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Otherwise, use our powerful multi-layered text search
|
||||
elements = findElementsByTextWithFallback(request);
|
||||
}
|
||||
sendResponse({ success: true, elements });
|
||||
} catch (error) {
|
||||
console.error('Error in getInteractiveElements:', error);
|
||||
sendResponse({ success: false, error: error.message });
|
||||
}
|
||||
return true; // Async response
|
||||
} else if (request.action === 'chrome_get_interactive_elements_ping') {
|
||||
sendResponse({ status: 'pong' });
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Interactive elements helper script loaded');
|
||||
})();
|
@@ -0,0 +1,291 @@
|
||||
/* eslint-disable */
|
||||
// keyboard-helper.js
|
||||
// This script is injected into the page to handle keyboard event simulation
|
||||
|
||||
if (window.__KEYBOARD_HELPER_INITIALIZED__) {
|
||||
// Already initialized, skip
|
||||
} else {
|
||||
window.__KEYBOARD_HELPER_INITIALIZED__ = true;
|
||||
|
||||
// A map for special keys to their KeyboardEvent properties
|
||||
// Key names should be lowercase for matching
|
||||
const SPECIAL_KEY_MAP = {
|
||||
enter: { key: 'Enter', code: 'Enter', keyCode: 13 },
|
||||
tab: { key: 'Tab', code: 'Tab', keyCode: 9 },
|
||||
esc: { key: 'Escape', code: 'Escape', keyCode: 27 },
|
||||
escape: { key: 'Escape', code: 'Escape', keyCode: 27 },
|
||||
space: { key: ' ', code: 'Space', keyCode: 32 },
|
||||
backspace: { key: 'Backspace', code: 'Backspace', keyCode: 8 },
|
||||
delete: { key: 'Delete', code: 'Delete', keyCode: 46 },
|
||||
del: { key: 'Delete', code: 'Delete', keyCode: 46 },
|
||||
up: { key: 'ArrowUp', code: 'ArrowUp', keyCode: 38 },
|
||||
arrowup: { key: 'ArrowUp', code: 'ArrowUp', keyCode: 38 },
|
||||
down: { key: 'ArrowDown', code: 'ArrowDown', keyCode: 40 },
|
||||
arrowdown: { key: 'ArrowDown', code: 'ArrowDown', keyCode: 40 },
|
||||
left: { key: 'ArrowLeft', code: 'ArrowLeft', keyCode: 37 },
|
||||
arrowleft: { key: 'ArrowLeft', code: 'ArrowLeft', keyCode: 37 },
|
||||
right: { key: 'ArrowRight', code: 'ArrowRight', keyCode: 39 },
|
||||
arrowright: { key: 'ArrowRight', code: 'ArrowRight', keyCode: 39 },
|
||||
home: { key: 'Home', code: 'Home', keyCode: 36 },
|
||||
end: { key: 'End', code: 'End', keyCode: 35 },
|
||||
pageup: { key: 'PageUp', code: 'PageUp', keyCode: 33 },
|
||||
pagedown: { key: 'PageDown', code: 'PageDown', keyCode: 34 },
|
||||
insert: { key: 'Insert', code: 'Insert', keyCode: 45 },
|
||||
// Function keys
|
||||
...Object.fromEntries(
|
||||
Array.from({ length: 12 }, (_, i) => [
|
||||
`f${i + 1}`,
|
||||
{ key: `F${i + 1}`, code: `F${i + 1}`, keyCode: 112 + i },
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
const MODIFIER_KEYS = {
|
||||
ctrl: 'ctrlKey',
|
||||
control: 'ctrlKey',
|
||||
alt: 'altKey',
|
||||
shift: 'shiftKey',
|
||||
meta: 'metaKey',
|
||||
command: 'metaKey',
|
||||
cmd: 'metaKey',
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a key string (e.g., "Ctrl+Shift+A", "Enter") into a main key and modifiers.
|
||||
* @param {string} keyString - String representation of a single key press (can include modifiers).
|
||||
* @returns { {key: string, code: string, keyCode: number, charCode?: number, modifiers: {ctrlKey:boolean, altKey:boolean, shiftKey:boolean, metaKey:boolean}} | null }
|
||||
* Returns null if the keyString is invalid or represents only modifiers.
|
||||
*/
|
||||
function parseSingleKeyCombination(keyString) {
|
||||
const parts = keyString.split('+').map((part) => part.trim().toLowerCase());
|
||||
const modifiers = {
|
||||
ctrlKey: false,
|
||||
altKey: false,
|
||||
shiftKey: false,
|
||||
metaKey: false,
|
||||
};
|
||||
let mainKeyPart = null;
|
||||
|
||||
for (const part of parts) {
|
||||
if (MODIFIER_KEYS[part]) {
|
||||
modifiers[MODIFIER_KEYS[part]] = true;
|
||||
} else if (mainKeyPart === null) {
|
||||
// First non-modifier is the main key
|
||||
mainKeyPart = part;
|
||||
} else {
|
||||
// Invalid format: multiple main keys in a single combination (e.g., "Ctrl+A+B")
|
||||
console.error(`Invalid key combination string: ${keyString}. Multiple main keys found.`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mainKeyPart) {
|
||||
// This case could happen if the keyString is something like "Ctrl+" or just "Ctrl"
|
||||
// If the intent was to press JUST 'Control', the input should be 'Control' not 'Control+'
|
||||
// Let's check if mainKeyPart is actually a modifier name used as a main key
|
||||
if (Object.keys(MODIFIER_KEYS).includes(parts[parts.length - 1]) && parts.length === 1) {
|
||||
mainKeyPart = parts[parts.length - 1]; // e.g. user wants to press "Control" key itself
|
||||
// For "Control" key itself, key: "Control", code: "ControlLeft" (or Right)
|
||||
if (mainKeyPart === 'ctrl' || mainKeyPart === 'control')
|
||||
return { key: 'Control', code: 'ControlLeft', keyCode: 17, modifiers };
|
||||
if (mainKeyPart === 'alt') return { key: 'Alt', code: 'AltLeft', keyCode: 18, modifiers };
|
||||
if (mainKeyPart === 'shift')
|
||||
return { key: 'Shift', code: 'ShiftLeft', keyCode: 16, modifiers };
|
||||
if (mainKeyPart === 'meta' || mainKeyPart === 'command' || mainKeyPart === 'cmd')
|
||||
return { key: 'Meta', code: 'MetaLeft', keyCode: 91, modifiers };
|
||||
} else {
|
||||
console.error(`Invalid key combination string: ${keyString}. No main key specified.`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const specialKey = SPECIAL_KEY_MAP[mainKeyPart];
|
||||
if (specialKey) {
|
||||
return { ...specialKey, modifiers };
|
||||
}
|
||||
|
||||
// For single characters or other unmapped keys
|
||||
if (mainKeyPart.length === 1) {
|
||||
const charCode = mainKeyPart.charCodeAt(0);
|
||||
// If Shift is active and it's a letter, use the uppercase version for 'key'
|
||||
// This mimics more closely how keyboards behave.
|
||||
let keyChar = mainKeyPart;
|
||||
if (modifiers.shiftKey && mainKeyPart.match(/^[a-z]$/i)) {
|
||||
keyChar = mainKeyPart.toUpperCase();
|
||||
}
|
||||
|
||||
return {
|
||||
key: keyChar,
|
||||
code: `Key${mainKeyPart.toUpperCase()}`, // 'a' -> KeyA, 'A' -> KeyA
|
||||
keyCode: charCode,
|
||||
charCode: charCode, // charCode is legacy, but some old systems might use it
|
||||
modifiers,
|
||||
};
|
||||
}
|
||||
|
||||
console.error(`Unknown key: ${mainKeyPart} in string "${keyString}"`);
|
||||
return null; // Or handle as an error
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates a single key press (keydown, (keypress), keyup) for a parsed key.
|
||||
* @param { {key: string, code: string, keyCode: number, charCode?: number, modifiers: object} } parsedKeyInfo
|
||||
* @param {Element} element - Target element.
|
||||
* @returns {{success: boolean, error?: string}}
|
||||
*/
|
||||
function dispatchKeyEvents(parsedKeyInfo, element) {
|
||||
if (!parsedKeyInfo) return { success: false, error: 'Invalid key info provided for dispatch.' };
|
||||
|
||||
const { key, code, keyCode, charCode, modifiers } = parsedKeyInfo;
|
||||
|
||||
const eventOptions = {
|
||||
key: key,
|
||||
code: code,
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
composed: true, // Important for shadow DOM
|
||||
view: window,
|
||||
...modifiers, // ctrlKey, altKey, shiftKey, metaKey
|
||||
// keyCode/which are deprecated but often set for compatibility
|
||||
keyCode: keyCode || (key.length === 1 ? key.charCodeAt(0) : 0),
|
||||
which: keyCode || (key.length === 1 ? key.charCodeAt(0) : 0),
|
||||
};
|
||||
|
||||
try {
|
||||
const kdRes = element.dispatchEvent(new KeyboardEvent('keydown', eventOptions));
|
||||
|
||||
// keypress is deprecated, but simulate if it's a character key or Enter
|
||||
// Only dispatch if keydown was not cancelled and it's a character producing key
|
||||
if (kdRes && (key.length === 1 || key === 'Enter' || key === ' ')) {
|
||||
const keypressOptions = { ...eventOptions };
|
||||
if (charCode) keypressOptions.charCode = charCode;
|
||||
element.dispatchEvent(new KeyboardEvent('keypress', keypressOptions));
|
||||
}
|
||||
|
||||
element.dispatchEvent(new KeyboardEvent('keyup', eventOptions));
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error(`Error dispatching key events for "${key}":`, error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Error dispatching key events for "${key}": ${error.message}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate keyboard events on an element or document
|
||||
* @param {string} keysSequenceString - String representation of key(s) (e.g., "Enter", "Ctrl+C, A, B")
|
||||
* @param {Element} targetElement - Element to dispatch events on (optional)
|
||||
* @param {number} delay - Delay between key sequences in milliseconds (optional)
|
||||
* @returns {Promise<Object>} - Result of the keyboard operation
|
||||
*/
|
||||
async function simulateKeyboard(keysSequenceString, targetElement = null, delay = 0) {
|
||||
try {
|
||||
const element = targetElement || document.activeElement || document.body;
|
||||
|
||||
if (element !== document.activeElement && typeof element.focus === 'function') {
|
||||
element.focus();
|
||||
await new Promise((resolve) => setTimeout(resolve, 50)); // Small delay for focus
|
||||
}
|
||||
|
||||
const keyCombinations = keysSequenceString
|
||||
.split(',')
|
||||
.map((k) => k.trim())
|
||||
.filter((k) => k.length > 0);
|
||||
const operationResults = [];
|
||||
|
||||
for (let i = 0; i < keyCombinations.length; i++) {
|
||||
const comboString = keyCombinations[i];
|
||||
const parsedKeyInfo = parseSingleKeyCombination(comboString);
|
||||
|
||||
if (!parsedKeyInfo) {
|
||||
operationResults.push({
|
||||
keyCombination: comboString,
|
||||
success: false,
|
||||
error: `Invalid key string or combination: ${comboString}`,
|
||||
});
|
||||
continue; // Skip to next combination in sequence
|
||||
}
|
||||
|
||||
const dispatchResult = dispatchKeyEvents(parsedKeyInfo, element);
|
||||
operationResults.push({
|
||||
keyCombination: comboString,
|
||||
...dispatchResult,
|
||||
});
|
||||
|
||||
if (dispatchResult.error) {
|
||||
// Optionally, decide if sequence should stop on first error
|
||||
// For now, we continue but log the error in results
|
||||
console.warn(
|
||||
`Failed to simulate key combination "${comboString}": ${dispatchResult.error}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (delay > 0 && i < keyCombinations.length - 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if all individual operations were successful
|
||||
const overallSuccess = operationResults.every((r) => r.success);
|
||||
|
||||
return {
|
||||
success: overallSuccess,
|
||||
message: overallSuccess
|
||||
? `Keyboard events simulated successfully: ${keysSequenceString}`
|
||||
: `Some keyboard events failed for: ${keysSequenceString}`,
|
||||
results: operationResults, // Detailed results for each key combination
|
||||
targetElement: {
|
||||
tagName: element.tagName,
|
||||
id: element.id,
|
||||
className: element.className,
|
||||
type: element.type, // if applicable e.g. for input
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error in simulateKeyboard:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Error simulating keyboard events: ${error.message}`,
|
||||
results: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Listener for messages from the extension
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
if (request.action === 'simulateKeyboard') {
|
||||
let targetEl = null;
|
||||
if (request.selector) {
|
||||
targetEl = document.querySelector(request.selector);
|
||||
if (!targetEl) {
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: `Element with selector "${request.selector}" not found`,
|
||||
results: [],
|
||||
});
|
||||
return true; // Keep channel open for async response
|
||||
}
|
||||
}
|
||||
|
||||
simulateKeyboard(request.keys, targetEl, request.delay)
|
||||
.then(sendResponse)
|
||||
.catch((error) => {
|
||||
// This catch is for unexpected errors in simulateKeyboard promise chain itself
|
||||
console.error('Unexpected error in simulateKeyboard promise chain:', error);
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: `Unexpected error during keyboard simulation: ${error.message}`,
|
||||
results: [],
|
||||
});
|
||||
});
|
||||
return true; // Indicates async response is expected
|
||||
} else if (request.action === 'chrome_keyboard_ping') {
|
||||
sendResponse({ status: 'pong', initialized: true }); // Respond that it's initialized
|
||||
return false; // Synchronous response
|
||||
}
|
||||
// Not our message, or no async response needed
|
||||
return false;
|
||||
});
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Network Capture Helper
|
||||
*
|
||||
* This script helps replay network requests with the original cookies and headers.
|
||||
*/
|
||||
|
||||
// Prevent duplicate initialization
|
||||
if (window.__NETWORK_CAPTURE_HELPER_INITIALIZED__) {
|
||||
// Already initialized, skip
|
||||
} else {
|
||||
window.__NETWORK_CAPTURE_HELPER_INITIALIZED__ = true;
|
||||
|
||||
/**
|
||||
* Replay a network request
|
||||
* @param {string} url - The URL to send the request to
|
||||
* @param {string} method - The HTTP method to use
|
||||
* @param {Object} headers - The headers to include in the request
|
||||
* @param {any} body - The body of the request
|
||||
* @param {number} timeout - Timeout in milliseconds (default: 30000)
|
||||
* @returns {Promise<Object>} - The response data
|
||||
*/
|
||||
async function replayNetworkRequest(url, method, headers, body, timeout = 30000) {
|
||||
try {
|
||||
// Create fetch options
|
||||
const options = {
|
||||
method: method,
|
||||
headers: headers || {},
|
||||
credentials: 'include', // Include cookies
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
};
|
||||
|
||||
// Add body for non-GET requests
|
||||
if (method !== 'GET' && method !== 'HEAD' && body !== undefined) {
|
||||
options.body = body;
|
||||
}
|
||||
|
||||
// 创建一个带超时的 fetch
|
||||
const fetchWithTimeout = async (url, options, timeout) => {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
// 设置超时
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { ...options, signal });
|
||||
clearTimeout(timeoutId);
|
||||
return response;
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutId);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// 发送带超时的请求
|
||||
const response = await fetchWithTimeout(url, options, timeout);
|
||||
|
||||
// Process response
|
||||
const responseData = {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: {},
|
||||
};
|
||||
|
||||
// Get response headers
|
||||
response.headers.forEach((value, key) => {
|
||||
responseData.headers[key] = value;
|
||||
});
|
||||
|
||||
// Try to get response body based on content type
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
|
||||
try {
|
||||
if (contentType.includes('application/json')) {
|
||||
responseData.body = await response.json();
|
||||
} else if (
|
||||
contentType.includes('text/') ||
|
||||
contentType.includes('application/xml') ||
|
||||
contentType.includes('application/javascript')
|
||||
) {
|
||||
responseData.body = await response.text();
|
||||
} else {
|
||||
// For binary data, just indicate it was received but not parsed
|
||||
responseData.body = '[Binary data not displayed]';
|
||||
}
|
||||
} catch (error) {
|
||||
responseData.body = `[Error parsing response body: ${error.message}]`;
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
response: responseData,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error replaying request:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: `Error replaying request: ${error.message}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for messages from the extension
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
// Respond to ping message
|
||||
if (request.action === 'chrome_network_request_ping') {
|
||||
sendResponse({ status: 'pong' });
|
||||
return false; // Synchronous response
|
||||
} else if (request.action === 'sendPureNetworkRequest') {
|
||||
replayNetworkRequest(
|
||||
request.url,
|
||||
request.method,
|
||||
request.headers,
|
||||
request.body,
|
||||
request.timeout,
|
||||
)
|
||||
.then(sendResponse)
|
||||
.catch((error) => {
|
||||
sendResponse({
|
||||
success: false,
|
||||
error: `Unexpected error: ${error.message}`,
|
||||
});
|
||||
});
|
||||
return true; // Indicates async response
|
||||
}
|
||||
});
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
/* eslint-disable */
|
||||
/**
|
||||
* Screenshot helper content script
|
||||
* Handles page preparation, scrolling, element positioning, etc.
|
||||
*/
|
||||
|
||||
if (window.__SCREENSHOT_HELPER_INITIALIZED__) {
|
||||
// Already initialized, skip
|
||||
} else {
|
||||
window.__SCREENSHOT_HELPER_INITIALIZED__ = true;
|
||||
|
||||
// Save original styles
|
||||
let originalOverflowStyle = '';
|
||||
let hiddenFixedElements = [];
|
||||
|
||||
/**
|
||||
* Get fixed/sticky positioned elements
|
||||
* @returns Array of fixed/sticky elements
|
||||
*/
|
||||
function getFixedElements() {
|
||||
const fixed = [];
|
||||
|
||||
document.querySelectorAll('*').forEach((el) => {
|
||||
const htmlEl = el;
|
||||
const style = window.getComputedStyle(htmlEl);
|
||||
if (style.position === 'fixed' || style.position === 'sticky') {
|
||||
// Filter out tiny or invisible elements, and elements that are part of the extension UI
|
||||
if (
|
||||
htmlEl.offsetWidth > 1 &&
|
||||
htmlEl.offsetHeight > 1 &&
|
||||
!htmlEl.id.startsWith('chrome-mcp-')
|
||||
) {
|
||||
fixed.push({
|
||||
element: htmlEl,
|
||||
originalDisplay: htmlEl.style.display,
|
||||
originalVisibility: htmlEl.style.visibility,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide fixed/sticky elements
|
||||
*/
|
||||
function hideFixedElements() {
|
||||
hiddenFixedElements = getFixedElements();
|
||||
hiddenFixedElements.forEach((item) => {
|
||||
item.element.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore fixed/sticky elements
|
||||
*/
|
||||
function showFixedElements() {
|
||||
hiddenFixedElements.forEach((item) => {
|
||||
item.element.style.display = item.originalDisplay || '';
|
||||
});
|
||||
hiddenFixedElements = [];
|
||||
}
|
||||
|
||||
// Listen for messages from the extension
|
||||
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||
// Respond to ping message
|
||||
if (request.action === 'chrome_screenshot_ping') {
|
||||
sendResponse({ status: 'pong' });
|
||||
return false; // Synchronous response
|
||||
}
|
||||
|
||||
// Prepare page for capture
|
||||
else if (request.action === 'preparePageForCapture') {
|
||||
originalOverflowStyle = document.documentElement.style.overflow;
|
||||
document.documentElement.style.overflow = 'hidden'; // Hide main scrollbar
|
||||
if (request.options?.fullPage) {
|
||||
// Only hide fixed elements for full page to avoid flicker
|
||||
hideFixedElements();
|
||||
}
|
||||
// Give styles a moment to apply
|
||||
setTimeout(() => {
|
||||
sendResponse({ success: true });
|
||||
}, 50);
|
||||
return true; // Async response
|
||||
}
|
||||
|
||||
// Get page details
|
||||
else if (request.action === 'getPageDetails') {
|
||||
const body = document.body;
|
||||
const html = document.documentElement;
|
||||
sendResponse({
|
||||
totalWidth: Math.max(
|
||||
body.scrollWidth,
|
||||
body.offsetWidth,
|
||||
html.clientWidth,
|
||||
html.scrollWidth,
|
||||
html.offsetWidth,
|
||||
),
|
||||
totalHeight: Math.max(
|
||||
body.scrollHeight,
|
||||
body.offsetHeight,
|
||||
html.clientHeight,
|
||||
html.scrollHeight,
|
||||
html.offsetHeight,
|
||||
),
|
||||
viewportWidth: window.innerWidth,
|
||||
viewportHeight: window.innerHeight,
|
||||
devicePixelRatio: window.devicePixelRatio || 1,
|
||||
currentScrollX: window.scrollX,
|
||||
currentScrollY: window.scrollY,
|
||||
});
|
||||
}
|
||||
|
||||
// Get element details
|
||||
else if (request.action === 'getElementDetails') {
|
||||
const element = document.querySelector(request.selector);
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'instant', block: 'nearest', inline: 'nearest' });
|
||||
setTimeout(() => {
|
||||
// Wait for scroll
|
||||
const rect = element.getBoundingClientRect();
|
||||
sendResponse({
|
||||
rect: { x: rect.left, y: rect.top, width: rect.width, height: rect.height },
|
||||
devicePixelRatio: window.devicePixelRatio || 1,
|
||||
});
|
||||
}, 200); // Increased delay for scrollIntoView
|
||||
return true; // Async response
|
||||
} else {
|
||||
sendResponse({ error: `Element with selector "${request.selector}" not found.` });
|
||||
}
|
||||
return true; // Async response
|
||||
}
|
||||
|
||||
// Scroll page
|
||||
else if (request.action === 'scrollPage') {
|
||||
window.scrollTo({ left: request.x, top: request.y, behavior: 'instant' });
|
||||
// Wait for scroll and potential reflows/lazy-loading
|
||||
setTimeout(() => {
|
||||
sendResponse({
|
||||
success: true,
|
||||
newScrollX: window.scrollX,
|
||||
newScrollY: window.scrollY,
|
||||
});
|
||||
}, request.scrollDelay || 300); // Configurable delay
|
||||
return true; // Async response
|
||||
}
|
||||
|
||||
// Reset page
|
||||
else if (request.action === 'resetPageAfterCapture') {
|
||||
document.documentElement.style.overflow = originalOverflowStyle;
|
||||
showFixedElements();
|
||||
if (typeof request.scrollX !== 'undefined' && typeof request.scrollY !== 'undefined') {
|
||||
window.scrollTo({ left: request.scrollX, top: request.scrollY, behavior: 'instant' });
|
||||
}
|
||||
sendResponse({ success: true });
|
||||
}
|
||||
|
||||
return false; // Synchronous response
|
||||
});
|
||||
}
|
File diff suppressed because it is too large
Load Diff
2869
releases/chrome-extension/latest/chrome-mcp-server-lastest/libs/ort.min.js
vendored
Normal file
2869
releases/chrome-extension/latest/chrome-mcp-server-lastest/libs/ort.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"manifest_version":3,"name":"__MSG_extensionName__","description":"__MSG_extensionDescription__","version":"0.0.6","icons":{"16":"icon/16.png","32":"icon/32.png","48":"icon/48.png","96":"icon/96.png","128":"icon/128.png"},"key":"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDnB4a6/wwEIEnMqhd64+OblTmF0KlqvHkZJnYN7vdOLElFOzjZbl2dA4tQERDfiY5M0qTkp+1QnYGkS2sAAUYg9v8k0BQjKHM0JSZQaV+QjukglUDiNzsgcSw0Yek/KF0mFVtuKS72EpBI5krEJ8N/b6SVTfg+3arG4SeY6Bww2bEhcFusDv8w2FJnWHpnnIFGch02/NON4aDWPSZJfF1AxMBtXSHDaEaN+mEffwyflBEl9fjlYrJe8PJxAytgWkOwJErJXFHKxgONE84W5UgYWomEJHkFolxTLvBdPtryPp6ZWbwZUBR4mBuH2luo4L+JAlF17uDASzAs0qCEMwzAgMBAAECggEAS9LsaIspSohbSBJ+6UkycIecKUTC9Oz6rwnACOwxymL7Z+BgoxT/e0cpZ6kNzQvNTUbwlZu0hNKqZYlJJu8rCoGyeImr2I1q+rWvpGip+fM6o15SDfiziooS8GeIKRA0lbmnA80bLiV9QxrFeMgMn6PIh3i5HGDdcx5LngoIWyz122vrIMUAynkUlgWRuESOvBded1N2TzsJoyMwYPdFSBK7fY4hKehU/SuSHetiXDieS0RBWj+wOaoEJRaZFCiVrGPMV5BcKWMtgs9WkYG/AMFVYgXDNDgcfLy0ExckIvonY05nh/x50Np+EzZR65K56kpqJjIB6yZMacjevYOhQQKBgQDjJrkVTHM4Qd0fpL7AtJnRpQpr/fE+0vWpMvB+VkqoAEwKdLyymejy2lOuxfqUCkHY4IcITwTyw4A6hibfZ1zHnBc3yCJwcKCvZXuJZaQTvd6xGZSHf9JHcwkDtDZ1VYzrzV8gKV12GzaqQRmyagS0/fuITTfhG8bKSbv/0I4NeQKBgQDcc+alUI02hjJ9T1AkMQt9LeUXjMjzQVH6rVn0qts5Vs5LvgLOqdpnK5xTeomxM0qCPCy9Da6EqV7/5sFuybvj8oFvrxEnhEcGH/Iy2XH3yUtROGOkOsvEqkoo/6C5LUSehclCzZnFABb7z915utlbrNZFEQJyZTXf3Sz6QPH4CwKBgH2ke5eWU9z4QXExVPmOa86UNXGKYxhW498U+AVJgb3vfCAEdiNsEnfR35u6kmG0Uru9ZbNo0dnd3V2Bupqzt5QJeKY4IySCh768qVpUSC9LRJQ9C/Tu9MbkkEXmNoEsMuhzDnzhpHqhjtkZbTdMgRIDsk+wNopjLM/TfROArjIxAoGBAMGksSHfWttdD7aQ16WiyyO/D7AbA1zhsMAQS6cl+YEpZfaURmUAQA9F+IA/b/mOQ1GYx/ecsAJpwD/qk1jcrUVyfA39aoUapUSVBStzY6+zSoxiiuv0lY7/wjq3KJfgUpkojXw3m223QXkZwsKtxUXI0UJDybFwg91Lq7l7GNC3AoGARTBSr83TTKIkcHsnH9Wl7ZVgS44iRXvTe/7pLgwzPLVAWwBiOZFF7yDqIxZlSTUh9f+MWGCMmMqfm8SDom91G0L8KoQP1PMKrbspRCG65M1VJlecwSXG0MhxdUZ3l5vT0i/aYDP6hBcc57Q2iHHOtJTRk/va1l8uH/1JOUVj9gs=","default_locale":"zh_CN","permissions":["nativeMessaging","tabs","activeTab","scripting","downloads","webRequest","debugger","history","bookmarks","offscreen","storage"],"host_permissions":["<all_urls>"],"web_accessible_resources":[{"resources":["/models/*","/workers/*"],"matches":["<all_urls>"]}],"cross_origin_embedder_policy":{"value":"require-corp"},"cross_origin_opener_policy":{"value":"same-origin"},"content_security_policy":{"extension_pages":"script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"},"background":{"service_worker":"background.js"},"action":{"default_title":"Default Popup Title","default_popup":"popup.html"},"content_scripts":[{"matches":["*://*.google.com/*"],"js":["content-scripts/content.js"]}]}
|
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<script type="module" crossorigin src="/chunks/offscreen-QDezJN9Y.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/chunks/semantic-similarity-engine-D0u7zDKx.js">
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Default Popup Title</title>
|
||||
<meta name="manifest.type" content="browser_action">
|
||||
<script type="module" crossorigin src="/chunks/popup-CNE4nbSP.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/chunks/semantic-similarity-engine-D0u7zDKx.js">
|
||||
<link rel="stylesheet" crossorigin href="/assets/popup-OnFboBpW.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,125 @@
|
||||
var ortWasmThreaded = (() => {
|
||||
var _scriptName = import.meta.url;
|
||||
|
||||
return (
|
||||
async function(moduleArg = {}) {
|
||||
var moduleRtn;
|
||||
|
||||
var e=moduleArg,aa,ca,da=new Promise((a,b)=>{aa=a;ca=b}),ea="object"==typeof window,k="undefined"!=typeof WorkerGlobalScope,n="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type,q=k&&self.name?.startsWith("em-pthread");if(n){const {createRequire:a}=await import("module");var require=a(import.meta.url),fa=require("worker_threads");global.Worker=fa.Worker;q=(k=!fa.pc)&&"em-pthread"==fa.workerData}
|
||||
e.mountExternalData=(a,b)=>{a.startsWith("./")&&(a=a.substring(2));(e.Fb||(e.Fb=new Map)).set(a,b)};e.unmountExternalData=()=>{delete e.Fb};var SharedArrayBuffer=globalThis.SharedArrayBuffer??(new WebAssembly.Memory({initial:0,maximum:0,qc:!0})).buffer.constructor;
|
||||
const ha=a=>async(...b)=>{try{if(e.Gb)throw Error("Session already started");const c=e.Gb={ec:b[0],errors:[]},d=await a(...b);if(e.Gb!==c)throw Error("Session mismatch");e.Kb?.flush();const f=c.errors;if(0<f.length){let g=await Promise.all(f);g=g.filter(h=>h);if(0<g.length)throw Error(g.join("\n"));}return d}finally{e.Gb=null}};
|
||||
e.jsepInit=(a,b)=>{if("webgpu"===a){[e.Kb,e.Vb,e.Zb,e.Lb,e.Yb,e.kb,e.$b,e.bc,e.Wb,e.Xb,e.ac]=b;const c=e.Kb;e.jsepRegisterBuffer=(d,f,g,h)=>c.registerBuffer(d,f,g,h);e.jsepGetBuffer=d=>c.getBuffer(d);e.jsepCreateDownloader=(d,f,g)=>c.createDownloader(d,f,g);e.jsepOnCreateSession=d=>{c.onCreateSession(d)};e.jsepOnReleaseSession=d=>{c.onReleaseSession(d)};e.jsepOnRunStart=d=>c.onRunStart(d);e.cc=(d,f)=>{c.upload(d,f)}}else if("webnn"===a){const c=b[0];[e.oc,e.Ob,e.webnnEnsureTensor,e.Pb,e.webnnDownloadTensor]=
|
||||
b.slice(1);e.webnnReleaseTensorId=e.Ob;e.webnnUploadTensor=e.Pb;e.webnnOnRunStart=d=>c.onRunStart(d);e.webnnOnRunEnd=c.onRunEnd.bind(c);e.webnnRegisterMLContext=(d,f)=>{c.registerMLContext(d,f)};e.webnnOnReleaseSession=d=>{c.onReleaseSession(d)};e.webnnCreateMLTensorDownloader=(d,f)=>c.createMLTensorDownloader(d,f);e.webnnRegisterMLTensor=(d,f,g,h)=>c.registerMLTensor(d,f,g,h);e.webnnCreateMLContext=d=>c.createMLContext(d);e.webnnRegisterMLConstant=(d,f,g,h,l,m)=>c.registerMLConstant(d,f,g,h,l,e.Fb,
|
||||
m);e.webnnRegisterGraphInput=c.registerGraphInput.bind(c);e.webnnIsGraphInput=c.isGraphInput.bind(c);e.webnnRegisterGraphOutput=c.registerGraphOutput.bind(c);e.webnnIsGraphOutput=c.isGraphOutput.bind(c);e.webnnCreateTemporaryTensor=c.createTemporaryTensor.bind(c);e.webnnIsGraphInputOutputTypeSupported=c.isGraphInputOutputTypeSupported.bind(c)}};
|
||||
let ja=()=>{const a=(b,c,d)=>(...f)=>{const g=t,h=c?.();f=b(...f);const l=c?.();h!==l&&(b=l,d(h),c=d=null);return t!=g?ia():f};(b=>{for(const c of b)e[c]=a(e[c],()=>e[c],d=>e[c]=d)})(["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"]);"undefined"!==typeof ha&&(e._OrtRun=ha(e._OrtRun),e._OrtRunWithBinding=ha(e._OrtRunWithBinding));ja=void 0};e.asyncInit=()=>{ja?.()};var ka=Object.assign({},e),la="./this.program",ma=(a,b)=>{throw b;},v="",na,oa;
|
||||
if(n){var fs=require("fs"),pa=require("path");import.meta.url.startsWith("data:")||(v=pa.dirname(require("url").fileURLToPath(import.meta.url))+"/");oa=a=>{a=qa(a)?new URL(a):a;return fs.readFileSync(a)};na=async a=>{a=qa(a)?new URL(a):a;return fs.readFileSync(a,void 0)};!e.thisProgram&&1<process.argv.length&&(la=process.argv[1].replace(/\\/g,"/"));process.argv.slice(2);ma=(a,b)=>{process.exitCode=a;throw b;}}else if(ea||k)k?v=self.location.href:"undefined"!=typeof document&&
|
||||
document.currentScript&&(v=document.currentScript.src),_scriptName&&(v=_scriptName),v.startsWith("blob:")?v="":v=v.slice(0,v.replace(/[?#].*/,"").lastIndexOf("/")+1),n||(k&&(oa=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),na=async a=>{if(qa(a))return new Promise((c,d)=>{var f=new XMLHttpRequest;f.open("GET",a,!0);f.responseType="arraybuffer";f.onload=()=>{200==f.status||0==f.status&&f.response?c(f.response):d(f.status)};
|
||||
f.onerror=d;f.send(null)});var b=await fetch(a,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw Error(b.status+" : "+b.url);});var ra=console.log.bind(console),sa=console.error.bind(console);n&&(ra=(...a)=>fs.writeSync(1,a.join(" ")+"\n"),sa=(...a)=>fs.writeSync(2,a.join(" ")+"\n"));var ta=ra,x=sa;Object.assign(e,ka);ka=null;var ua=e.wasmBinary,z,va,A=!1,wa,B,xa,ya,za,Aa,Ba,Ca,C,Da,Ea,qa=a=>a.startsWith("file://");function D(){z.buffer!=B.buffer&&E();return B}
|
||||
function F(){z.buffer!=B.buffer&&E();return xa}function G(){z.buffer!=B.buffer&&E();return ya}function Fa(){z.buffer!=B.buffer&&E();return za}function H(){z.buffer!=B.buffer&&E();return Aa}function I(){z.buffer!=B.buffer&&E();return Ba}function Ga(){z.buffer!=B.buffer&&E();return Ca}function J(){z.buffer!=B.buffer&&E();return Ea}
|
||||
if(q){var Ha;if(n){var Ia=fa.parentPort;Ia.on("message",b=>onmessage({data:b}));Object.assign(globalThis,{self:global,postMessage:b=>Ia.postMessage(b)})}var Ja=!1;x=function(...b){b=b.join(" ");n?fs.writeSync(2,b+"\n"):console.error(b)};self.alert=function(...b){postMessage({Cb:"alert",text:b.join(" "),jc:Ka()})};self.onunhandledrejection=b=>{throw b.reason||b;};function a(b){try{var c=b.data,d=c.Cb;if("load"===d){let f=[];self.onmessage=g=>f.push(g);self.startWorker=()=>{postMessage({Cb:"loaded"});
|
||||
for(let g of f)a(g);self.onmessage=a};for(const g of c.Sb)if(!e[g]||e[g].proxy)e[g]=(...h)=>{postMessage({Cb:"callHandler",Rb:g,args:h})},"print"==g&&(ta=e[g]),"printErr"==g&&(x=e[g]);z=c.lc;E();Ha(c.mc)}else if("run"===d){La(c.Bb);Ma(c.Bb,0,0,1,0,0);Na();Oa(c.Bb);Ja||(Pa(),Ja=!0);try{Qa(c.hc,c.Ib)}catch(f){if("unwind"!=f)throw f;}}else"setimmediate"!==c.target&&("checkMailbox"===d?Ja&&Ra():d&&(x(`worker: received unknown command ${d}`),x(c)))}catch(f){throw Sa(),f;}}self.onmessage=a}
|
||||
function E(){var a=z.buffer;e.HEAP8=B=new Int8Array(a);e.HEAP16=ya=new Int16Array(a);e.HEAPU8=xa=new Uint8Array(a);e.HEAPU16=za=new Uint16Array(a);e.HEAP32=Aa=new Int32Array(a);e.HEAPU32=Ba=new Uint32Array(a);e.HEAPF32=Ca=new Float32Array(a);e.HEAPF64=Ea=new Float64Array(a);e.HEAP64=C=new BigInt64Array(a);e.HEAPU64=Da=new BigUint64Array(a)}q||(z=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),E());function Ta(){q?startWorker(e):K.Da()}var Ua=0,Va=null;
|
||||
function Wa(){Ua--;if(0==Ua&&Va){var a=Va;Va=null;a()}}function L(a){a="Aborted("+a+")";x(a);A=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ca(a);throw a;}var Xa;async function Ya(a){if(!ua)try{var b=await na(a);return new Uint8Array(b)}catch{}if(a==Xa&&ua)a=new Uint8Array(ua);else if(oa)a=oa(a);else throw"both async and sync fetching of the wasm failed";return a}
|
||||
async function Za(a,b){try{var c=await Ya(a);return await WebAssembly.instantiate(c,b)}catch(d){x(`failed to asynchronously prepare wasm: ${d}`),L(d)}}async function $a(a){var b=Xa;if(!ua&&"function"==typeof WebAssembly.instantiateStreaming&&!qa(b)&&!n)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){x(`wasm streaming compile failed: ${d}`),x("falling back to ArrayBuffer instantiation")}return Za(b,a)}
|
||||
function ab(){bb={L:cb,Aa:db,b:eb,$:fb,A:gb,pa:hb,X:ib,Z:jb,qa:kb,na:lb,ga:mb,ma:nb,J:ob,Y:pb,V:qb,oa:rb,W:sb,va:tb,E:ub,Q:vb,O:wb,D:xb,v:yb,r:zb,P:Ab,z:Bb,R:Cb,ja:Db,T:Eb,aa:Fb,M:Gb,F:Hb,ia:Oa,sa:Ib,t:Jb,Ca:Kb,w:Lb,o:Mb,m:Nb,c:Ob,Ba:Pb,n:Qb,j:Rb,u:Sb,p:Tb,f:Ub,s:Vb,l:Wb,e:Xb,k:Yb,h:Zb,g:$b,d:ac,da:bc,ea:cc,fa:dc,ba:ec,ca:fc,N:gc,xa:hc,ua:ic,i:jc,C:kc,G:lc,ta:mc,x:nc,ra:oc,U:pc,q:qc,y:rc,K:sc,S:tc,za:uc,ya:vc,ka:wc,la:xc,_:yc,B:zc,I:Ac,ha:Bc,H:Cc,a:z,wa:Dc};return{a:bb}}
|
||||
var Ec={840156:(a,b,c,d,f)=>{if("undefined"==typeof e||!e.Fb)return 1;a=M(Number(a>>>0));a.startsWith("./")&&(a=a.substring(2));a=e.Fb.get(a);if(!a)return 2;b=Number(b>>>0);c=Number(c>>>0);d=Number(d>>>0);if(b+c>a.byteLength)return 3;try{const g=a.subarray(b,b+c);switch(f){case 0:F().set(g,d>>>0);break;case 1:e.nc?e.nc(d,g):e.cc(d,g);break;default:return 4}return 0}catch{return 4}},840980:(a,b,c)=>{e.Pb(a,F().subarray(b>>>0,b+c>>>0))},841044:()=>e.oc(),841086:a=>{e.Ob(a)},841123:()=>{e.Wb()},841154:()=>
|
||||
{e.Xb()},841183:()=>{e.ac()},841208:a=>e.Vb(a),841241:a=>e.Zb(a),841273:(a,b,c)=>{e.Lb(Number(a),Number(b),Number(c),!0)},841336:(a,b,c)=>{e.Lb(Number(a),Number(b),Number(c))},841393:()=>"undefined"!==typeof wasmOffsetConverter,841450:a=>{e.kb("Abs",a,void 0)},841501:a=>{e.kb("Neg",a,void 0)},841552:a=>{e.kb("Floor",a,void 0)},841605:a=>{e.kb("Ceil",a,void 0)},841657:a=>{e.kb("Reciprocal",a,void 0)},841715:a=>{e.kb("Sqrt",a,void 0)},841767:a=>{e.kb("Exp",a,void 0)},841818:a=>{e.kb("Erf",a,void 0)},
|
||||
841869:a=>{e.kb("Sigmoid",a,void 0)},841924:(a,b,c)=>{e.kb("HardSigmoid",a,{alpha:b,beta:c})},842003:a=>{e.kb("Log",a,void 0)},842054:a=>{e.kb("Sin",a,void 0)},842105:a=>{e.kb("Cos",a,void 0)},842156:a=>{e.kb("Tan",a,void 0)},842207:a=>{e.kb("Asin",a,void 0)},842259:a=>{e.kb("Acos",a,void 0)},842311:a=>{e.kb("Atan",a,void 0)},842363:a=>{e.kb("Sinh",a,void 0)},842415:a=>{e.kb("Cosh",a,void 0)},842467:a=>{e.kb("Asinh",a,void 0)},842520:a=>{e.kb("Acosh",a,void 0)},842573:a=>{e.kb("Atanh",a,void 0)},
|
||||
842626:a=>{e.kb("Tanh",a,void 0)},842678:a=>{e.kb("Not",a,void 0)},842729:(a,b,c)=>{e.kb("Clip",a,{min:b,max:c})},842798:a=>{e.kb("Clip",a,void 0)},842850:(a,b)=>{e.kb("Elu",a,{alpha:b})},842908:a=>{e.kb("Gelu",a,void 0)},842960:a=>{e.kb("Relu",a,void 0)},843012:(a,b)=>{e.kb("LeakyRelu",a,{alpha:b})},843076:(a,b)=>{e.kb("ThresholdedRelu",a,{alpha:b})},843146:(a,b)=>{e.kb("Cast",a,{to:b})},843204:a=>{e.kb("Add",a,void 0)},843255:a=>{e.kb("Sub",a,void 0)},843306:a=>{e.kb("Mul",a,void 0)},843357:a=>
|
||||
{e.kb("Div",a,void 0)},843408:a=>{e.kb("Pow",a,void 0)},843459:a=>{e.kb("Equal",a,void 0)},843512:a=>{e.kb("Greater",a,void 0)},843567:a=>{e.kb("GreaterOrEqual",a,void 0)},843629:a=>{e.kb("Less",a,void 0)},843681:a=>{e.kb("LessOrEqual",a,void 0)},843740:(a,b,c,d,f)=>{e.kb("ReduceMean",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},843915:(a,b,c,d,f)=>{e.kb("ReduceMax",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>
|
||||
0,Number(f)>>>0)):[]})},844089:(a,b,c,d,f)=>{e.kb("ReduceMin",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},844263:(a,b,c,d,f)=>{e.kb("ReduceProd",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},844438:(a,b,c,d,f)=>{e.kb("ReduceSum",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},844612:(a,b,c,d,f)=>{e.kb("ReduceL1",a,{keepDims:!!b,
|
||||
noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},844785:(a,b,c,d,f)=>{e.kb("ReduceL2",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},844958:(a,b,c,d,f)=>{e.kb("ReduceLogSum",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},845135:(a,b,c,d,f)=>{e.kb("ReduceSumSquare",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>
|
||||
0,Number(f)>>>0)):[]})},845315:(a,b,c,d,f)=>{e.kb("ReduceLogSumExp",a,{keepDims:!!b,noopWithEmptyAxes:!!c,axes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},845495:a=>{e.kb("Where",a,void 0)},845548:(a,b,c)=>{e.kb("Transpose",a,{perm:b?Array.from(H().subarray(Number(b)>>>0,Number(c)>>>0)):[]})},845672:(a,b,c,d)=>{e.kb("DepthToSpace",a,{blocksize:b,mode:M(c),format:d?"NHWC":"NCHW"})},845805:(a,b,c,d)=>{e.kb("DepthToSpace",a,{blocksize:b,mode:M(c),format:d?"NHWC":"NCHW"})},845938:(a,
|
||||
b,c,d,f,g,h,l,m,p,r,u,w,y,ba)=>{e.kb("ConvTranspose",a,{format:m?"NHWC":"NCHW",autoPad:b,dilations:[c],group:d,kernelShape:[f],pads:[g,h],strides:[l],wIsConst:()=>!!D()[p>>>0],outputPadding:r?Array.from(H().subarray(Number(r)>>>0,Number(u)>>>0)):[],outputShape:w?Array.from(H().subarray(Number(w)>>>0,Number(y)>>>0)):[],activation:M(ba)})},846371:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("ConvTranspose",a,{format:l?"NHWC":"NCHW",autoPad:b,dilations:Array.from(H().subarray(Number(c)>>>0,(Number(c)>>>0)+2>>>
|
||||
0)),group:d,kernelShape:Array.from(H().subarray(Number(f)>>>0,(Number(f)>>>0)+2>>>0)),pads:Array.from(H().subarray(Number(g)>>>0,(Number(g)>>>0)+4>>>0)),strides:Array.from(H().subarray(Number(h)>>>0,(Number(h)>>>0)+2>>>0)),wIsConst:()=>!!D()[m>>>0],outputPadding:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],outputShape:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[],activation:M(y)})},847032:(a,b,c,d,f,g,h,l,m,p,r,u,w,y,ba)=>{e.kb("ConvTranspose",a,{format:m?"NHWC":"NCHW",
|
||||
autoPad:b,dilations:[c],group:d,kernelShape:[f],pads:[g,h],strides:[l],wIsConst:()=>!!D()[p>>>0],outputPadding:r?Array.from(H().subarray(Number(r)>>>0,Number(u)>>>0)):[],outputShape:w?Array.from(H().subarray(Number(w)>>>0,Number(y)>>>0)):[],activation:M(ba)})},847465:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("ConvTranspose",a,{format:l?"NHWC":"NCHW",autoPad:b,dilations:Array.from(H().subarray(Number(c)>>>0,(Number(c)>>>0)+2>>>0)),group:d,kernelShape:Array.from(H().subarray(Number(f)>>>0,(Number(f)>>>0)+
|
||||
2>>>0)),pads:Array.from(H().subarray(Number(g)>>>0,(Number(g)>>>0)+4>>>0)),strides:Array.from(H().subarray(Number(h)>>>0,(Number(h)>>>0)+2>>>0)),wIsConst:()=>!!D()[m>>>0],outputPadding:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],outputShape:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[],activation:M(y)})},848126:(a,b)=>{e.kb("GlobalAveragePool",a,{format:b?"NHWC":"NCHW"})},848217:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("AveragePool",a,{format:y?"NHWC":"NCHW",auto_pad:b,ceil_mode:c,
|
||||
count_include_pad:d,storage_order:f,dilations:g?Array.from(H().subarray(Number(g)>>>0,Number(h)>>>0)):[],kernel_shape:l?Array.from(H().subarray(Number(l)>>>0,Number(m)>>>0)):[],pads:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],strides:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[]})},848696:(a,b)=>{e.kb("GlobalAveragePool",a,{format:b?"NHWC":"NCHW"})},848787:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("AveragePool",a,{format:y?"NHWC":"NCHW",auto_pad:b,ceil_mode:c,count_include_pad:d,
|
||||
storage_order:f,dilations:g?Array.from(H().subarray(Number(g)>>>0,Number(h)>>>0)):[],kernel_shape:l?Array.from(H().subarray(Number(l)>>>0,Number(m)>>>0)):[],pads:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],strides:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[]})},849266:(a,b)=>{e.kb("GlobalMaxPool",a,{format:b?"NHWC":"NCHW"})},849353:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("MaxPool",a,{format:y?"NHWC":"NCHW",auto_pad:b,ceil_mode:c,count_include_pad:d,storage_order:f,dilations:g?
|
||||
Array.from(H().subarray(Number(g)>>>0,Number(h)>>>0)):[],kernel_shape:l?Array.from(H().subarray(Number(l)>>>0,Number(m)>>>0)):[],pads:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],strides:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[]})},849828:(a,b)=>{e.kb("GlobalMaxPool",a,{format:b?"NHWC":"NCHW"})},849915:(a,b,c,d,f,g,h,l,m,p,r,u,w,y)=>{e.kb("MaxPool",a,{format:y?"NHWC":"NCHW",auto_pad:b,ceil_mode:c,count_include_pad:d,storage_order:f,dilations:g?Array.from(H().subarray(Number(g)>>>
|
||||
0,Number(h)>>>0)):[],kernel_shape:l?Array.from(H().subarray(Number(l)>>>0,Number(m)>>>0)):[],pads:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],strides:u?Array.from(H().subarray(Number(u)>>>0,Number(w)>>>0)):[]})},850390:(a,b,c,d,f)=>{e.kb("Gemm",a,{alpha:b,beta:c,transA:d,transB:f})},850494:a=>{e.kb("MatMul",a,void 0)},850548:(a,b,c,d)=>{e.kb("ArgMax",a,{keepDims:!!b,selectLastIndex:!!c,axis:d})},850656:(a,b,c,d)=>{e.kb("ArgMin",a,{keepDims:!!b,selectLastIndex:!!c,axis:d})},850764:(a,
|
||||
b)=>{e.kb("Softmax",a,{axis:b})},850827:(a,b)=>{e.kb("Concat",a,{axis:b})},850887:(a,b,c,d,f)=>{e.kb("Split",a,{axis:b,numOutputs:c,splitSizes:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},851043:a=>{e.kb("Expand",a,void 0)},851097:(a,b)=>{e.kb("Gather",a,{axis:Number(b)})},851168:(a,b)=>{e.kb("GatherElements",a,{axis:Number(b)})},851247:(a,b)=>{e.kb("GatherND",a,{batch_dims:Number(b)})},851326:(a,b,c,d,f,g,h,l,m,p,r)=>{e.kb("Resize",a,{antialias:b,axes:c?Array.from(H().subarray(Number(c)>>>
|
||||
0,Number(d)>>>0)):[],coordinateTransformMode:M(f),cubicCoeffA:g,excludeOutside:h,extrapolationValue:l,keepAspectRatioPolicy:M(m),mode:M(p),nearestMode:M(r)})},851688:(a,b,c,d,f,g,h)=>{e.kb("Slice",a,{starts:b?Array.from(H().subarray(Number(b)>>>0,Number(c)>>>0)):[],ends:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[],axes:g?Array.from(H().subarray(Number(g)>>>0,Number(h)>>>0)):[]})},851952:a=>{e.kb("Tile",a,void 0)},852004:(a,b,c)=>{e.kb("InstanceNormalization",a,{epsilon:b,format:c?"NHWC":
|
||||
"NCHW"})},852118:(a,b,c)=>{e.kb("InstanceNormalization",a,{epsilon:b,format:c?"NHWC":"NCHW"})},852232:a=>{e.kb("Range",a,void 0)},852285:(a,b)=>{e.kb("Einsum",a,{equation:M(b)})},852366:(a,b,c,d,f)=>{e.kb("Pad",a,{mode:b,value:c,pads:d?Array.from(H().subarray(Number(d)>>>0,Number(f)>>>0)):[]})},852509:(a,b,c,d,f,g)=>{e.kb("BatchNormalization",a,{epsilon:b,momentum:c,spatial:!!f,trainingMode:!!d,format:g?"NHWC":"NCHW"})},852678:(a,b,c,d,f,g)=>{e.kb("BatchNormalization",a,{epsilon:b,momentum:c,spatial:!!f,
|
||||
trainingMode:!!d,format:g?"NHWC":"NCHW"})},852847:(a,b,c)=>{e.kb("CumSum",a,{exclusive:Number(b),reverse:Number(c)})},852944:(a,b,c)=>{e.kb("DequantizeLinear",a,{axis:b,blockSize:c})},853034:(a,b,c,d,f)=>{e.kb("GridSample",a,{align_corners:b,mode:M(c),padding_mode:M(d),format:f?"NHWC":"NCHW"})},853204:(a,b,c,d,f)=>{e.kb("GridSample",a,{align_corners:b,mode:M(c),padding_mode:M(d),format:f?"NHWC":"NCHW"})},853374:(a,b)=>{e.kb("ScatterND",a,{reduction:M(b)})},853459:(a,b,c,d,f,g,h,l,m)=>{e.kb("Attention",
|
||||
a,{numHeads:b,isUnidirectional:c,maskFilterValue:d,scale:f,doRotary:g,qkvHiddenSizes:h?Array.from(H().subarray(Number(l)>>>0,Number(l)+h>>>0)):[],pastPresentShareBuffer:!!m})},853731:a=>{e.kb("BiasAdd",a,void 0)},853786:a=>{e.kb("BiasSplitGelu",a,void 0)},853847:a=>{e.kb("FastGelu",a,void 0)},853903:(a,b,c,d,f,g,h,l,m,p,r,u,w,y,ba,Wd)=>{e.kb("Conv",a,{format:u?"NHWC":"NCHW",auto_pad:b,dilations:c?Array.from(H().subarray(Number(c)>>>0,Number(d)>>>0)):[],group:f,kernel_shape:g?Array.from(H().subarray(Number(g)>>>
|
||||
0,Number(h)>>>0)):[],pads:l?Array.from(H().subarray(Number(l)>>>0,Number(m)>>>0)):[],strides:p?Array.from(H().subarray(Number(p)>>>0,Number(r)>>>0)):[],w_is_const:()=>!!D()[Number(w)>>>0],activation:M(y),activation_params:ba?Array.from(Ga().subarray(Number(ba)>>>0,Number(Wd)>>>0)):[]})},854487:a=>{e.kb("Gelu",a,void 0)},854539:(a,b,c,d,f,g,h,l,m)=>{e.kb("GroupQueryAttention",a,{numHeads:b,kvNumHeads:c,scale:d,softcap:f,doRotary:g,rotaryInterleaved:h,smoothSoftmax:l,localWindowSize:m})},854756:(a,
|
||||
b,c,d)=>{e.kb("LayerNormalization",a,{axis:b,epsilon:c,simplified:!!d})},854867:(a,b,c,d)=>{e.kb("LayerNormalization",a,{axis:b,epsilon:c,simplified:!!d})},854978:(a,b,c,d,f,g)=>{e.kb("MatMulNBits",a,{k:b,n:c,accuracyLevel:d,bits:f,blockSize:g})},855105:(a,b,c,d,f,g)=>{e.kb("MultiHeadAttention",a,{numHeads:b,isUnidirectional:c,maskFilterValue:d,scale:f,doRotary:g})},855264:(a,b)=>{e.kb("QuickGelu",a,{alpha:b})},855328:(a,b,c,d,f)=>{e.kb("RotaryEmbedding",a,{interleaved:!!b,numHeads:c,rotaryEmbeddingDim:d,
|
||||
scale:f})},855467:(a,b,c)=>{e.kb("SkipLayerNormalization",a,{epsilon:b,simplified:!!c})},855569:(a,b,c)=>{e.kb("SkipLayerNormalization",a,{epsilon:b,simplified:!!c})},855671:(a,b,c,d)=>{e.kb("GatherBlockQuantized",a,{gatherAxis:b,quantizeAxis:c,blockSize:d})},855792:a=>{e.$b(a)},855826:(a,b)=>e.bc(Number(a),Number(b),e.Gb.ec,e.Gb.errors)};function db(a,b,c){return Fc(async()=>{await e.Yb(Number(a),Number(b),Number(c))})}function cb(){return"undefined"!==typeof wasmOffsetConverter}
|
||||
class Gc{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
|
||||
var Hc=a=>{a.terminate();a.onmessage=()=>{}},Ic=[],Mc=a=>{0==N.length&&(Jc(),Kc(N[0]));var b=N.pop();if(!b)return 6;Lc.push(b);O[a.Bb]=b;b.Bb=a.Bb;var c={Cb:"run",hc:a.fc,Ib:a.Ib,Bb:a.Bb};n&&b.unref();b.postMessage(c,a.Nb);return 0},P=0,Q=(a,b,...c)=>{for(var d=2*c.length,f=Nc(),g=Oc(8*d),h=g>>>3,l=0;l<c.length;l++){var m=c[l];"bigint"==typeof m?(C[h+2*l]=1n,C[h+2*l+1]=m):(C[h+2*l]=0n,J()[h+2*l+1>>>0]=m)}a=Pc(a,0,d,g,b);Qc(f);return a};
|
||||
function Dc(a){if(q)return Q(0,1,a);wa=a;if(!(0<P)){for(var b of Lc)Hc(b);for(b of N)Hc(b);N=[];Lc=[];O={};A=!0}ma(a,new Gc(a))}function Rc(a){if(q)return Q(1,0,a);yc(a)}var yc=a=>{wa=a;if(q)throw Rc(a),"unwind";Dc(a)},N=[],Lc=[],Sc=[],O={};function Tc(){for(var a=e.numThreads-1;a--;)Jc();Ic.unshift(()=>{Ua++;Uc(()=>Wa())})}var Wc=a=>{var b=a.Bb;delete O[b];N.push(a);Lc.splice(Lc.indexOf(a),1);a.Bb=0;Vc(b)};function Na(){Sc.forEach(a=>a())}
|
||||
var Kc=a=>new Promise(b=>{a.onmessage=g=>{g=g.data;var h=g.Cb;if(g.Hb&&g.Hb!=Ka()){var l=O[g.Hb];l?l.postMessage(g,g.Nb):x(`Internal error! Worker sent a message "${h}" to target pthread ${g.Hb}, but that thread no longer exists!`)}else if("checkMailbox"===h)Ra();else if("spawnThread"===h)Mc(g);else if("cleanupThread"===h)Wc(O[g.ic]);else if("loaded"===h)a.loaded=!0,n&&!a.Bb&&a.unref(),b(a);else if("alert"===h)alert(`Thread ${g.jc}: ${g.text}`);else if("setimmediate"===g.target)a.postMessage(g);else if("callHandler"===
|
||||
h)e[g.Rb](...g.args);else h&&x(`worker sent an unknown command ${h}`)};a.onerror=g=>{x(`${"worker sent an error!"} ${g.filename}:${g.lineno}: ${g.message}`);throw g;};n&&(a.on("message",g=>a.onmessage({data:g})),a.on("error",g=>a.onerror(g)));var c=[],d=[],f;for(f of d)e.propertyIsEnumerable(f)&&c.push(f);a.postMessage({Cb:"load",Sb:c,lc:z,mc:va})});function Uc(a){q?a():Promise.all(N.map(Kc)).then(a)}
|
||||
function Jc(){var a=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});N.push(a)}var La=a=>{E();var b=I()[a+52>>>2>>>0];a=I()[a+56>>>2>>>0];Xc(b,b-a);Qc(b)},Qa=(a,b)=>{P=0;a=Yc(a,b);0<P?wa=a:Zc(a)};class $c{constructor(a){this.Jb=a-24}}var ad=0,bd=0;function eb(a,b,c){a>>>=0;var d=new $c(a);b>>>=0;c>>>=0;I()[d.Jb+16>>>2>>>0]=0;I()[d.Jb+4>>>2>>>0]=b;I()[d.Jb+8>>>2>>>0]=c;ad=a;bd++;throw ad;}
|
||||
function cd(a,b,c,d){return q?Q(2,1,a,b,c,d):fb(a,b,c,d)}function fb(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;if("undefined"==typeof SharedArrayBuffer)return 6;var f=[];if(q&&0===f.length)return cd(a,b,c,d);a={fc:c,Bb:a,Ib:d,Nb:f};return q?(a.Cb="spawnThread",postMessage(a,f),0):Mc(a)}
|
||||
var dd="undefined"!=typeof TextDecoder?new TextDecoder:void 0,ed=(a,b=0,c=NaN)=>{b>>>=0;var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.buffer&&dd)return dd.decode(a.buffer instanceof ArrayBuffer?a.subarray(b,c):a.slice(b,c));for(d="";b<c;){var f=a[b++];if(f&128){var g=a[b++]&63;if(192==(f&224))d+=String.fromCharCode((f&31)<<6|g);else{var h=a[b++]&63;f=224==(f&240)?(f&15)<<12|g<<6|h:(f&7)<<18|g<<12|h<<6|a[b++]&63;65536>f?d+=String.fromCharCode(f):(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|
|
||||
f&1023))}}else d+=String.fromCharCode(f)}return d},M=(a,b)=>(a>>>=0)?ed(F(),a,b):"";function gb(a,b,c){return q?Q(3,1,a,b,c):0}function hb(a,b){if(q)return Q(4,1,a,b)}
|
||||
var fd=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);127>=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b},gd=(a,b,c)=>{var d=F();b>>>=0;if(0<c){var f=b;c=b+c-1;for(var g=0;g<a.length;++g){var h=a.charCodeAt(g);if(55296<=h&&57343>=h){var l=a.charCodeAt(++g);h=65536+((h&1023)<<10)|l&1023}if(127>=h){if(b>=c)break;d[b++>>>0]=h}else{if(2047>=h){if(b+1>=c)break;d[b++>>>0]=192|h>>6}else{if(65535>=h){if(b+2>=c)break;d[b++>>>0]=224|h>>12}else{if(b+3>=c)break;d[b++>>>0]=240|h>>18;
|
||||
d[b++>>>0]=128|h>>12&63}d[b++>>>0]=128|h>>6&63}d[b++>>>0]=128|h&63}}d[b>>>0]=0;a=b-f}else a=0;return a};function ib(a,b){if(q)return Q(5,1,a,b)}function jb(a,b,c){if(q)return Q(6,1,a,b,c)}function kb(a,b,c){return q?Q(7,1,a,b,c):0}function lb(a,b){if(q)return Q(8,1,a,b)}function mb(a,b,c){if(q)return Q(9,1,a,b,c)}function nb(a,b,c,d){if(q)return Q(10,1,a,b,c,d)}function ob(a,b,c,d){if(q)return Q(11,1,a,b,c,d)}function pb(a,b,c,d){if(q)return Q(12,1,a,b,c,d)}function qb(a){if(q)return Q(13,1,a)}
|
||||
function rb(a,b){if(q)return Q(14,1,a,b)}function sb(a,b,c){if(q)return Q(15,1,a,b,c)}var tb=()=>L(""),hd,R=a=>{for(var b="";F()[a>>>0];)b+=hd[F()[a++>>>0]];return b},jd={},kd={},ld={},S;function md(a,b,c={}){var d=b.name;if(!a)throw new S(`type "${d}" must have a positive integer typeid pointer`);if(kd.hasOwnProperty(a)){if(c.Tb)return;throw new S(`Cannot register type '${d}' twice`);}kd[a]=b;delete ld[a];jd.hasOwnProperty(a)&&(b=jd[a],delete jd[a],b.forEach(f=>f()))}
|
||||
function T(a,b,c={}){return md(a,b,c)}var nd=(a,b,c)=>{switch(b){case 1:return c?d=>D()[d>>>0]:d=>F()[d>>>0];case 2:return c?d=>G()[d>>>1>>>0]:d=>Fa()[d>>>1>>>0];case 4:return c?d=>H()[d>>>2>>>0]:d=>I()[d>>>2>>>0];case 8:return c?d=>C[d>>>3]:d=>Da[d>>>3];default:throw new TypeError(`invalid integer width (${b}): ${a}`);}};
|
||||
function ub(a,b,c){a>>>=0;c>>>=0;b=R(b>>>0);T(a,{name:b,fromWireType:d=>d,toWireType:function(d,f){if("bigint"!=typeof f&&"number"!=typeof f)throw null===f?f="null":(d=typeof f,f="object"===d||"array"===d||"function"===d?f.toString():""+f),new TypeError(`Cannot convert "${f}" to ${this.name}`);"number"==typeof f&&(f=BigInt(f));return f},Db:U,readValueFromPointer:nd(b,c,-1==b.indexOf("u")),Eb:null})}var U=8;
|
||||
function vb(a,b,c,d){a>>>=0;b=R(b>>>0);T(a,{name:b,fromWireType:function(f){return!!f},toWireType:function(f,g){return g?c:d},Db:U,readValueFromPointer:function(f){return this.fromWireType(F()[f>>>0])},Eb:null})}var od=[],V=[];function Ob(a){a>>>=0;9<a&&0===--V[a+1]&&(V[a]=void 0,od.push(a))}
|
||||
var W=a=>{if(!a)throw new S("Cannot use deleted val. handle = "+a);return V[a]},X=a=>{switch(a){case void 0:return 2;case null:return 4;case !0:return 6;case !1:return 8;default:const b=od.pop()||V.length;V[b]=a;V[b+1]=1;return b}};function pd(a){return this.fromWireType(I()[a>>>2>>>0])}var qd={name:"emscripten::val",fromWireType:a=>{var b=W(a);Ob(a);return b},toWireType:(a,b)=>X(b),Db:U,readValueFromPointer:pd,Eb:null};function wb(a){return T(a>>>0,qd)}
|
||||
var rd=(a,b)=>{switch(b){case 4:return function(c){return this.fromWireType(Ga()[c>>>2>>>0])};case 8:return function(c){return this.fromWireType(J()[c>>>3>>>0])};default:throw new TypeError(`invalid float width (${b}): ${a}`);}};function xb(a,b,c){a>>>=0;c>>>=0;b=R(b>>>0);T(a,{name:b,fromWireType:d=>d,toWireType:(d,f)=>f,Db:U,readValueFromPointer:rd(b,c),Eb:null})}
|
||||
function yb(a,b,c,d,f){a>>>=0;c>>>=0;b=R(b>>>0);-1===f&&(f=4294967295);f=l=>l;if(0===d){var g=32-8*c;f=l=>l<<g>>>g}var h=b.includes("unsigned")?function(l,m){return m>>>0}:function(l,m){return m};T(a,{name:b,fromWireType:f,toWireType:h,Db:U,readValueFromPointer:nd(b,c,0!==d),Eb:null})}
|
||||
function zb(a,b,c){function d(g){var h=I()[g>>>2>>>0];g=I()[g+4>>>2>>>0];return new f(D().buffer,g,h)}a>>>=0;var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][b];c=R(c>>>0);T(a,{name:c,fromWireType:d,Db:U,readValueFromPointer:d},{Tb:!0})}
|
||||
function Ab(a,b){a>>>=0;b=R(b>>>0);T(a,{name:b,fromWireType:function(c){for(var d=I()[c>>>2>>>0],f=c+4,g,h=f,l=0;l<=d;++l){var m=f+l;if(l==d||0==F()[m>>>0])h=M(h,m-h),void 0===g?g=h:(g+=String.fromCharCode(0),g+=h),h=m+1}Y(c);return g},toWireType:function(c,d){d instanceof ArrayBuffer&&(d=new Uint8Array(d));var f="string"==typeof d;if(!(f||d instanceof Uint8Array||d instanceof Uint8ClampedArray||d instanceof Int8Array))throw new S("Cannot pass non-string to std::string");var g=f?fd(d):d.length;var h=
|
||||
sd(4+g+1),l=h+4;I()[h>>>2>>>0]=g;if(f)gd(d,l,g+1);else if(f)for(f=0;f<g;++f){var m=d.charCodeAt(f);if(255<m)throw Y(h),new S("String has UTF-16 code units that do not fit in 8 bits");F()[l+f>>>0]=m}else for(f=0;f<g;++f)F()[l+f>>>0]=d[f];null!==c&&c.push(Y,h);return h},Db:U,readValueFromPointer:pd,Eb(c){Y(c)}})}
|
||||
var td="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0,ud=(a,b)=>{var c=a>>1;for(var d=c+b/2;!(c>=d)&&Fa()[c>>>0];)++c;c<<=1;if(32<c-a&&td)return td.decode(F().slice(a,c));c="";for(d=0;!(d>=b/2);++d){var f=G()[a+2*d>>>1>>>0];if(0==f)break;c+=String.fromCharCode(f)}return c},vd=(a,b,c)=>{c??=2147483647;if(2>c)return 0;c-=2;var d=b;c=c<2*a.length?c/2:a.length;for(var f=0;f<c;++f){var g=a.charCodeAt(f);G()[b>>>1>>>0]=g;b+=2}G()[b>>>1>>>0]=0;return b-d},wd=a=>2*a.length,xd=(a,b)=>{for(var c=
|
||||
0,d="";!(c>=b/4);){var f=H()[a+4*c>>>2>>>0];if(0==f)break;++c;65536<=f?(f-=65536,d+=String.fromCharCode(55296|f>>10,56320|f&1023)):d+=String.fromCharCode(f)}return d},yd=(a,b,c)=>{b>>>=0;c??=2147483647;if(4>c)return 0;var d=b;c=d+c-4;for(var f=0;f<a.length;++f){var g=a.charCodeAt(f);if(55296<=g&&57343>=g){var h=a.charCodeAt(++f);g=65536+((g&1023)<<10)|h&1023}H()[b>>>2>>>0]=g;b+=4;if(b+4>c)break}H()[b>>>2>>>0]=0;return b-d},zd=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);55296<=d&&57343>=
|
||||
d&&++c;b+=4}return b};
|
||||
function Bb(a,b,c){a>>>=0;b>>>=0;c>>>=0;c=R(c);if(2===b){var d=ud;var f=vd;var g=wd;var h=l=>Fa()[l>>>1>>>0]}else 4===b&&(d=xd,f=yd,g=zd,h=l=>I()[l>>>2>>>0]);T(a,{name:c,fromWireType:l=>{for(var m=I()[l>>>2>>>0],p,r=l+4,u=0;u<=m;++u){var w=l+4+u*b;if(u==m||0==h(w))r=d(r,w-r),void 0===p?p=r:(p+=String.fromCharCode(0),p+=r),r=w+b}Y(l);return p},toWireType:(l,m)=>{if("string"!=typeof m)throw new S(`Cannot pass non-string to C++ string type ${c}`);var p=g(m),r=sd(4+p+b);I()[r>>>2>>>0]=p/b;f(m,r+4,p+b);
|
||||
null!==l&&l.push(Y,r);return r},Db:U,readValueFromPointer:pd,Eb(l){Y(l)}})}function Cb(a,b){a>>>=0;b=R(b>>>0);T(a,{Ub:!0,name:b,Db:0,fromWireType:()=>{},toWireType:()=>{}})}function Db(a){Ma(a>>>0,!k,1,!ea,131072,!1);Na()}var Ad=a=>{if(!A)try{if(a(),!(0<P))try{q?Zc(wa):yc(wa)}catch(b){b instanceof Gc||"unwind"==b||ma(1,b)}}catch(b){b instanceof Gc||"unwind"==b||ma(1,b)}};
|
||||
function Oa(a){a>>>=0;"function"===typeof Atomics.kc&&(Atomics.kc(H(),a>>>2,a).value.then(Ra),a+=128,Atomics.store(H(),a>>>2,1))}var Ra=()=>{var a=Ka();a&&(Oa(a),Ad(Bd))};function Eb(a,b){a>>>=0;a==b>>>0?setTimeout(Ra):q?postMessage({Hb:a,Cb:"checkMailbox"}):(a=O[a])&&a.postMessage({Cb:"checkMailbox"})}var Cd=[];function Fb(a,b,c,d,f){b>>>=0;d/=2;Cd.length=d;c=f>>>0>>>3;for(f=0;f<d;f++)Cd[f]=C[c+2*f]?C[c+2*f+1]:J()[c+2*f+1>>>0];return(b?Ec[b]:Dd[a])(...Cd)}var Gb=()=>{P=0};
|
||||
function Hb(a){a>>>=0;q?postMessage({Cb:"cleanupThread",ic:a}):Wc(O[a])}function Ib(a){n&&O[a>>>0].ref()}var Fd=(a,b)=>{var c=kd[a];if(void 0===c)throw a=Ed(a),c=R(a),Y(a),new S(`${b} has unknown type ${c}`);return c},Gd=(a,b,c)=>{var d=[];a=a.toWireType(d,c);d.length&&(I()[b>>>2>>>0]=X(d));return a};function Jb(a,b,c){b>>>=0;c>>>=0;a=W(a>>>0);b=Fd(b,"emval::as");return Gd(b,c,a)}function Kb(a,b){b>>>=0;a=W(a>>>0);b=Fd(b,"emval::as");return b.toWireType(null,a)}var Hd=a=>{try{a()}catch(b){L(b)}};
|
||||
function Id(){var a=K,b={};for(let [c,d]of Object.entries(a))b[c]="function"==typeof d?(...f)=>{Jd.push(c);try{return d(...f)}finally{A||(Jd.pop(),t&&1===Z&&0===Jd.length&&(Z=0,P+=1,Hd(Kd),"undefined"!=typeof Fibers&&Fibers.sc()))}}:d;return b}var Z=0,t=null,Ld=0,Jd=[],Md={},Nd={},Od=0,Pd=null,Qd=[];function ia(){return new Promise((a,b)=>{Pd={resolve:a,reject:b}})}
|
||||
function Rd(){var a=sd(65548),b=a+12;I()[a>>>2>>>0]=b;I()[a+4>>>2>>>0]=b+65536;b=Jd[0];var c=Md[b];void 0===c&&(c=Od++,Md[b]=c,Nd[c]=b);b=c;H()[a+8>>>2>>>0]=b;return a}function Sd(){var a=H()[t+8>>>2>>>0];a=K[Nd[a]];--P;return a()}
|
||||
function Td(a){if(!A){if(0===Z){var b=!1,c=!1;a((d=0)=>{if(!A&&(Ld=d,b=!0,c)){Z=2;Hd(()=>Ud(t));"undefined"!=typeof MainLoop&&MainLoop.Qb&&MainLoop.resume();d=!1;try{var f=Sd()}catch(l){f=l,d=!0}var g=!1;if(!t){var h=Pd;h&&(Pd=null,(d?h.reject:h.resolve)(f),g=!0)}if(d&&!g)throw f;}});c=!0;b||(Z=1,t=Rd(),"undefined"!=typeof MainLoop&&MainLoop.Qb&&MainLoop.pause(),Hd(()=>Vd(t)))}else 2===Z?(Z=0,Hd(Xd),Y(t),t=null,Qd.forEach(Ad)):L(`invalid state: ${Z}`);return Ld}}
|
||||
function Fc(a){return Td(b=>{a().then(b)})}function Lb(a){a>>>=0;return Fc(async()=>{var b=await W(a);return X(b)})}var Yd=[];function Mb(a,b,c,d){c>>>=0;d>>>=0;a=Yd[a>>>0];b=W(b>>>0);return a(null,b,c,d)}var Zd={},$d=a=>{var b=Zd[a];return void 0===b?R(a):b};function Nb(a,b,c,d,f){c>>>=0;d>>>=0;f>>>=0;a=Yd[a>>>0];b=W(b>>>0);c=$d(c);return a(b,b[c],d,f)}function Pb(a,b){b>>>=0;a=W(a>>>0);b=W(b);return a==b}var ae=()=>"object"==typeof globalThis?globalThis:Function("return this")();
|
||||
function Qb(a){a>>>=0;if(0===a)return X(ae());a=$d(a);return X(ae()[a])}var be=a=>{var b=Yd.length;Yd.push(a);return b},ce=(a,b)=>{for(var c=Array(a),d=0;d<a;++d)c[d]=Fd(I()[b+4*d>>>2>>>0],"parameter "+d);return c},de=(a,b)=>Object.defineProperty(b,"name",{value:a});
|
||||
function ee(a){var b=Function;if(!(b instanceof Function))throw new TypeError(`new_ called with constructor type ${typeof b} which is not a function`);var c=de(b.name||"unknownFunctionName",function(){});c.prototype=b.prototype;c=new c;a=b.apply(c,a);return a instanceof Object?a:c}
|
||||
function Rb(a,b,c){b=ce(a,b>>>0);var d=b.shift();a--;var f="return function (obj, func, destructorsRef, args) {\n",g=0,h=[];0===c&&h.push("obj");for(var l=["retType"],m=[d],p=0;p<a;++p)h.push("arg"+p),l.push("argType"+p),m.push(b[p]),f+=` var arg${p} = argType${p}.readValueFromPointer(args${g?"+"+g:""});\n`,g+=b[p].Db;f+=` var rv = ${1===c?"new func":"func.call"}(${h.join(", ")});\n`;d.Ub||(l.push("emval_returnValue"),m.push(Gd),f+=" return emval_returnValue(retType, destructorsRef, rv);\n");l.push(f+
|
||||
"};\n");a=ee(l)(...m);c=`methodCaller<(${b.map(r=>r.name).join(", ")}) => ${d.name}>`;return be(de(c,a))}function Sb(a){a=$d(a>>>0);return X(e[a])}function Tb(a,b){b>>>=0;a=W(a>>>0);b=W(b);return X(a[b])}function Ub(a){a>>>=0;9<a&&(V[a+1]+=1)}function Vb(){return X([])}function Wb(a){a=W(a>>>0);for(var b=Array(a.length),c=0;c<a.length;c++)b[c]=a[c];return X(b)}function Xb(a){return X($d(a>>>0))}function Yb(){return X({})}
|
||||
function Zb(a){a>>>=0;for(var b=W(a);b.length;){var c=b.pop();b.pop()(c)}Ob(a)}function $b(a,b,c){b>>>=0;c>>>=0;a=W(a>>>0);b=W(b);c=W(c);a[b]=c}function ac(a,b){b>>>=0;a=Fd(a>>>0,"_emval_take_value");a=a.readValueFromPointer(b);return X(a)}
|
||||
function bc(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);H()[b>>>2>>>0]=a.getUTCSeconds();H()[b+4>>>2>>>0]=a.getUTCMinutes();H()[b+8>>>2>>>0]=a.getUTCHours();H()[b+12>>>2>>>0]=a.getUTCDate();H()[b+16>>>2>>>0]=a.getUTCMonth();H()[b+20>>>2>>>0]=a.getUTCFullYear()-1900;H()[b+24>>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;H()[b+28>>>2>>>0]=a}
|
||||
var fe=a=>0===a%4&&(0!==a%100||0===a%400),ge=[0,31,60,91,121,152,182,213,244,274,305,335],he=[0,31,59,90,120,151,181,212,243,273,304,334];
|
||||
function cc(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);H()[b>>>2>>>0]=a.getSeconds();H()[b+4>>>2>>>0]=a.getMinutes();H()[b+8>>>2>>>0]=a.getHours();H()[b+12>>>2>>>0]=a.getDate();H()[b+16>>>2>>>0]=a.getMonth();H()[b+20>>>2>>>0]=a.getFullYear()-1900;H()[b+24>>>2>>>0]=a.getDay();var c=(fe(a.getFullYear())?ge:he)[a.getMonth()]+a.getDate()-1|0;H()[b+28>>>2>>>0]=c;H()[b+36>>>2>>>0]=-(60*a.getTimezoneOffset());c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
|
||||
var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();a=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0;H()[b+32>>>2>>>0]=a}
|
||||
function dc(a){a>>>=0;var b=new Date(H()[a+20>>>2>>>0]+1900,H()[a+16>>>2>>>0],H()[a+12>>>2>>>0],H()[a+8>>>2>>>0],H()[a+4>>>2>>>0],H()[a>>>2>>>0],0),c=H()[a+32>>>2>>>0],d=b.getTimezoneOffset(),f=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),g=(new Date(b.getFullYear(),0,1)).getTimezoneOffset(),h=Math.min(g,f);0>c?H()[a+32>>>2>>>0]=Number(f!=g&&h==d):0<c!=(h==d)&&(f=Math.max(g,f),b.setTime(b.getTime()+6E4*((0<c?h:f)-d)));H()[a+24>>>2>>>0]=b.getDay();c=(fe(b.getFullYear())?ge:he)[b.getMonth()]+
|
||||
b.getDate()-1|0;H()[a+28>>>2>>>0]=c;H()[a>>>2>>>0]=b.getSeconds();H()[a+4>>>2>>>0]=b.getMinutes();H()[a+8>>>2>>>0]=b.getHours();H()[a+12>>>2>>>0]=b.getDate();H()[a+16>>>2>>>0]=b.getMonth();H()[a+20>>>2>>>0]=b.getYear();a=b.getTime();return BigInt(isNaN(a)?-1:a/1E3)}function ec(a,b,c,d,f,g,h){return q?Q(16,1,a,b,c,d,f,g,h):-52}function fc(a,b,c,d,f,g){if(q)return Q(17,1,a,b,c,d,f,g)}var ie={},qc=()=>performance.timeOrigin+performance.now();
|
||||
function gc(a,b){if(q)return Q(18,1,a,b);ie[a]&&(clearTimeout(ie[a].id),delete ie[a]);if(!b)return 0;var c=setTimeout(()=>{delete ie[a];Ad(()=>je(a,performance.timeOrigin+performance.now()))},b);ie[a]={id:c,rc:b};return 0}
|
||||
function hc(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;var f=(new Date).getFullYear(),g=(new Date(f,0,1)).getTimezoneOffset();f=(new Date(f,6,1)).getTimezoneOffset();var h=Math.max(g,f);I()[a>>>2>>>0]=60*h;H()[b>>>2>>>0]=Number(g!=f);b=l=>{var m=Math.abs(l);return`UTC${0<=l?"-":"+"}${String(Math.floor(m/60)).padStart(2,"0")}${String(m%60).padStart(2,"0")}`};a=b(g);b=b(f);f<g?(gd(a,c,17),gd(b,d,17)):(gd(a,d,17),gd(b,c,17))}var mc=()=>Date.now(),ke=1;
|
||||
function ic(a,b,c){if(!(0<=a&&3>=a))return 28;if(0===a)a=Date.now();else if(ke)a=performance.timeOrigin+performance.now();else return 52;C[c>>>0>>>3]=BigInt(Math.round(1E6*a));return 0}var le=[],me=(a,b)=>{le.length=0;for(var c;c=F()[a++>>>0];){var d=105!=c;d&=112!=c;b+=d&&b%8?4:0;le.push(112==c?I()[b>>>2>>>0]:106==c?C[b>>>3]:105==c?H()[b>>>2>>>0]:J()[b>>>3>>>0]);b+=d?8:4}return le};function jc(a,b,c){a>>>=0;b=me(b>>>0,c>>>0);return Ec[a](...b)}
|
||||
function kc(a,b,c){a>>>=0;b=me(b>>>0,c>>>0);return Ec[a](...b)}var lc=()=>{};function nc(a,b){return x(M(a>>>0,b>>>0))}var oc=()=>{P+=1;throw"unwind";};function pc(){return 4294901760}var rc=()=>n?require("os").cpus().length:navigator.hardwareConcurrency;function sc(){L("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER");return 0}
|
||||
function tc(a){a>>>=0;var b=F().length;if(a<=b||4294901760<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(4294901760,65536*Math.ceil(Math.max(a,d)/65536))-z.buffer.byteLength+65535)/65536|0;try{z.grow(d);E();var f=1;break a}catch(g){}f=void 0}if(f)return!0}return!1}var ne=()=>{L("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER");return 0},oe={},pe=a=>{a.forEach(b=>{var c=ne();c&&(oe[c]=b)})};
|
||||
function uc(){var a=Error().stack.toString().split("\n");"Error"==a[0]&&a.shift();pe(a);oe.Mb=ne();oe.dc=a;return oe.Mb}function vc(a,b,c){a>>>=0;b>>>=0;if(oe.Mb==a)var d=oe.dc;else d=Error().stack.toString().split("\n"),"Error"==d[0]&&d.shift(),pe(d);for(var f=3;d[f]&&ne()!=a;)++f;for(a=0;a<c&&d[a+f];++a)H()[b+4*a>>>2>>>0]=ne();return a}
|
||||
var qe={},se=()=>{if(!re){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:la||"./this.program"},b;for(b in qe)void 0===qe[b]?delete a[b]:a[b]=qe[b];var c=[];for(b in a)c.push(`${b}=${a[b]}`);re=c}return re},re;
|
||||
function wc(a,b){if(q)return Q(19,1,a,b);a>>>=0;b>>>=0;var c=0;se().forEach((d,f)=>{var g=b+c;f=I()[a+4*f>>>2>>>0]=g;for(g=0;g<d.length;++g)D()[f++>>>0]=d.charCodeAt(g);D()[f>>>0]=0;c+=d.length+1});return 0}function xc(a,b){if(q)return Q(20,1,a,b);a>>>=0;b>>>=0;var c=se();I()[a>>>2>>>0]=c.length;var d=0;c.forEach(f=>d+=f.length+1);I()[b>>>2>>>0]=d;return 0}function zc(a){return q?Q(21,1,a):52}function Ac(a,b,c,d){return q?Q(22,1,a,b,c,d):52}function Bc(a,b,c,d){return q?Q(23,1,a,b,c,d):70}
|
||||
var te=[null,[],[]];function Cc(a,b,c,d){if(q)return Q(24,1,a,b,c,d);b>>>=0;c>>>=0;d>>>=0;for(var f=0,g=0;g<c;g++){var h=I()[b>>>2>>>0],l=I()[b+4>>>2>>>0];b+=8;for(var m=0;m<l;m++){var p=F()[h+m>>>0],r=te[a];0===p||10===p?((1===a?ta:x)(ed(r)),r.length=0):r.push(p)}f+=l}I()[d>>>2>>>0]=f;return 0}q||Tc();for(var ue=Array(256),ve=0;256>ve;++ve)ue[ve]=String.fromCharCode(ve);hd=ue;S=e.BindingError=class extends Error{constructor(a){super(a);this.name="BindingError"}};
|
||||
e.InternalError=class extends Error{constructor(a){super(a);this.name="InternalError"}};V.push(0,1,void 0,1,null,1,!0,1,!1,1);e.count_emval_handles=()=>V.length/2-5-od.length;var Dd=[Dc,Rc,cd,gb,hb,ib,jb,kb,lb,mb,nb,ob,pb,qb,rb,sb,ec,fc,gc,wc,xc,zc,Ac,Bc,Cc],bb,K;
|
||||
(async function(){function a(d,f){K=d.exports;K=Id();K=we();Sc.push(K.jb);va=f;Wa();return K}Ua++;var b=ab();if(e.instantiateWasm)return new Promise(d=>{e.instantiateWasm(b,(f,g)=>{a(f,g);d(f.exports)})});if(q)return new Promise(d=>{Ha=f=>{var g=new WebAssembly.Instance(f,ab());d(a(g,f))}});Xa??=e.locateFile?e.locateFile?e.locateFile("ort-wasm-simd-threaded.jsep.wasm",v):v+"ort-wasm-simd-threaded.jsep.wasm":(new URL("ort-wasm-simd-threaded.jsep.wasm",import.meta.url)).href;try{var c=await $a(b);
|
||||
return a(c.instance,c.module)}catch(d){return ca(d),Promise.reject(d)}})();var Ed=a=>(Ed=K.Ea)(a),Pa=()=>(Pa=K.Fa)();e._OrtInit=(a,b)=>(e._OrtInit=K.Ga)(a,b);e._OrtGetLastError=(a,b)=>(e._OrtGetLastError=K.Ha)(a,b);e._OrtCreateSessionOptions=(a,b,c,d,f,g,h,l,m,p)=>(e._OrtCreateSessionOptions=K.Ia)(a,b,c,d,f,g,h,l,m,p);e._OrtAppendExecutionProvider=(a,b,c,d,f)=>(e._OrtAppendExecutionProvider=K.Ja)(a,b,c,d,f);e._OrtAddFreeDimensionOverride=(a,b,c)=>(e._OrtAddFreeDimensionOverride=K.Ka)(a,b,c);
|
||||
e._OrtAddSessionConfigEntry=(a,b,c)=>(e._OrtAddSessionConfigEntry=K.La)(a,b,c);e._OrtReleaseSessionOptions=a=>(e._OrtReleaseSessionOptions=K.Ma)(a);e._OrtCreateSession=(a,b,c)=>(e._OrtCreateSession=K.Na)(a,b,c);e._OrtReleaseSession=a=>(e._OrtReleaseSession=K.Oa)(a);e._OrtGetInputOutputCount=(a,b,c)=>(e._OrtGetInputOutputCount=K.Pa)(a,b,c);e._OrtGetInputOutputMetadata=(a,b,c,d)=>(e._OrtGetInputOutputMetadata=K.Qa)(a,b,c,d);e._OrtFree=a=>(e._OrtFree=K.Ra)(a);
|
||||
e._OrtCreateTensor=(a,b,c,d,f,g)=>(e._OrtCreateTensor=K.Sa)(a,b,c,d,f,g);e._OrtGetTensorData=(a,b,c,d,f)=>(e._OrtGetTensorData=K.Ta)(a,b,c,d,f);e._OrtReleaseTensor=a=>(e._OrtReleaseTensor=K.Ua)(a);e._OrtCreateRunOptions=(a,b,c,d)=>(e._OrtCreateRunOptions=K.Va)(a,b,c,d);e._OrtAddRunConfigEntry=(a,b,c)=>(e._OrtAddRunConfigEntry=K.Wa)(a,b,c);e._OrtReleaseRunOptions=a=>(e._OrtReleaseRunOptions=K.Xa)(a);e._OrtCreateBinding=a=>(e._OrtCreateBinding=K.Ya)(a);
|
||||
e._OrtBindInput=(a,b,c)=>(e._OrtBindInput=K.Za)(a,b,c);e._OrtBindOutput=(a,b,c,d)=>(e._OrtBindOutput=K._a)(a,b,c,d);e._OrtClearBoundOutputs=a=>(e._OrtClearBoundOutputs=K.$a)(a);e._OrtReleaseBinding=a=>(e._OrtReleaseBinding=K.ab)(a);e._OrtRunWithBinding=(a,b,c,d,f)=>(e._OrtRunWithBinding=K.bb)(a,b,c,d,f);e._OrtRun=(a,b,c,d,f,g,h,l)=>(e._OrtRun=K.cb)(a,b,c,d,f,g,h,l);e._OrtEndProfiling=a=>(e._OrtEndProfiling=K.db)(a);e._JsepOutput=(a,b,c)=>(e._JsepOutput=K.eb)(a,b,c);
|
||||
e._JsepGetNodeName=a=>(e._JsepGetNodeName=K.fb)(a);
|
||||
var Ka=()=>(Ka=K.gb)(),Y=e._free=a=>(Y=e._free=K.hb)(a),sd=e._malloc=a=>(sd=e._malloc=K.ib)(a),Ma=(a,b,c,d,f,g)=>(Ma=K.lb)(a,b,c,d,f,g),Sa=()=>(Sa=K.mb)(),Pc=(a,b,c,d,f)=>(Pc=K.nb)(a,b,c,d,f),Vc=a=>(Vc=K.ob)(a),Zc=a=>(Zc=K.pb)(a),je=(a,b)=>(je=K.qb)(a,b),Bd=()=>(Bd=K.rb)(),Xc=(a,b)=>(Xc=K.sb)(a,b),Qc=a=>(Qc=K.tb)(a),Oc=a=>(Oc=K.ub)(a),Nc=()=>(Nc=K.vb)(),Yc=e.dynCall_ii=(a,b)=>(Yc=e.dynCall_ii=K.wb)(a,b),Vd=a=>(Vd=K.xb)(a),Kd=()=>(Kd=K.yb)(),Ud=a=>(Ud=K.zb)(a),Xd=()=>(Xd=K.Ab)();
|
||||
function we(){var a=K;a=Object.assign({},a);var b=d=>f=>d(f)>>>0,c=d=>()=>d()>>>0;a.Ea=b(a.Ea);a.gb=c(a.gb);a.ib=b(a.ib);a.ub=b(a.ub);a.vb=c(a.vb);a.__cxa_get_exception_ptr=b(a.__cxa_get_exception_ptr);return a}e.stackSave=()=>Nc();e.stackRestore=a=>Qc(a);e.stackAlloc=a=>Oc(a);
|
||||
e.setValue=function(a,b,c="i8"){c.endsWith("*")&&(c="*");switch(c){case "i1":D()[a>>>0]=b;break;case "i8":D()[a>>>0]=b;break;case "i16":G()[a>>>1>>>0]=b;break;case "i32":H()[a>>>2>>>0]=b;break;case "i64":C[a>>>3]=BigInt(b);break;case "float":Ga()[a>>>2>>>0]=b;break;case "double":J()[a>>>3>>>0]=b;break;case "*":I()[a>>>2>>>0]=b;break;default:L(`invalid type for setValue: ${c}`)}};
|
||||
e.getValue=function(a,b="i8"){b.endsWith("*")&&(b="*");switch(b){case "i1":return D()[a>>>0];case "i8":return D()[a>>>0];case "i16":return G()[a>>>1>>>0];case "i32":return H()[a>>>2>>>0];case "i64":return C[a>>>3];case "float":return Ga()[a>>>2>>>0];case "double":return J()[a>>>3>>>0];case "*":return I()[a>>>2>>>0];default:L(`invalid type for getValue: ${b}`)}};e.UTF8ToString=M;e.stringToUTF8=gd;e.lengthBytesUTF8=fd;
|
||||
function xe(){if(0<Ua)Va=xe;else if(q)aa(e),Ta();else{for(;0<Ic.length;)Ic.shift()(e);0<Ua?Va=xe:(e.calledRun=!0,A||(Ta(),aa(e)))}}xe();e.PTR_SIZE=4;moduleRtn=da;
|
||||
|
||||
|
||||
return moduleRtn;
|
||||
}
|
||||
);
|
||||
})();
|
||||
export default ortWasmThreaded;
|
||||
var isPthread = globalThis.self?.name?.startsWith('em-pthread');
|
||||
var isNode = typeof globalThis.process?.versions?.node == 'string';
|
||||
if (isNode) isPthread = (await import('worker_threads')).workerData === 'em-pthread';
|
||||
|
||||
// When running as a pthread, construct a new instance on startup
|
||||
isPthread && ortWasmThreaded();
|
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
var ortWasmThreaded = (() => {
|
||||
var _scriptName = import.meta.url;
|
||||
|
||||
return (
|
||||
async function(moduleArg = {}) {
|
||||
var moduleRtn;
|
||||
|
||||
var f=moduleArg,aa,ba,ca=new Promise((a,b)=>{aa=a;ba=b}),da="object"==typeof window,k="undefined"!=typeof WorkerGlobalScope,l="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node&&"renderer"!=process.type,m=k&&self.name?.startsWith("em-pthread");if(l){const {createRequire:a}=await import("module");var require=a(import.meta.url),n=require("worker_threads");global.Worker=n.Worker;m=(k=!n.jb)&&"em-pthread"==n.workerData}
|
||||
f.mountExternalData=(a,b)=>{a.startsWith("./")&&(a=a.substring(2));(f.Sa||(f.Sa=new Map)).set(a,b)};f.unmountExternalData=()=>{delete f.Sa};var SharedArrayBuffer=globalThis.SharedArrayBuffer??(new WebAssembly.Memory({initial:0,maximum:0,lb:!0})).buffer.constructor,ea=Object.assign({},f),fa="./this.program",q=(a,b)=>{throw b;},r="",ha,t;
|
||||
if(l){var fs=require("fs"),ia=require("path");import.meta.url.startsWith("data:")||(r=ia.dirname(require("url").fileURLToPath(import.meta.url))+"/");t=a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a)};ha=async a=>{a=u(a)?new URL(a):a;return fs.readFileSync(a,void 0)};!f.thisProgram&&1<process.argv.length&&(fa=process.argv[1].replace(/\\/g,"/"));process.argv.slice(2);q=(a,b)=>{process.exitCode=a;throw b;}}else if(da||k)k?r=self.location.href:"undefined"!=typeof document&&document.currentScript&&
|
||||
(r=document.currentScript.src),_scriptName&&(r=_scriptName),r.startsWith("blob:")?r="":r=r.slice(0,r.replace(/[?#].*/,"").lastIndexOf("/")+1),l||(k&&(t=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";b.send(null);return new Uint8Array(b.response)}),ha=async a=>{if(u(a))return new Promise((c,d)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?c(e.response):d(e.status)};e.onerror=d;e.send(null)});
|
||||
var b=await fetch(a,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw Error(b.status+" : "+b.url);});var ja=console.log.bind(console),ka=console.error.bind(console);l&&(ja=(...a)=>fs.writeSync(1,a.join(" ")+"\n"),ka=(...a)=>fs.writeSync(2,a.join(" ")+"\n"));var la=ja,w=ka;Object.assign(f,ea);ea=null;var x=f.wasmBinary,y,ma,z=!1,A,B,na,oa,pa,qa,ra,C,sa,u=a=>a.startsWith("file://");function D(){y.buffer!=B.buffer&&E();return B}function F(){y.buffer!=B.buffer&&E();return na}
|
||||
function ta(){y.buffer!=B.buffer&&E();return oa}function G(){y.buffer!=B.buffer&&E();return pa}function H(){y.buffer!=B.buffer&&E();return qa}function va(){y.buffer!=B.buffer&&E();return ra}function I(){y.buffer!=B.buffer&&E();return sa}
|
||||
if(m){var wa;if(l){var xa=n.parentPort;xa.on("message",b=>onmessage({data:b}));Object.assign(globalThis,{self:global,postMessage:b=>xa.postMessage(b)})}var ya=!1;w=function(...b){b=b.join(" ");l?fs.writeSync(2,b+"\n"):console.error(b)};self.alert=function(...b){postMessage({Ra:"alert",text:b.join(" "),eb:J()})};self.onunhandledrejection=b=>{throw b.reason||b;};function a(b){try{var c=b.data,d=c.Ra;if("load"===d){let e=[];self.onmessage=g=>e.push(g);self.startWorker=()=>{postMessage({Ra:"loaded"});
|
||||
for(let g of e)a(g);self.onmessage=a};for(const g of c.Za)if(!f[g]||f[g].proxy)f[g]=(...h)=>{postMessage({Ra:"callHandler",Ya:g,args:h})},"print"==g&&(la=f[g]),"printErr"==g&&(w=f[g]);y=c.gb;E();wa(c.hb)}else if("run"===d){za(c.Qa);Aa(c.Qa,0,0,1,0,0);Ba();Ca(c.Qa);ya||=!0;try{Da(c.bb,c.Va)}catch(e){if("unwind"!=e)throw e;}}else"setimmediate"!==c.target&&("checkMailbox"===d?ya&&K():d&&(w(`worker: received unknown command ${d}`),w(c)))}catch(e){throw Ea(),e;}}self.onmessage=a}
|
||||
function E(){var a=y.buffer;f.HEAP8=B=new Int8Array(a);f.HEAP16=oa=new Int16Array(a);f.HEAPU8=na=new Uint8Array(a);f.HEAPU16=new Uint16Array(a);f.HEAP32=pa=new Int32Array(a);f.HEAPU32=qa=new Uint32Array(a);f.HEAPF32=ra=new Float32Array(a);f.HEAPF64=sa=new Float64Array(a);f.HEAP64=C=new BigInt64Array(a);f.HEAPU64=new BigUint64Array(a)}m||(y=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),E());function Fa(){m?startWorker(f):L.$()}var M=0,N=null;
|
||||
function Ga(){M--;if(0==M&&N){var a=N;N=null;a()}}function O(a){a="Aborted("+a+")";w(a);z=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");ba(a);throw a;}var Ha;async function Ia(a){if(!x)try{var b=await ha(a);return new Uint8Array(b)}catch{}if(a==Ha&&x)a=new Uint8Array(x);else if(t)a=t(a);else throw"both async and sync fetching of the wasm failed";return a}
|
||||
async function Ja(a,b){try{var c=await Ia(a);return await WebAssembly.instantiate(c,b)}catch(d){w(`failed to asynchronously prepare wasm: ${d}`),O(d)}}async function Ka(a){var b=Ha;if(!x&&"function"==typeof WebAssembly.instantiateStreaming&&!u(b)&&!l)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){w(`wasm streaming compile failed: ${d}`),w("falling back to ArrayBuffer instantiation")}return Ja(b,a)}
|
||||
function La(){Ma={j:Na,b:Oa,E:Pa,f:Qa,U:Ra,A:Sa,C:Ta,V:Ua,S:Va,L:Wa,R:Xa,n:Ya,B:Za,y:$a,T:ab,z:bb,_:cb,O:db,w:eb,F:fb,t:gb,i:hb,N:Ca,X:ib,I:jb,J:kb,K:lb,G:mb,H:nb,u:ob,q:pb,Z:qb,o:rb,k:sb,Y:tb,d:ub,W:vb,x:wb,c:xb,e:yb,h:zb,v:Ab,s:Bb,r:Cb,P:Db,Q:Eb,D:Fb,g:Gb,m:Hb,M:Ib,l:Jb,a:y,p:Kb};return{a:Ma}}
|
||||
var Mb={802156:(a,b,c,d,e)=>{if("undefined"==typeof f||!f.Sa)return 1;a=Lb(Number(a>>>0));a.startsWith("./")&&(a=a.substring(2));a=f.Sa.get(a);if(!a)return 2;b=Number(b>>>0);c=Number(c>>>0);d=Number(d>>>0);if(b+c>a.byteLength)return 3;try{const g=a.subarray(b,b+c);switch(e){case 0:F().set(g,d>>>0);break;case 1:f.ib?f.ib(d,g):f.kb(d,g);break;default:return 4}return 0}catch{return 4}},802980:()=>"undefined"!==typeof wasmOffsetConverter};function Na(){return"undefined"!==typeof wasmOffsetConverter}
|
||||
class Nb{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
|
||||
var Ob=a=>{a.terminate();a.onmessage=()=>{}},Pb=[],Sb=a=>{0==Q.length&&(Qb(),Rb(Q[0]));var b=Q.pop();if(!b)return 6;R.push(b);S[a.Qa]=b;b.Qa=a.Qa;var c={Ra:"run",bb:a.ab,Va:a.Va,Qa:a.Qa};l&&b.unref();b.postMessage(c,a.Xa);return 0},T=0,V=(a,b,...c)=>{for(var d=2*c.length,e=Tb(),g=Ub(8*d),h=g>>>3,p=0;p<c.length;p++){var v=c[p];"bigint"==typeof v?(C[h+2*p]=1n,C[h+2*p+1]=v):(C[h+2*p]=0n,I()[h+2*p+1>>>0]=v)}a=Vb(a,0,d,g,b);U(e);return a};
|
||||
function Kb(a){if(m)return V(0,1,a);A=a;if(!(0<T)){for(var b of R)Ob(b);for(b of Q)Ob(b);Q=[];R=[];S={};z=!0}q(a,new Nb(a))}function Wb(a){if(m)return V(1,0,a);Fb(a)}var Fb=a=>{A=a;if(m)throw Wb(a),"unwind";Kb(a)},Q=[],R=[],Xb=[],S={};function Yb(){for(var a=f.numThreads-1;a--;)Qb();Pb.unshift(()=>{M++;Zb(()=>Ga())})}var ac=a=>{var b=a.Qa;delete S[b];Q.push(a);R.splice(R.indexOf(a),1);a.Qa=0;$b(b)};function Ba(){Xb.forEach(a=>a())}
|
||||
var Rb=a=>new Promise(b=>{a.onmessage=g=>{g=g.data;var h=g.Ra;if(g.Ta&&g.Ta!=J()){var p=S[g.Ta];p?p.postMessage(g,g.Xa):w(`Internal error! Worker sent a message "${h}" to target pthread ${g.Ta}, but that thread no longer exists!`)}else if("checkMailbox"===h)K();else if("spawnThread"===h)Sb(g);else if("cleanupThread"===h)ac(S[g.cb]);else if("loaded"===h)a.loaded=!0,l&&!a.Qa&&a.unref(),b(a);else if("alert"===h)alert(`Thread ${g.eb}: ${g.text}`);else if("setimmediate"===g.target)a.postMessage(g);else if("callHandler"===
|
||||
h)f[g.Ya](...g.args);else h&&w(`worker sent an unknown command ${h}`)};a.onerror=g=>{w(`${"worker sent an error!"} ${g.filename}:${g.lineno}: ${g.message}`);throw g;};l&&(a.on("message",g=>a.onmessage({data:g})),a.on("error",g=>a.onerror(g)));var c=[],d=[],e;for(e of d)f.propertyIsEnumerable(e)&&c.push(e);a.postMessage({Ra:"load",Za:c,gb:y,hb:ma})});function Zb(a){m?a():Promise.all(Q.map(Rb)).then(a)}
|
||||
function Qb(){var a=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});Q.push(a)}var za=a=>{E();var b=H()[a+52>>>2>>>0];a=H()[a+56>>>2>>>0];bc(b,b-a);U(b)},W=[],cc,Da=(a,b)=>{T=0;var c=W[a];c||(a>=W.length&&(W.length=a+1),W[a]=c=cc.get(a));a=c(b);0<T?A=a:dc(a)};class ec{constructor(a){this.Ua=a-24}}var fc=0,gc=0;
|
||||
function Oa(a,b,c){a>>>=0;var d=new ec(a);b>>>=0;c>>>=0;H()[d.Ua+16>>>2>>>0]=0;H()[d.Ua+4>>>2>>>0]=b;H()[d.Ua+8>>>2>>>0]=c;fc=a;gc++;throw fc;}function hc(a,b,c,d){return m?V(2,1,a,b,c,d):Pa(a,b,c,d)}function Pa(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;if("undefined"==typeof SharedArrayBuffer)return 6;var e=[];if(m&&0===e.length)return hc(a,b,c,d);a={ab:c,Qa:a,Va:d,Xa:e};return m?(a.Ra="spawnThread",postMessage(a,e),0):Sb(a)}
|
||||
var ic="undefined"!=typeof TextDecoder?new TextDecoder:void 0,jc=(a,b=0,c=NaN)=>{b>>>=0;var d=b+c;for(c=b;a[c]&&!(c>=d);)++c;if(16<c-b&&a.buffer&&ic)return ic.decode(a.buffer instanceof ArrayBuffer?a.subarray(b,c):a.slice(b,c));for(d="";b<c;){var e=a[b++];if(e&128){var g=a[b++]&63;if(192==(e&224))d+=String.fromCharCode((e&31)<<6|g);else{var h=a[b++]&63;e=224==(e&240)?(e&15)<<12|g<<6|h:(e&7)<<18|g<<12|h<<6|a[b++]&63;65536>e?d+=String.fromCharCode(e):(e-=65536,d+=String.fromCharCode(55296|e>>10,56320|
|
||||
e&1023))}}else d+=String.fromCharCode(e)}return d},Lb=(a,b)=>(a>>>=0)?jc(F(),a,b):"";function Qa(a,b,c){return m?V(3,1,a,b,c):0}function Ra(a,b){if(m)return V(4,1,a,b)}
|
||||
var X=(a,b,c)=>{var d=F();b>>>=0;if(0<c){var e=b;c=b+c-1;for(var g=0;g<a.length;++g){var h=a.charCodeAt(g);if(55296<=h&&57343>=h){var p=a.charCodeAt(++g);h=65536+((h&1023)<<10)|p&1023}if(127>=h){if(b>=c)break;d[b++>>>0]=h}else{if(2047>=h){if(b+1>=c)break;d[b++>>>0]=192|h>>6}else{if(65535>=h){if(b+2>=c)break;d[b++>>>0]=224|h>>12}else{if(b+3>=c)break;d[b++>>>0]=240|h>>18;d[b++>>>0]=128|h>>12&63}d[b++>>>0]=128|h>>6&63}d[b++>>>0]=128|h&63}}d[b>>>0]=0;a=b-e}else a=0;return a};
|
||||
function Sa(a,b){if(m)return V(5,1,a,b)}function Ta(a,b,c){if(m)return V(6,1,a,b,c)}function Ua(a,b,c){return m?V(7,1,a,b,c):0}function Va(a,b){if(m)return V(8,1,a,b)}function Wa(a,b,c){if(m)return V(9,1,a,b,c)}function Xa(a,b,c,d){if(m)return V(10,1,a,b,c,d)}function Ya(a,b,c,d){if(m)return V(11,1,a,b,c,d)}function Za(a,b,c,d){if(m)return V(12,1,a,b,c,d)}function $a(a){if(m)return V(13,1,a)}function ab(a,b){if(m)return V(14,1,a,b)}function bb(a,b,c){if(m)return V(15,1,a,b,c)}var cb=()=>O("");
|
||||
function db(a){Aa(a>>>0,!k,1,!da,131072,!1);Ba()}var kc=a=>{if(!z)try{if(a(),!(0<T))try{m?dc(A):Fb(A)}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}}catch(b){b instanceof Nb||"unwind"==b||q(1,b)}};function Ca(a){a>>>=0;"function"===typeof Atomics.fb&&(Atomics.fb(G(),a>>>2,a).value.then(K),a+=128,Atomics.store(G(),a>>>2,1))}var K=()=>{var a=J();a&&(Ca(a),kc(lc))};function eb(a,b){a>>>=0;a==b>>>0?setTimeout(K):m?postMessage({Ta:a,Ra:"checkMailbox"}):(a=S[a])&&a.postMessage({Ra:"checkMailbox"})}
|
||||
var mc=[];function fb(a,b,c,d,e){b>>>=0;d/=2;mc.length=d;c=e>>>0>>>3;for(e=0;e<d;e++)mc[e]=C[c+2*e]?C[c+2*e+1]:I()[c+2*e+1>>>0];return(b?Mb[b]:nc[a])(...mc)}var gb=()=>{T=0};function hb(a){a>>>=0;m?postMessage({Ra:"cleanupThread",cb:a}):ac(S[a])}function ib(a){l&&S[a>>>0].ref()}
|
||||
function jb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getUTCSeconds();G()[b+4>>>2>>>0]=a.getUTCMinutes();G()[b+8>>>2>>>0]=a.getUTCHours();G()[b+12>>>2>>>0]=a.getUTCDate();G()[b+16>>>2>>>0]=a.getUTCMonth();G()[b+20>>>2>>>0]=a.getUTCFullYear()-1900;G()[b+24>>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;G()[b+28>>>2>>>0]=a}
|
||||
var oc=a=>0===a%4&&(0!==a%100||0===a%400),pc=[0,31,60,91,121,152,182,213,244,274,305,335],qc=[0,31,59,90,120,151,181,212,243,273,304,334];
|
||||
function kb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);G()[b>>>2>>>0]=a.getSeconds();G()[b+4>>>2>>>0]=a.getMinutes();G()[b+8>>>2>>>0]=a.getHours();G()[b+12>>>2>>>0]=a.getDate();G()[b+16>>>2>>>0]=a.getMonth();G()[b+20>>>2>>>0]=a.getFullYear()-1900;G()[b+24>>>2>>>0]=a.getDay();var c=(oc(a.getFullYear())?pc:qc)[a.getMonth()]+a.getDate()-1|0;G()[b+28>>>2>>>0]=c;G()[b+36>>>2>>>0]=-(60*a.getTimezoneOffset());c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
|
||||
var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();a=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0;G()[b+32>>>2>>>0]=a}
|
||||
function lb(a){a>>>=0;var b=new Date(G()[a+20>>>2>>>0]+1900,G()[a+16>>>2>>>0],G()[a+12>>>2>>>0],G()[a+8>>>2>>>0],G()[a+4>>>2>>>0],G()[a>>>2>>>0],0),c=G()[a+32>>>2>>>0],d=b.getTimezoneOffset(),e=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),g=(new Date(b.getFullYear(),0,1)).getTimezoneOffset(),h=Math.min(g,e);0>c?G()[a+32>>>2>>>0]=Number(e!=g&&h==d):0<c!=(h==d)&&(e=Math.max(g,e),b.setTime(b.getTime()+6E4*((0<c?h:e)-d)));G()[a+24>>>2>>>0]=b.getDay();c=(oc(b.getFullYear())?pc:qc)[b.getMonth()]+
|
||||
b.getDate()-1|0;G()[a+28>>>2>>>0]=c;G()[a>>>2>>>0]=b.getSeconds();G()[a+4>>>2>>>0]=b.getMinutes();G()[a+8>>>2>>>0]=b.getHours();G()[a+12>>>2>>>0]=b.getDate();G()[a+16>>>2>>>0]=b.getMonth();G()[a+20>>>2>>>0]=b.getYear();a=b.getTime();return BigInt(isNaN(a)?-1:a/1E3)}function mb(a,b,c,d,e,g,h){return m?V(16,1,a,b,c,d,e,g,h):-52}function nb(a,b,c,d,e,g){if(m)return V(17,1,a,b,c,d,e,g)}var Y={},xb=()=>performance.timeOrigin+performance.now();
|
||||
function ob(a,b){if(m)return V(18,1,a,b);Y[a]&&(clearTimeout(Y[a].id),delete Y[a]);if(!b)return 0;var c=setTimeout(()=>{delete Y[a];kc(()=>rc(a,performance.timeOrigin+performance.now()))},b);Y[a]={id:c,mb:b};return 0}
|
||||
function pb(a,b,c,d){a>>>=0;b>>>=0;c>>>=0;d>>>=0;var e=(new Date).getFullYear(),g=(new Date(e,0,1)).getTimezoneOffset();e=(new Date(e,6,1)).getTimezoneOffset();var h=Math.max(g,e);H()[a>>>2>>>0]=60*h;G()[b>>>2>>>0]=Number(g!=e);b=p=>{var v=Math.abs(p);return`UTC${0<=p?"-":"+"}${String(Math.floor(v/60)).padStart(2,"0")}${String(v%60).padStart(2,"0")}`};a=b(g);b=b(e);e<g?(X(a,c,17),X(b,d,17)):(X(a,d,17),X(b,c,17))}var tb=()=>Date.now(),sc=1;
|
||||
function qb(a,b,c){if(!(0<=a&&3>=a))return 28;if(0===a)a=Date.now();else if(sc)a=performance.timeOrigin+performance.now();else return 52;C[c>>>0>>>3]=BigInt(Math.round(1E6*a));return 0}var tc=[];function rb(a,b,c){a>>>=0;b>>>=0;c>>>=0;tc.length=0;for(var d;d=F()[b++>>>0];){var e=105!=d;e&=112!=d;c+=e&&c%8?4:0;tc.push(112==d?H()[c>>>2>>>0]:106==d?C[c>>>3]:105==d?G()[c>>>2>>>0]:I()[c>>>3>>>0]);c+=e?8:4}return Mb[a](...tc)}var sb=()=>{};function ub(a,b){return w(Lb(a>>>0,b>>>0))}
|
||||
var vb=()=>{T+=1;throw"unwind";};function wb(){return 4294901760}var yb=()=>l?require("os").cpus().length:navigator.hardwareConcurrency;function zb(){O("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER");return 0}
|
||||
function Ab(a){a>>>=0;var b=F().length;if(a<=b||4294901760<a)return!1;for(var c=1;4>=c;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(4294901760,65536*Math.ceil(Math.max(a,d)/65536))-y.buffer.byteLength+65535)/65536|0;try{y.grow(d);E();var e=1;break a}catch(g){}e=void 0}if(e)return!0}return!1}var uc=()=>{O("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER");return 0},Z={},vc=a=>{a.forEach(b=>{var c=uc();c&&(Z[c]=b)})};
|
||||
function Bb(){var a=Error().stack.toString().split("\n");"Error"==a[0]&&a.shift();vc(a);Z.Wa=uc();Z.$a=a;return Z.Wa}function Cb(a,b,c){a>>>=0;b>>>=0;if(Z.Wa==a)var d=Z.$a;else d=Error().stack.toString().split("\n"),"Error"==d[0]&&d.shift(),vc(d);for(var e=3;d[e]&&uc()!=a;)++e;for(a=0;a<c&&d[a+e];++a)G()[b+4*a>>>2>>>0]=uc();return a}
|
||||
var wc={},yc=()=>{if(!xc){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:fa||"./this.program"},b;for(b in wc)void 0===wc[b]?delete a[b]:a[b]=wc[b];var c=[];for(b in a)c.push(`${b}=${a[b]}`);xc=c}return xc},xc;
|
||||
function Db(a,b){if(m)return V(19,1,a,b);a>>>=0;b>>>=0;var c=0;yc().forEach((d,e)=>{var g=b+c;e=H()[a+4*e>>>2>>>0]=g;for(g=0;g<d.length;++g)D()[e++>>>0]=d.charCodeAt(g);D()[e>>>0]=0;c+=d.length+1});return 0}function Eb(a,b){if(m)return V(20,1,a,b);a>>>=0;b>>>=0;var c=yc();H()[a>>>2>>>0]=c.length;var d=0;c.forEach(e=>d+=e.length+1);H()[b>>>2>>>0]=d;return 0}function Gb(a){return m?V(21,1,a):52}function Hb(a,b,c,d){return m?V(22,1,a,b,c,d):52}function Ib(a,b,c,d){return m?V(23,1,a,b,c,d):70}
|
||||
var zc=[null,[],[]];function Jb(a,b,c,d){if(m)return V(24,1,a,b,c,d);b>>>=0;c>>>=0;d>>>=0;for(var e=0,g=0;g<c;g++){var h=H()[b>>>2>>>0],p=H()[b+4>>>2>>>0];b+=8;for(var v=0;v<p;v++){var P=F()[h+v>>>0],ua=zc[a];0===P||10===P?((1===a?la:w)(jc(ua)),ua.length=0):ua.push(P)}e+=p}H()[d>>>2>>>0]=e;return 0}m||Yb();var nc=[Kb,Wb,hc,Qa,Ra,Sa,Ta,Ua,Va,Wa,Xa,Ya,Za,$a,ab,bb,mb,nb,ob,Db,Eb,Gb,Hb,Ib,Jb],Ma,L;
|
||||
(async function(){function a(d,e){L=d.exports;L=Ac();Xb.push(L.Da);cc=L.Ea;ma=e;Ga();return L}M++;var b=La();if(f.instantiateWasm)return new Promise(d=>{f.instantiateWasm(b,(e,g)=>{a(e,g);d(e.exports)})});if(m)return new Promise(d=>{wa=e=>{var g=new WebAssembly.Instance(e,La());d(a(g,e))}});Ha??=f.locateFile?f.locateFile?f.locateFile("ort-wasm-simd-threaded.wasm",r):r+"ort-wasm-simd-threaded.wasm":(new URL("ort-wasm-simd-threaded.wasm",import.meta.url)).href;try{var c=await Ka(b);return a(c.instance,
|
||||
c.module)}catch(d){return ba(d),Promise.reject(d)}})();f._OrtInit=(a,b)=>(f._OrtInit=L.aa)(a,b);f._OrtGetLastError=(a,b)=>(f._OrtGetLastError=L.ba)(a,b);f._OrtCreateSessionOptions=(a,b,c,d,e,g,h,p,v,P)=>(f._OrtCreateSessionOptions=L.ca)(a,b,c,d,e,g,h,p,v,P);f._OrtAppendExecutionProvider=(a,b,c,d,e)=>(f._OrtAppendExecutionProvider=L.da)(a,b,c,d,e);f._OrtAddFreeDimensionOverride=(a,b,c)=>(f._OrtAddFreeDimensionOverride=L.ea)(a,b,c);
|
||||
f._OrtAddSessionConfigEntry=(a,b,c)=>(f._OrtAddSessionConfigEntry=L.fa)(a,b,c);f._OrtReleaseSessionOptions=a=>(f._OrtReleaseSessionOptions=L.ga)(a);f._OrtCreateSession=(a,b,c)=>(f._OrtCreateSession=L.ha)(a,b,c);f._OrtReleaseSession=a=>(f._OrtReleaseSession=L.ia)(a);f._OrtGetInputOutputCount=(a,b,c)=>(f._OrtGetInputOutputCount=L.ja)(a,b,c);f._OrtGetInputOutputMetadata=(a,b,c,d)=>(f._OrtGetInputOutputMetadata=L.ka)(a,b,c,d);f._OrtFree=a=>(f._OrtFree=L.la)(a);
|
||||
f._OrtCreateTensor=(a,b,c,d,e,g)=>(f._OrtCreateTensor=L.ma)(a,b,c,d,e,g);f._OrtGetTensorData=(a,b,c,d,e)=>(f._OrtGetTensorData=L.na)(a,b,c,d,e);f._OrtReleaseTensor=a=>(f._OrtReleaseTensor=L.oa)(a);f._OrtCreateRunOptions=(a,b,c,d)=>(f._OrtCreateRunOptions=L.pa)(a,b,c,d);f._OrtAddRunConfigEntry=(a,b,c)=>(f._OrtAddRunConfigEntry=L.qa)(a,b,c);f._OrtReleaseRunOptions=a=>(f._OrtReleaseRunOptions=L.ra)(a);f._OrtCreateBinding=a=>(f._OrtCreateBinding=L.sa)(a);
|
||||
f._OrtBindInput=(a,b,c)=>(f._OrtBindInput=L.ta)(a,b,c);f._OrtBindOutput=(a,b,c,d)=>(f._OrtBindOutput=L.ua)(a,b,c,d);f._OrtClearBoundOutputs=a=>(f._OrtClearBoundOutputs=L.va)(a);f._OrtReleaseBinding=a=>(f._OrtReleaseBinding=L.wa)(a);f._OrtRunWithBinding=(a,b,c,d,e)=>(f._OrtRunWithBinding=L.xa)(a,b,c,d,e);f._OrtRun=(a,b,c,d,e,g,h,p)=>(f._OrtRun=L.ya)(a,b,c,d,e,g,h,p);f._OrtEndProfiling=a=>(f._OrtEndProfiling=L.za)(a);var J=()=>(J=L.Aa)();f._free=a=>(f._free=L.Ba)(a);f._malloc=a=>(f._malloc=L.Ca)(a);
|
||||
var Aa=(a,b,c,d,e,g)=>(Aa=L.Fa)(a,b,c,d,e,g),Ea=()=>(Ea=L.Ga)(),Vb=(a,b,c,d,e)=>(Vb=L.Ha)(a,b,c,d,e),$b=a=>($b=L.Ia)(a),dc=a=>(dc=L.Ja)(a),rc=(a,b)=>(rc=L.Ka)(a,b),lc=()=>(lc=L.La)(),bc=(a,b)=>(bc=L.Ma)(a,b),U=a=>(U=L.Na)(a),Ub=a=>(Ub=L.Oa)(a),Tb=()=>(Tb=L.Pa)();function Ac(){var a=L;a=Object.assign({},a);var b=d=>()=>d()>>>0,c=d=>e=>d(e)>>>0;a.Aa=b(a.Aa);a.Ca=c(a.Ca);a.Oa=c(a.Oa);a.Pa=b(a.Pa);a.__cxa_get_exception_ptr=c(a.__cxa_get_exception_ptr);return a}f.stackSave=()=>Tb();f.stackRestore=a=>U(a);
|
||||
f.stackAlloc=a=>Ub(a);f.setValue=function(a,b,c="i8"){c.endsWith("*")&&(c="*");switch(c){case "i1":D()[a>>>0]=b;break;case "i8":D()[a>>>0]=b;break;case "i16":ta()[a>>>1>>>0]=b;break;case "i32":G()[a>>>2>>>0]=b;break;case "i64":C[a>>>3]=BigInt(b);break;case "float":va()[a>>>2>>>0]=b;break;case "double":I()[a>>>3>>>0]=b;break;case "*":H()[a>>>2>>>0]=b;break;default:O(`invalid type for setValue: ${c}`)}};
|
||||
f.getValue=function(a,b="i8"){b.endsWith("*")&&(b="*");switch(b){case "i1":return D()[a>>>0];case "i8":return D()[a>>>0];case "i16":return ta()[a>>>1>>>0];case "i32":return G()[a>>>2>>>0];case "i64":return C[a>>>3];case "float":return va()[a>>>2>>>0];case "double":return I()[a>>>3>>>0];case "*":return H()[a>>>2>>>0];default:O(`invalid type for getValue: ${b}`)}};f.UTF8ToString=Lb;f.stringToUTF8=X;
|
||||
f.lengthBytesUTF8=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);127>=d?b++:2047>=d?b+=2:55296<=d&&57343>=d?(b+=4,++c):b+=3}return b};function Bc(){if(0<M)N=Bc;else if(m)aa(f),Fa();else{for(;0<Pb.length;)Pb.shift()(f);0<M?N=Bc:(f.calledRun=!0,z||(Fa(),aa(f)))}}Bc();f.PTR_SIZE=4;moduleRtn=ca;
|
||||
|
||||
|
||||
return moduleRtn;
|
||||
}
|
||||
);
|
||||
})();
|
||||
export default ortWasmThreaded;
|
||||
var isPthread = globalThis.self?.name?.startsWith('em-pthread');
|
||||
var isNode = typeof globalThis.process?.versions?.node == 'string';
|
||||
if (isNode) isPthread = (await import('worker_threads')).workerData === 'em-pthread';
|
||||
|
||||
// When running as a pthread, construct a new instance on startup
|
||||
isPthread && ortWasmThreaded();
|
Binary file not shown.
@@ -0,0 +1,324 @@
|
||||
let wasm;
|
||||
|
||||
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
||||
|
||||
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
||||
|
||||
let cachedUint8ArrayMemory0 = null;
|
||||
|
||||
function getUint8ArrayMemory0() {
|
||||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
||||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedUint8ArrayMemory0;
|
||||
}
|
||||
|
||||
function getStringFromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
||||
}
|
||||
|
||||
let WASM_VECTOR_LEN = 0;
|
||||
|
||||
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
||||
|
||||
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
||||
? function (arg, view) {
|
||||
return cachedTextEncoder.encodeInto(arg, view);
|
||||
}
|
||||
: function (arg, view) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
view.set(buf);
|
||||
return {
|
||||
read: arg.length,
|
||||
written: buf.length
|
||||
};
|
||||
});
|
||||
|
||||
function passStringToWasm0(arg, malloc, realloc) {
|
||||
|
||||
if (realloc === undefined) {
|
||||
const buf = cachedTextEncoder.encode(arg);
|
||||
const ptr = malloc(buf.length, 1) >>> 0;
|
||||
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
||||
WASM_VECTOR_LEN = buf.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let len = arg.length;
|
||||
let ptr = malloc(len, 1) >>> 0;
|
||||
|
||||
const mem = getUint8ArrayMemory0();
|
||||
|
||||
let offset = 0;
|
||||
|
||||
for (; offset < len; offset++) {
|
||||
const code = arg.charCodeAt(offset);
|
||||
if (code > 0x7F) break;
|
||||
mem[ptr + offset] = code;
|
||||
}
|
||||
|
||||
if (offset !== len) {
|
||||
if (offset !== 0) {
|
||||
arg = arg.slice(offset);
|
||||
}
|
||||
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
||||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
||||
const ret = encodeString(arg, view);
|
||||
|
||||
offset += ret.written;
|
||||
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
||||
}
|
||||
|
||||
WASM_VECTOR_LEN = offset;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
let cachedDataViewMemory0 = null;
|
||||
|
||||
function getDataViewMemory0() {
|
||||
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
||||
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
||||
}
|
||||
return cachedDataViewMemory0;
|
||||
}
|
||||
|
||||
export function main() {
|
||||
wasm.main();
|
||||
}
|
||||
|
||||
let cachedFloat32ArrayMemory0 = null;
|
||||
|
||||
function getFloat32ArrayMemory0() {
|
||||
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
||||
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
||||
}
|
||||
return cachedFloat32ArrayMemory0;
|
||||
}
|
||||
|
||||
function passArrayF32ToWasm0(arg, malloc) {
|
||||
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
||||
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
||||
WASM_VECTOR_LEN = arg.length;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
function getArrayF32FromWasm0(ptr, len) {
|
||||
ptr = ptr >>> 0;
|
||||
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
||||
}
|
||||
|
||||
const SIMDMathFinalization = (typeof FinalizationRegistry === 'undefined')
|
||||
? { register: () => {}, unregister: () => {} }
|
||||
: new FinalizationRegistry(ptr => wasm.__wbg_simdmath_free(ptr >>> 0, 1));
|
||||
|
||||
export class SIMDMath {
|
||||
|
||||
__destroy_into_raw() {
|
||||
const ptr = this.__wbg_ptr;
|
||||
this.__wbg_ptr = 0;
|
||||
SIMDMathFinalization.unregister(this);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
free() {
|
||||
const ptr = this.__destroy_into_raw();
|
||||
wasm.__wbg_simdmath_free(ptr, 0);
|
||||
}
|
||||
constructor() {
|
||||
const ret = wasm.simdmath_new();
|
||||
this.__wbg_ptr = ret >>> 0;
|
||||
SIMDMathFinalization.register(this, this.__wbg_ptr, this);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @param {Float32Array} vec_a
|
||||
* @param {Float32Array} vec_b
|
||||
* @returns {number}
|
||||
*/
|
||||
cosine_similarity(vec_a, vec_b) {
|
||||
const ptr0 = passArrayF32ToWasm0(vec_a, wasm.__wbindgen_malloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(vec_b, wasm.__wbindgen_malloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.simdmath_cosine_similarity(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @param {Float32Array} vectors
|
||||
* @param {Float32Array} query
|
||||
* @param {number} vector_dim
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
batch_similarity(vectors, query, vector_dim) {
|
||||
const ptr0 = passArrayF32ToWasm0(vectors, wasm.__wbindgen_malloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(query, wasm.__wbindgen_malloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.simdmath_batch_similarity(this.__wbg_ptr, ptr0, len0, ptr1, len1, vector_dim);
|
||||
var v3 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
||||
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
||||
return v3;
|
||||
}
|
||||
/**
|
||||
* @param {Float32Array} vectors_a
|
||||
* @param {Float32Array} vectors_b
|
||||
* @param {number} vector_dim
|
||||
* @returns {Float32Array}
|
||||
*/
|
||||
similarity_matrix(vectors_a, vectors_b, vector_dim) {
|
||||
const ptr0 = passArrayF32ToWasm0(vectors_a, wasm.__wbindgen_malloc);
|
||||
const len0 = WASM_VECTOR_LEN;
|
||||
const ptr1 = passArrayF32ToWasm0(vectors_b, wasm.__wbindgen_malloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
const ret = wasm.simdmath_similarity_matrix(this.__wbg_ptr, ptr0, len0, ptr1, len1, vector_dim);
|
||||
var v3 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
||||
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
||||
return v3;
|
||||
}
|
||||
}
|
||||
|
||||
async function __wbg_load(module, imports) {
|
||||
if (typeof Response === 'function' && module instanceof Response) {
|
||||
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
||||
try {
|
||||
return await WebAssembly.instantiateStreaming(module, imports);
|
||||
|
||||
} catch (e) {
|
||||
if (module.headers.get('Content-Type') != 'application/wasm') {
|
||||
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
||||
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bytes = await module.arrayBuffer();
|
||||
return await WebAssembly.instantiate(bytes, imports);
|
||||
|
||||
} else {
|
||||
const instance = await WebAssembly.instantiate(module, imports);
|
||||
|
||||
if (instance instanceof WebAssembly.Instance) {
|
||||
return { instance, module };
|
||||
|
||||
} else {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function __wbg_get_imports() {
|
||||
const imports = {};
|
||||
imports.wbg = {};
|
||||
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
||||
let deferred0_0;
|
||||
let deferred0_1;
|
||||
try {
|
||||
deferred0_0 = arg0;
|
||||
deferred0_1 = arg1;
|
||||
console.error(getStringFromWasm0(arg0, arg1));
|
||||
} finally {
|
||||
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
||||
}
|
||||
};
|
||||
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
||||
const ret = new Error();
|
||||
return ret;
|
||||
};
|
||||
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
||||
const ret = arg1.stack;
|
||||
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
||||
const len1 = WASM_VECTOR_LEN;
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
||||
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
||||
};
|
||||
imports.wbg.__wbindgen_init_externref_table = function() {
|
||||
const table = wasm.__wbindgen_export_3;
|
||||
const offset = table.grow(4);
|
||||
table.set(0, undefined);
|
||||
table.set(offset + 0, undefined);
|
||||
table.set(offset + 1, null);
|
||||
table.set(offset + 2, true);
|
||||
table.set(offset + 3, false);
|
||||
;
|
||||
};
|
||||
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
||||
throw new Error(getStringFromWasm0(arg0, arg1));
|
||||
};
|
||||
|
||||
return imports;
|
||||
}
|
||||
|
||||
function __wbg_init_memory(imports, memory) {
|
||||
|
||||
}
|
||||
|
||||
function __wbg_finalize_init(instance, module) {
|
||||
wasm = instance.exports;
|
||||
__wbg_init.__wbindgen_wasm_module = module;
|
||||
cachedDataViewMemory0 = null;
|
||||
cachedFloat32ArrayMemory0 = null;
|
||||
cachedUint8ArrayMemory0 = null;
|
||||
|
||||
|
||||
wasm.__wbindgen_start();
|
||||
return wasm;
|
||||
}
|
||||
|
||||
function initSync(module) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
if (Object.getPrototypeOf(module) === Object.prototype) {
|
||||
({module} = module)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
__wbg_init_memory(imports);
|
||||
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
module = new WebAssembly.Module(module);
|
||||
}
|
||||
|
||||
const instance = new WebAssembly.Instance(module, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
async function __wbg_init(module_or_path) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
|
||||
if (typeof module_or_path !== 'undefined') {
|
||||
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
||||
({module_or_path} = module_or_path)
|
||||
} else {
|
||||
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof module_or_path === 'undefined') {
|
||||
module_or_path = new URL('simd_math_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
|
||||
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
||||
module_or_path = fetch(module_or_path);
|
||||
}
|
||||
|
||||
__wbg_init_memory(imports);
|
||||
|
||||
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
||||
|
||||
return __wbg_finalize_init(instance, module);
|
||||
}
|
||||
|
||||
export { initSync };
|
||||
export default __wbg_init;
|
Binary file not shown.
@@ -0,0 +1,384 @@
|
||||
/* eslint-disable */
|
||||
// js/similarity.worker.js
|
||||
importScripts('../libs/ort.min.js'); // 调整路径以匹配您的文件结构
|
||||
|
||||
// 全局Worker状态
|
||||
let session = null;
|
||||
let modelPathInternal = null;
|
||||
let ortEnvConfigured = false;
|
||||
let sessionOptions = null;
|
||||
let modelInputNames = null; // 存储模型的输入名称
|
||||
|
||||
// 复用的 TypedArray 缓冲区,减少内存分配
|
||||
let reusableBuffers = {
|
||||
inputIds: null,
|
||||
attentionMask: null,
|
||||
tokenTypeIds: null,
|
||||
};
|
||||
|
||||
// 性能统计
|
||||
let workerStats = {
|
||||
totalInferences: 0,
|
||||
totalInferenceTime: 0,
|
||||
averageInferenceTime: 0,
|
||||
memoryAllocations: 0,
|
||||
};
|
||||
|
||||
// 配置 ONNX Runtime 环境 (仅一次)
|
||||
function configureOrtEnv(numThreads = 1, executionProviders = ['wasm']) {
|
||||
if (ortEnvConfigured) return;
|
||||
try {
|
||||
ort.env.wasm.numThreads = numThreads;
|
||||
ort.env.wasm.simd = true; // 尽可能启用SIMD
|
||||
ort.env.wasm.proxy = false; // 在Worker中,通常不需要代理
|
||||
ort.env.logLevel = 'warning'; // 'verbose', 'info', 'warning', 'error', 'fatal'
|
||||
ortEnvConfigured = true;
|
||||
|
||||
sessionOptions = {
|
||||
executionProviders: executionProviders,
|
||||
graphOptimizationLevel: 'all',
|
||||
enableCpuMemArena: true,
|
||||
enableMemPattern: true,
|
||||
// executionMode: 'sequential' // 在worker内部通常是顺序执行一个任务
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Worker: Failed to configure ORT environment', error);
|
||||
throw error; // 抛出错误,让主线程知道
|
||||
}
|
||||
}
|
||||
|
||||
async function initializeModel(modelPathOrData, numThreads, executionProviders) {
|
||||
try {
|
||||
configureOrtEnv(numThreads, executionProviders); // 确保环境已配置
|
||||
|
||||
if (!modelPathOrData) {
|
||||
throw new Error('Worker: Model path or data is not provided.');
|
||||
}
|
||||
|
||||
// Check if input is ArrayBuffer (cached model data) or string (URL path)
|
||||
if (modelPathOrData instanceof ArrayBuffer) {
|
||||
console.log(
|
||||
`Worker: Initializing model from cached ArrayBuffer (${modelPathOrData.byteLength} bytes)`,
|
||||
);
|
||||
session = await ort.InferenceSession.create(modelPathOrData, sessionOptions);
|
||||
modelPathInternal = '[Cached ArrayBuffer]'; // For debugging purposes
|
||||
} else {
|
||||
console.log(`Worker: Initializing model from URL: ${modelPathOrData}`);
|
||||
modelPathInternal = modelPathOrData; // 存储模型路径以备调试或重载(如果需要)
|
||||
session = await ort.InferenceSession.create(modelPathInternal, sessionOptions);
|
||||
}
|
||||
|
||||
// 获取模型的输入名称,用于判断是否需要token_type_ids
|
||||
modelInputNames = session.inputNames;
|
||||
console.log(`Worker: ONNX session created successfully for model: ${modelPathInternal}`);
|
||||
console.log(`Worker: Model input names:`, modelInputNames);
|
||||
|
||||
return { status: 'success', message: 'Model initialized' };
|
||||
} catch (error) {
|
||||
console.error(`Worker: Model initialization failed:`, error);
|
||||
session = null; // 清理session以防部分初始化
|
||||
modelInputNames = null;
|
||||
// 将错误信息序列化,因为Error对象本身可能无法直接postMessage
|
||||
throw new Error(`Worker: Model initialization failed - ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 优化的缓冲区管理函数
|
||||
function getOrCreateBuffer(name, requiredLength, type = BigInt64Array) {
|
||||
if (!reusableBuffers[name] || reusableBuffers[name].length < requiredLength) {
|
||||
reusableBuffers[name] = new type(requiredLength);
|
||||
workerStats.memoryAllocations++;
|
||||
}
|
||||
return reusableBuffers[name];
|
||||
}
|
||||
|
||||
// 优化的批处理推理函数
|
||||
async function runBatchInference(batchData) {
|
||||
if (!session) {
|
||||
throw new Error("Worker: Session not initialized. Call 'initializeModel' first.");
|
||||
}
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
try {
|
||||
const feeds = {};
|
||||
const batchSize = batchData.dims.input_ids[0];
|
||||
const seqLength = batchData.dims.input_ids[1];
|
||||
|
||||
// 优化:复用缓冲区,减少内存分配
|
||||
const inputIdsLength = batchData.input_ids.length;
|
||||
const attentionMaskLength = batchData.attention_mask.length;
|
||||
|
||||
// 复用或创建 BigInt64Array 缓冲区
|
||||
const inputIdsBuffer = getOrCreateBuffer('inputIds', inputIdsLength);
|
||||
const attentionMaskBuffer = getOrCreateBuffer('attentionMask', attentionMaskLength);
|
||||
|
||||
// 批量填充数据(避免 map 操作)
|
||||
for (let i = 0; i < inputIdsLength; i++) {
|
||||
inputIdsBuffer[i] = BigInt(batchData.input_ids[i]);
|
||||
}
|
||||
for (let i = 0; i < attentionMaskLength; i++) {
|
||||
attentionMaskBuffer[i] = BigInt(batchData.attention_mask[i]);
|
||||
}
|
||||
|
||||
feeds['input_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
inputIdsBuffer.slice(0, inputIdsLength),
|
||||
batchData.dims.input_ids,
|
||||
);
|
||||
feeds['attention_mask'] = new ort.Tensor(
|
||||
'int64',
|
||||
attentionMaskBuffer.slice(0, attentionMaskLength),
|
||||
batchData.dims.attention_mask,
|
||||
);
|
||||
|
||||
// 处理 token_type_ids - 只有当模型需要时才提供
|
||||
if (modelInputNames && modelInputNames.includes('token_type_ids')) {
|
||||
if (batchData.token_type_ids && batchData.dims.token_type_ids) {
|
||||
const tokenTypeIdsLength = batchData.token_type_ids.length;
|
||||
const tokenTypeIdsBuffer = getOrCreateBuffer('tokenTypeIds', tokenTypeIdsLength);
|
||||
|
||||
for (let i = 0; i < tokenTypeIdsLength; i++) {
|
||||
tokenTypeIdsBuffer[i] = BigInt(batchData.token_type_ids[i]);
|
||||
}
|
||||
|
||||
feeds['token_type_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
tokenTypeIdsBuffer.slice(0, tokenTypeIdsLength),
|
||||
batchData.dims.token_type_ids,
|
||||
);
|
||||
} else {
|
||||
// 创建默认的全零 token_type_ids
|
||||
const tokenTypeIdsBuffer = getOrCreateBuffer('tokenTypeIds', inputIdsLength);
|
||||
tokenTypeIdsBuffer.fill(0n, 0, inputIdsLength);
|
||||
|
||||
feeds['token_type_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
tokenTypeIdsBuffer.slice(0, inputIdsLength),
|
||||
batchData.dims.input_ids,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log('Worker: Skipping token_type_ids as model does not require it');
|
||||
}
|
||||
|
||||
// 执行批处理推理
|
||||
const results = await session.run(feeds);
|
||||
const outputTensor = results.last_hidden_state || results[Object.keys(results)[0]];
|
||||
|
||||
// 使用 Transferable Objects 优化数据传输
|
||||
const outputData = new Float32Array(outputTensor.data);
|
||||
|
||||
// 更新统计信息
|
||||
workerStats.totalInferences += batchSize; // 批处理计算多个推理
|
||||
const inferenceTime = performance.now() - startTime;
|
||||
workerStats.totalInferenceTime += inferenceTime;
|
||||
workerStats.averageInferenceTime = workerStats.totalInferenceTime / workerStats.totalInferences;
|
||||
|
||||
return {
|
||||
status: 'success',
|
||||
output: {
|
||||
data: outputData,
|
||||
dims: outputTensor.dims,
|
||||
batchSize: batchSize,
|
||||
seqLength: seqLength,
|
||||
},
|
||||
transferList: [outputData.buffer],
|
||||
stats: {
|
||||
inferenceTime,
|
||||
totalInferences: workerStats.totalInferences,
|
||||
averageInferenceTime: workerStats.averageInferenceTime,
|
||||
memoryAllocations: workerStats.memoryAllocations,
|
||||
batchSize: batchSize,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Worker: Batch inference failed:', error);
|
||||
throw new Error(`Worker: Batch inference failed - ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function runInference(inputData) {
|
||||
if (!session) {
|
||||
throw new Error("Worker: Session not initialized. Call 'initializeModel' first.");
|
||||
}
|
||||
|
||||
const startTime = performance.now();
|
||||
|
||||
try {
|
||||
const feeds = {};
|
||||
|
||||
// 优化:复用缓冲区,减少内存分配
|
||||
const inputIdsLength = inputData.input_ids.length;
|
||||
const attentionMaskLength = inputData.attention_mask.length;
|
||||
|
||||
// 复用或创建 BigInt64Array 缓冲区
|
||||
const inputIdsBuffer = getOrCreateBuffer('inputIds', inputIdsLength);
|
||||
const attentionMaskBuffer = getOrCreateBuffer('attentionMask', attentionMaskLength);
|
||||
|
||||
// 填充数据(避免 map 操作)
|
||||
for (let i = 0; i < inputIdsLength; i++) {
|
||||
inputIdsBuffer[i] = BigInt(inputData.input_ids[i]);
|
||||
}
|
||||
for (let i = 0; i < attentionMaskLength; i++) {
|
||||
attentionMaskBuffer[i] = BigInt(inputData.attention_mask[i]);
|
||||
}
|
||||
|
||||
feeds['input_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
inputIdsBuffer.slice(0, inputIdsLength),
|
||||
inputData.dims.input_ids,
|
||||
);
|
||||
feeds['attention_mask'] = new ort.Tensor(
|
||||
'int64',
|
||||
attentionMaskBuffer.slice(0, attentionMaskLength),
|
||||
inputData.dims.attention_mask,
|
||||
);
|
||||
|
||||
// 处理 token_type_ids - 只有当模型需要时才提供
|
||||
if (modelInputNames && modelInputNames.includes('token_type_ids')) {
|
||||
if (inputData.token_type_ids && inputData.dims.token_type_ids) {
|
||||
const tokenTypeIdsLength = inputData.token_type_ids.length;
|
||||
const tokenTypeIdsBuffer = getOrCreateBuffer('tokenTypeIds', tokenTypeIdsLength);
|
||||
|
||||
for (let i = 0; i < tokenTypeIdsLength; i++) {
|
||||
tokenTypeIdsBuffer[i] = BigInt(inputData.token_type_ids[i]);
|
||||
}
|
||||
|
||||
feeds['token_type_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
tokenTypeIdsBuffer.slice(0, tokenTypeIdsLength),
|
||||
inputData.dims.token_type_ids,
|
||||
);
|
||||
} else {
|
||||
// 创建默认的全零 token_type_ids
|
||||
const tokenTypeIdsBuffer = getOrCreateBuffer('tokenTypeIds', inputIdsLength);
|
||||
tokenTypeIdsBuffer.fill(0n, 0, inputIdsLength);
|
||||
|
||||
feeds['token_type_ids'] = new ort.Tensor(
|
||||
'int64',
|
||||
tokenTypeIdsBuffer.slice(0, inputIdsLength),
|
||||
inputData.dims.input_ids,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log('Worker: Skipping token_type_ids as model does not require it');
|
||||
}
|
||||
|
||||
const results = await session.run(feeds);
|
||||
const outputTensor = results.last_hidden_state || results[Object.keys(results)[0]];
|
||||
|
||||
// 使用 Transferable Objects 优化数据传输
|
||||
const outputData = new Float32Array(outputTensor.data);
|
||||
|
||||
// 更新统计信息
|
||||
workerStats.totalInferences++;
|
||||
const inferenceTime = performance.now() - startTime;
|
||||
workerStats.totalInferenceTime += inferenceTime;
|
||||
workerStats.averageInferenceTime = workerStats.totalInferenceTime / workerStats.totalInferences;
|
||||
|
||||
return {
|
||||
status: 'success',
|
||||
output: {
|
||||
data: outputData, // 直接返回 Float32Array
|
||||
dims: outputTensor.dims,
|
||||
},
|
||||
transferList: [outputData.buffer], // 标记为可转移对象
|
||||
stats: {
|
||||
inferenceTime,
|
||||
totalInferences: workerStats.totalInferences,
|
||||
averageInferenceTime: workerStats.averageInferenceTime,
|
||||
memoryAllocations: workerStats.memoryAllocations,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Worker: Inference failed:', error);
|
||||
throw new Error(`Worker: Inference failed - ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
self.onmessage = async (event) => {
|
||||
const { id, type, payload } = event.data;
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case 'init':
|
||||
// Support both modelPath (URL string) and modelData (ArrayBuffer)
|
||||
const modelInput = payload.modelData || payload.modelPath;
|
||||
await initializeModel(modelInput, payload.numThreads, payload.executionProviders);
|
||||
self.postMessage({ id, type: 'init_complete', status: 'success' });
|
||||
break;
|
||||
case 'infer':
|
||||
const result = await runInference(payload);
|
||||
// 使用 Transferable Objects 优化数据传输
|
||||
self.postMessage(
|
||||
{
|
||||
id,
|
||||
type: 'infer_complete',
|
||||
status: 'success',
|
||||
payload: result.output,
|
||||
stats: result.stats,
|
||||
},
|
||||
result.transferList || [],
|
||||
);
|
||||
break;
|
||||
case 'batchInfer':
|
||||
const batchResult = await runBatchInference(payload);
|
||||
// 使用 Transferable Objects 优化数据传输
|
||||
self.postMessage(
|
||||
{
|
||||
id,
|
||||
type: 'batchInfer_complete',
|
||||
status: 'success',
|
||||
payload: batchResult.output,
|
||||
stats: batchResult.stats,
|
||||
},
|
||||
batchResult.transferList || [],
|
||||
);
|
||||
break;
|
||||
case 'getStats':
|
||||
self.postMessage({
|
||||
id,
|
||||
type: 'stats_complete',
|
||||
status: 'success',
|
||||
payload: workerStats,
|
||||
});
|
||||
break;
|
||||
case 'clearBuffers':
|
||||
// 清理缓冲区,释放内存
|
||||
reusableBuffers = {
|
||||
inputIds: null,
|
||||
attentionMask: null,
|
||||
tokenTypeIds: null,
|
||||
};
|
||||
workerStats.memoryAllocations = 0;
|
||||
self.postMessage({
|
||||
id,
|
||||
type: 'clear_complete',
|
||||
status: 'success',
|
||||
payload: { message: 'Buffers cleared' },
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.warn(`Worker: Unknown message type: ${type}`);
|
||||
self.postMessage({
|
||||
id,
|
||||
type: 'error',
|
||||
status: 'error',
|
||||
payload: { message: `Unknown message type: ${type}` },
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// 确保将错误作为普通对象发送,因为Error对象本身可能无法正确序列化
|
||||
self.postMessage({
|
||||
id,
|
||||
type: `${type}_error`, // 如 'init_error' 或 'infer_error'
|
||||
status: 'error',
|
||||
payload: {
|
||||
message: error.message,
|
||||
stack: error.stack, // 可选,用于调试
|
||||
name: error.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 319 KiB |
Reference in New Issue
Block a user