Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "GitHub Copilot Browser",
"version": "0.1.0",
"version": "0.3.0",
"description": "Your AI copilot for the web",
"permissions": [
"sidePanel",
Expand Down
182 changes: 147 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "github-copilot-browser",
"private": true,
"version": "0.1.0",
"version": "0.3.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
"preview": "vite preview",
"postinstall": "node scripts/patch-vscode-jsonrpc.mjs"
},
"dependencies": {
"@github/copilot-sdk": "file:../copilot-sdk/nodejs",
"@github/copilot-sdk": "^0.1.32",
"highlight.js": "^11.11.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
25 changes: 25 additions & 0 deletions scripts/patch-vscode-jsonrpc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Patch vscode-jsonrpc package.json to add ESM-compatible exports map.
// vscode-jsonrpc@8.x doesn't define "exports", so ESM imports like
// "vscode-jsonrpc/node" (used by @github/copilot-sdk) fail.
import { readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = join(__dirname, '..', 'node_modules', 'vscode-jsonrpc', 'package.json');

try {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
if (!pkg.exports) {
pkg.exports = {
'.': { types: './lib/common/api.d.ts', default: './lib/common/api.js' },
'./node': { node: './lib/node/main.js', types: './lib/node/main.d.ts', default: './lib/node/main.js' },
'./node.js': { node: './lib/node/main.js', types: './lib/node/main.d.ts', default: './lib/node/main.js' },
'./browser': { types: './lib/browser/main.d.ts', browser: './lib/browser/main.js' },
};
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n', 'utf8');
console.log('[postinstall] Patched vscode-jsonrpc exports for ESM compatibility');
}
} catch (e) {
// Silently ignore if vscode-jsonrpc isn't installed yet
}
4 changes: 2 additions & 2 deletions scripts/register-host.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ setlocal
set HOST_NAME=com.github.copilot.browser
set SCRIPT_DIR=%~dp0
set PROJECT_DIR=%SCRIPT_DIR%..
set HOST_PATH=%PROJECT_DIR%\src\host\host.mjs
set WRAPPER_PATH=%PROJECT_DIR%\src\host\host-wrapper.bat

set EXTENSION_ID=%1
if "%EXTENSION_ID%"=="" (
Expand All @@ -24,7 +24,7 @@ if not exist "%CHROME_DIR%" mkdir "%CHROME_DIR%"
echo {> "%CHROME_DIR%\%HOST_NAME%.json"
echo "name": "%HOST_NAME%",>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "description": "GitHub Copilot Browser Extension Native Messaging Host",>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "path": "node %HOST_PATH:\=\\%",>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "path": "%WRAPPER_PATH:\=\\%",>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "type": "stdio",>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "allowed_origins": [>> "%CHROME_DIR%\%HOST_NAME%.json"
echo "chrome-extension://%EXTENSION_ID%/">> "%CHROME_DIR%\%HOST_NAME%.json"
Expand Down
27 changes: 25 additions & 2 deletions src/background/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ console.log('[Background] Service worker loaded');

// Track panel connections
const panelPorts: chrome.runtime.Port[] = [];
let cachedModels: { models: Array<{ id: string; name: string }> } | null = null;

// Listen for connections from the side panel
chrome.runtime.onConnect.addListener((port) => {
Expand All @@ -30,6 +31,11 @@ chrome.runtime.onConnect.addListener((port) => {
type: 'CONNECTION_STATUS_CHANGED',
payload: { status: nativeMessaging.status, error: nativeMessaging.lastError },
});

// Send cached model list if available
if (cachedModels) {
sendToPanel(port, { type: 'AVAILABLE_MODELS', payload: cachedModels });
}
}
});

Expand Down Expand Up @@ -58,11 +64,11 @@ async function handlePanelMessage(message: PanelMessage, port: chrome.runtime.Po
}

case 'SEND_CHAT_MESSAGE': {
const { content, sessionId } = message.payload;
const { content, sessionId, model } = message.payload;
try {
nativeMessaging.send({
type: 'SEND_CHAT_MESSAGE',
payload: { content },
payload: { content, ...(model && { model }) },
});
} catch (error) {
sendToPanel(port, {
Expand All @@ -76,6 +82,14 @@ async function handlePanelMessage(message: PanelMessage, port: chrome.runtime.Po
break;
}

case 'CANCEL_REQUEST':
try {
nativeMessaging.send({ type: 'CANCEL_REQUEST' });
} catch {
// Host may not support cancel — ignore
}
break;

case 'EXECUTE_TOOL':
break;
}
Expand Down Expand Up @@ -152,6 +166,15 @@ nativeMessaging.onMessage((message: any) => {
case 'TOOL_EXECUTION_COMPLETE':
// Already handled via TOOL_CALL_REQUEST flow
break;

// Available models from the Copilot SDK
case 'AVAILABLE_MODELS':
cachedModels = { models: message.payload.models };
sendToPanels({
type: 'AVAILABLE_MODELS',
payload: cachedModels,
});
break;
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/host/host-wrapper.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
node "%~dp0host.mjs"
Loading