feat(chrome-qwen-bridge): 🔥 init chrome qwen code bridge

This commit is contained in:
yiliang114
2025-12-20 00:58:41 +08:00
parent a92be72e88
commit a60c5c6697
57 changed files with 9489 additions and 0 deletions

View File

@@ -0,0 +1,385 @@
/* Popup Styles for Qwen CLI Bridge */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 400px;
min-height: 500px;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
color: #333;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.container {
background: white;
min-height: 500px;
display: flex;
flex-direction: column;
}
/* Header */
.header {
padding: 16px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
display: flex;
align-items: center;
gap: 8px;
}
.logo .icon {
width: 24px;
height: 24px;
}
.logo h1 {
font-size: 18px;
font-weight: 600;
}
/* Status Indicator */
.status-indicator {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
background: rgba(255, 255, 255, 0.2);
border-radius: 12px;
font-size: 12px;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #ff4444;
animation: pulse 2s infinite;
}
.status-indicator.connected .status-dot {
background: #44ff44;
}
.status-indicator.connecting .status-dot {
background: #ffaa44;
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
/* Sections */
.section {
padding: 16px;
border-bottom: 1px solid #e5e5e5;
}
.section:last-of-type {
border-bottom: none;
}
.section h2 {
font-size: 14px;
font-weight: 600;
color: #666;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 12px;
}
/* Buttons */
.btn {
padding: 8px 16px;
border: none;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn-secondary {
background: #f5f5f5;
color: #333;
}
.btn-secondary:hover:not(:disabled) {
background: #e5e5e5;
}
.btn-small {
padding: 4px 12px;
font-size: 12px;
}
.btn-icon {
width: 32px;
height: 32px;
padding: 4px;
border: none;
background: transparent;
cursor: pointer;
border-radius: 4px;
transition: background 0.2s;
}
.btn-icon:hover {
background: #f5f5f5;
}
.btn-icon svg {
width: 100%;
height: 100%;
stroke: #666;
}
/* Connection Section */
.connection-controls {
display: flex;
gap: 8px;
}
.error-message {
margin-top: 8px;
padding: 8px;
background: #fee;
color: #c00;
border-radius: 4px;
font-size: 12px;
}
/* Action Buttons */
.action-buttons {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
.action-btn {
padding: 12px;
border: 1px solid #e5e5e5;
border-radius: 8px;
background: white;
cursor: pointer;
transition: all 0.2s;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
font-size: 12px;
color: #666;
}
.action-btn:hover:not(:disabled) {
border-color: #667eea;
background: #f8f9ff;
color: #667eea;
}
.action-btn:hover:not(:disabled) .action-icon {
stroke: #667eea;
}
.action-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.action-icon {
width: 24px;
height: 24px;
stroke: #999;
}
/* Response Section */
.response-container {
background: #f9f9f9;
border-radius: 8px;
overflow: hidden;
}
.response-header {
padding: 8px 12px;
background: #f0f0f0;
border-bottom: 1px solid #e0e0e0;
display: flex;
justify-content: space-between;
align-items: center;
}
.response-type {
font-size: 12px;
font-weight: 600;
color: #666;
}
.response-content {
padding: 12px;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 12px;
color: #333;
max-height: 200px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-all;
}
/* Settings Section */
.settings-section details {
cursor: pointer;
}
.settings-section summary {
font-size: 14px;
font-weight: 600;
color: #666;
text-transform: uppercase;
letter-spacing: 0.5px;
padding: 4px 0;
user-select: none;
}
.settings-section summary:hover {
color: #667eea;
}
.settings-content {
margin-top: 12px;
}
.setting-item {
margin-bottom: 12px;
}
.setting-item label {
display: block;
margin-bottom: 4px;
font-size: 12px;
color: #666;
}
.setting-item input[type="text"],
.setting-item input[type="number"] {
width: 100%;
padding: 6px 8px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
}
.setting-item input[type="checkbox"] {
margin-right: 8px;
}
/* Footer */
.footer {
padding: 12px 16px;
background: #f9f9f9;
border-top: 1px solid #e5e5e5;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
font-size: 12px;
color: #999;
margin-top: auto;
}
.footer a {
color: #667eea;
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
.version {
color: #bbb;
}
/* Scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
/* Loading state */
.loading {
position: relative;
pointer-events: none;
}
.loading::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(255, 255, 255, 0.8);
display: flex;
align-items: center;
justify-content: center;
}
/* Animations */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.fade-in {
animation: fadeIn 0.3s ease;
}

View File

@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Qwen CLI Bridge</title>
<link rel="stylesheet" href="popup.css">
</head>
<body>
<div class="container">
<!-- Header -->
<header class="header">
<div class="logo">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg>
<h1>Qwen CLI Bridge</h1>
</div>
<div class="status-indicator" id="statusIndicator">
<span class="status-dot"></span>
<span class="status-text">Disconnected</span>
</div>
</header>
<!-- Connection Section -->
<section class="section connection-section">
<h2>Connection</h2>
<div class="connection-controls">
<button id="connectBtn" class="btn btn-primary">
Connect to Qwen CLI
</button>
<button id="startQwenBtn" class="btn btn-secondary" disabled>
Start Qwen CLI
</button>
</div>
<div id="connectionError" class="error-message" style="display: none;"></div>
</section>
<!-- Actions Section -->
<section class="section actions-section">
<h2>Quick Actions</h2>
<div class="action-buttons">
<button id="extractDataBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
Extract Page Data
</button>
<button id="captureScreenBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
Capture Screenshot
</button>
<button id="analyzePageBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
</svg>
Analyze with AI
</button>
<button id="getSelectedBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
Send Selected Text
</button>
<button id="networkLogsBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.141 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0" />
</svg>
Network Logs
</button>
<button id="consoleLogsBtn" class="action-btn" disabled>
<svg class="action-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
Console Logs
</button>
</div>
</section>
<!-- Response Section -->
<section class="section response-section" id="responseSection" style="display: none;">
<h2>Response</h2>
<div class="response-container">
<div class="response-header">
<span id="responseType" class="response-type"></span>
<button id="copyResponseBtn" class="btn-icon" title="Copy to clipboard">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
</button>
</div>
<pre id="responseContent" class="response-content"></pre>
</div>
</section>
<!-- Settings Section -->
<section class="section settings-section">
<details>
<summary>Advanced Settings</summary>
<div class="settings-content">
<div class="setting-item">
<label for="mcpServers">MCP Servers:</label>
<input type="text" id="mcpServers" placeholder="chrome-devtools,playwright" />
</div>
<div class="setting-item">
<label for="httpPort">HTTP Port:</label>
<input type="number" id="httpPort" placeholder="8080" value="8080" />
</div>
<div class="setting-item">
<label for="autoConnect">
<input type="checkbox" id="autoConnect" />
Auto-connect on startup
</label>
</div>
<button id="saveSettingsBtn" class="btn btn-small">Save Settings</button>
</div>
</details>
</section>
<!-- Footer -->
<footer class="footer">
<a href="#" id="openOptionsBtn">Options</a>
<span></span>
<a href="#" id="helpBtn">Help</a>
<span></span>
<span class="version">v1.0.0</span>
</footer>
</div>
<script src="popup.js"></script>
</body>
</html>

View File

@@ -0,0 +1,477 @@
/**
* Popup Script for Qwen CLI Bridge
* Handles UI interactions and communication with background script
*/
// UI Elements
const statusIndicator = document.getElementById('statusIndicator');
const statusText = statusIndicator.querySelector('.status-text');
const connectBtn = document.getElementById('connectBtn');
const startQwenBtn = document.getElementById('startQwenBtn');
const connectionError = document.getElementById('connectionError');
const responseSection = document.getElementById('responseSection');
const responseType = document.getElementById('responseType');
const responseContent = document.getElementById('responseContent');
const copyResponseBtn = document.getElementById('copyResponseBtn');
// Action buttons
const extractDataBtn = document.getElementById('extractDataBtn');
const captureScreenBtn = document.getElementById('captureScreenBtn');
const analyzePageBtn = document.getElementById('analyzePageBtn');
const getSelectedBtn = document.getElementById('getSelectedBtn');
const networkLogsBtn = document.getElementById('networkLogsBtn');
const consoleLogsBtn = document.getElementById('consoleLogsBtn');
// Settings
const mcpServersInput = document.getElementById('mcpServers');
const httpPortInput = document.getElementById('httpPort');
const autoConnectCheckbox = document.getElementById('autoConnect');
const saveSettingsBtn = document.getElementById('saveSettingsBtn');
// Footer links
const openOptionsBtn = document.getElementById('openOptionsBtn');
const helpBtn = document.getElementById('helpBtn');
// State
let isConnected = false;
let qwenStatus = 'disconnected';
// Initialize popup
document.addEventListener('DOMContentLoaded', async () => {
await loadSettings();
await checkConnectionStatus();
// Auto-connect if enabled
const settings = await chrome.storage.local.get(['autoConnect']);
if (settings.autoConnect && !isConnected) {
connectToQwen();
}
});
// Load saved settings
async function loadSettings() {
const settings = await chrome.storage.local.get([
'mcpServers',
'httpPort',
'autoConnect'
]);
if (settings.mcpServers) {
mcpServersInput.value = settings.mcpServers;
}
if (settings.httpPort) {
httpPortInput.value = settings.httpPort;
}
if (settings.autoConnect !== undefined) {
autoConnectCheckbox.checked = settings.autoConnect;
}
}
// Save settings
saveSettingsBtn.addEventListener('click', async () => {
await chrome.storage.local.set({
mcpServers: mcpServersInput.value,
httpPort: parseInt(httpPortInput.value) || 8080,
autoConnect: autoConnectCheckbox.checked
});
saveSettingsBtn.textContent = 'Saved!';
setTimeout(() => {
saveSettingsBtn.textContent = 'Save Settings';
}, 2000);
});
// Check connection status
async function checkConnectionStatus() {
try {
const response = await chrome.runtime.sendMessage({ type: 'GET_STATUS' });
updateConnectionStatus(response.connected, response.status);
} catch (error) {
updateConnectionStatus(false, 'disconnected');
}
}
// Update UI based on connection status
function updateConnectionStatus(connected, status) {
isConnected = connected;
qwenStatus = status;
// Update status indicator
statusIndicator.classList.toggle('connected', connected);
statusIndicator.classList.toggle('connecting', status === 'connecting');
statusText.textContent = getStatusText(status);
// Update button states
connectBtn.textContent = connected ? 'Disconnect' : 'Connect to Qwen CLI';
connectBtn.classList.toggle('btn-danger', connected);
startQwenBtn.disabled = !connected || status === 'running';
// Enable/disable action buttons
const actionButtons = [
extractDataBtn,
captureScreenBtn,
analyzePageBtn,
getSelectedBtn,
networkLogsBtn,
consoleLogsBtn
];
actionButtons.forEach(btn => {
btn.disabled = !connected || status !== 'running';
});
}
// Get human-readable status text
function getStatusText(status) {
switch (status) {
case 'connected':
return 'Connected';
case 'running':
return 'Qwen CLI Running';
case 'connecting':
return 'Connecting...';
case 'disconnected':
return 'Disconnected';
case 'stopped':
return 'Qwen CLI Stopped';
default:
return 'Unknown';
}
}
// Connect button handler
connectBtn.addEventListener('click', () => {
if (isConnected) {
disconnectFromQwen();
} else {
connectToQwen();
}
});
// Connect to Qwen CLI
async function connectToQwen() {
updateConnectionStatus(false, 'connecting');
connectionError.style.display = 'none';
try {
const response = await chrome.runtime.sendMessage({ type: 'CONNECT' });
if (response.success) {
updateConnectionStatus(true, response.status);
} else {
throw new Error(response.error || 'Connection failed');
}
} catch (error) {
console.error('Connection error:', error);
connectionError.textContent = `Error: ${error.message}`;
connectionError.style.display = 'block';
updateConnectionStatus(false, 'disconnected');
}
}
// Disconnect from Qwen CLI
function disconnectFromQwen() {
// Simply close the popup to disconnect
// The native port will be closed when the extension unloads
updateConnectionStatus(false, 'disconnected');
window.close();
}
// Start Qwen CLI button handler
startQwenBtn.addEventListener('click', async () => {
startQwenBtn.disabled = true;
startQwenBtn.textContent = 'Starting...';
try {
const settings = await chrome.storage.local.get(['mcpServers', 'httpPort']);
const response = await chrome.runtime.sendMessage({
type: 'START_QWEN_CLI',
config: {
mcpServers: settings.mcpServers ? settings.mcpServers.split(',').map(s => s.trim()) : [],
httpPort: settings.httpPort || 8080
}
});
if (response.success) {
updateConnectionStatus(true, 'running');
showResponse('Qwen CLI Started', response.data || 'Successfully started');
} else {
throw new Error(response.error || 'Failed to start Qwen CLI');
}
} catch (error) {
console.error('Start error:', error);
connectionError.textContent = `Error: ${error.message}`;
connectionError.style.display = 'block';
} finally {
startQwenBtn.textContent = 'Start Qwen CLI';
}
});
// Extract page data button handler
extractDataBtn.addEventListener('click', async () => {
try {
showLoading('Extracting page data...');
const response = await chrome.runtime.sendMessage({
type: 'EXTRACT_PAGE_DATA'
});
if (response.success) {
// Send to Qwen CLI
const qwenResponse = await chrome.runtime.sendMessage({
type: 'SEND_TO_QWEN',
action: 'analyze_page',
data: response.data
});
if (qwenResponse.success) {
showResponse('Page Analysis', qwenResponse.data);
} else {
throw new Error(qwenResponse.error);
}
} else {
throw new Error(response.error);
}
} catch (error) {
showError(`Failed to extract data: ${error.message}`);
}
});
// Capture screenshot button handler
captureScreenBtn.addEventListener('click', async () => {
try {
showLoading('Capturing screenshot...');
const response = await chrome.runtime.sendMessage({
type: 'CAPTURE_SCREENSHOT'
});
if (response.success) {
// Send to Qwen CLI
const qwenResponse = await chrome.runtime.sendMessage({
type: 'SEND_TO_QWEN',
action: 'analyze_screenshot',
data: {
screenshot: response.data,
url: (await chrome.tabs.query({ active: true, currentWindow: true }))[0].url
}
});
if (qwenResponse.success) {
showResponse('Screenshot Analysis', qwenResponse.data);
} else {
throw new Error(qwenResponse.error);
}
} else {
throw new Error(response.error);
}
} catch (error) {
showError(`Failed to capture screenshot: ${error.message}`);
}
});
// Analyze page with AI button handler
analyzePageBtn.addEventListener('click', async () => {
try {
showLoading('Analyzing page with AI...');
// First extract page data
const extractResponse = await chrome.runtime.sendMessage({
type: 'EXTRACT_PAGE_DATA'
});
if (!extractResponse.success) {
throw new Error(extractResponse.error);
}
// Send to Qwen for AI analysis
const qwenResponse = await chrome.runtime.sendMessage({
type: 'SEND_TO_QWEN',
action: 'ai_analyze',
data: {
pageData: extractResponse.data,
prompt: 'Please analyze this webpage and provide insights about its content, purpose, and any notable features.'
}
});
if (qwenResponse.success) {
showResponse('AI Analysis', qwenResponse.data);
} else {
throw new Error(qwenResponse.error);
}
} catch (error) {
showError(`Analysis failed: ${error.message}`);
}
});
// Get selected text button handler
getSelectedBtn.addEventListener('click', async () => {
try {
showLoading('Getting selected text...');
// Get active tab
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
const tab = tabs[0];
if (!tab) {
throw new Error('No active tab found');
}
// Get selected text from content script
const response = await chrome.tabs.sendMessage(tab.id, {
type: 'GET_SELECTED_TEXT'
});
if (response.success && response.data) {
// Send to Qwen CLI
const qwenResponse = await chrome.runtime.sendMessage({
type: 'SEND_TO_QWEN',
action: 'process_text',
data: {
text: response.data,
context: 'selected_text'
}
});
if (qwenResponse.success) {
showResponse('Selected Text Processed', qwenResponse.data);
} else {
throw new Error(qwenResponse.error);
}
} else {
showError('No text selected. Please select some text on the page first.');
}
} catch (error) {
showError(`Failed to process selected text: ${error.message}`);
}
});
// Network logs button handler
networkLogsBtn.addEventListener('click', async () => {
try {
showLoading('Getting network logs...');
const response = await chrome.runtime.sendMessage({
type: 'GET_NETWORK_LOGS'
});
if (response.success) {
showResponse('Network Logs', JSON.stringify(response.data, null, 2));
} else {
throw new Error(response.error);
}
} catch (error) {
showError(`Failed to get network logs: ${error.message}`);
}
});
// Console logs button handler
consoleLogsBtn.addEventListener('click', async () => {
try {
showLoading('Getting console logs...');
// Get active tab
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
const tab = tabs[0];
if (!tab) {
throw new Error('No active tab found');
}
// Get console logs from content script
const response = await chrome.tabs.sendMessage(tab.id, {
type: 'EXTRACT_DATA'
});
if (response.success) {
const consoleLogs = response.data.consoleLogs || [];
if (consoleLogs.length > 0) {
showResponse('Console Logs', JSON.stringify(consoleLogs, null, 2));
} else {
showResponse('Console Logs', 'No console logs captured');
}
} else {
throw new Error(response.error);
}
} catch (error) {
showError(`Failed to get console logs: ${error.message}`);
}
});
// Copy response button handler
copyResponseBtn.addEventListener('click', () => {
const text = responseContent.textContent;
navigator.clipboard.writeText(text).then(() => {
const originalTitle = copyResponseBtn.title;
copyResponseBtn.title = 'Copied!';
setTimeout(() => {
copyResponseBtn.title = originalTitle;
}, 2000);
});
});
// Footer link handlers
openOptionsBtn.addEventListener('click', (e) => {
e.preventDefault();
// Use try-catch to handle potential errors
try {
chrome.runtime.openOptionsPage(() => {
if (chrome.runtime.lastError) {
// If opening options page fails, open it in a new tab as fallback
console.error('Error opening options page:', chrome.runtime.lastError);
chrome.tabs.create({
url: chrome.runtime.getURL('options/options.html')
});
}
});
} catch (error) {
console.error('Failed to open options page:', error);
// Fallback: open in new tab
chrome.tabs.create({
url: chrome.runtime.getURL('options/options.html')
});
}
});
helpBtn.addEventListener('click', (e) => {
e.preventDefault();
chrome.tabs.create({
url: 'https://github.com/QwenLM/qwen-code/tree/main/packages/chrome-qwen-bridge'
});
});
// Helper functions
function showLoading(message) {
responseSection.style.display = 'block';
responseType.textContent = 'Loading';
responseContent.textContent = message;
responseSection.classList.add('loading');
}
function showResponse(type, content) {
responseSection.style.display = 'block';
responseType.textContent = type;
responseContent.textContent = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
responseSection.classList.remove('loading');
responseSection.classList.add('fade-in');
}
function showError(message) {
responseSection.style.display = 'block';
responseType.textContent = 'Error';
responseType.style.color = '#c00';
responseContent.textContent = message;
responseSection.classList.remove('loading');
}
// Listen for status updates from background
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === 'STATUS_UPDATE') {
updateConnectionStatus(message.status !== 'disconnected', message.status);
} else if (message.type === 'QWEN_EVENT') {
// Handle events from Qwen CLI
console.log('Qwen event received:', message.event);
// Could update UI based on event
}
});