converse-mcp-server 2.20.5 → 2.20.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/providers/copilot.js +69 -6
package/package.json
CHANGED
package/src/providers/copilot.js
CHANGED
|
@@ -9,9 +9,13 @@
|
|
|
9
9
|
* - Manages a singleton CopilotClient (spawns CLI process via JSON-RPC)
|
|
10
10
|
* - Creates a fresh CopilotSession per request, destroyed after each request
|
|
11
11
|
* - Bridges SDK push-based events to pull-based async generator for streaming
|
|
12
|
-
* - Requires
|
|
12
|
+
* - Requires GitHub CLI authenticated (gh auth login) with active Copilot subscription
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import { createRequire } from 'module';
|
|
16
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
17
|
+
import { dirname, join } from 'path';
|
|
18
|
+
import { fileURLToPath } from 'url';
|
|
15
19
|
import { debugLog, debugError } from '../utils/console.js';
|
|
16
20
|
import { ProviderError, ErrorCodes, StopReasons } from './interface.js';
|
|
17
21
|
|
|
@@ -290,16 +294,75 @@ function isCopilotSDKAvailable() {
|
|
|
290
294
|
return _sdkAvailable;
|
|
291
295
|
}
|
|
292
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Patch vscode-jsonrpc's package.json to add ESM-compatible exports.
|
|
299
|
+
* The @github/copilot-sdk imports "vscode-jsonrpc/node" (extensionless) and
|
|
300
|
+
* "vscode-jsonrpc/node.js" (with extension). Without an exports map, Node.js
|
|
301
|
+
* strict ESM resolution fails on both forms. Adding an exports field once
|
|
302
|
+
* also requires "./node.js" since exports blocks unlisted subpaths.
|
|
303
|
+
* Runs once, skips silently on failure (e.g. read-only node_modules).
|
|
304
|
+
*/
|
|
305
|
+
let _jsonrpcPatched = false;
|
|
306
|
+
function ensureVscodeJsonrpcExports() {
|
|
307
|
+
if (_jsonrpcPatched) return;
|
|
308
|
+
_jsonrpcPatched = true;
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
const sdkUrl = import.meta.resolve('@github/copilot-sdk');
|
|
312
|
+
const sdkDir = dirname(fileURLToPath(sdkUrl));
|
|
313
|
+
const sdkRequire = createRequire(join(sdkDir, '_resolve.js'));
|
|
314
|
+
|
|
315
|
+
let pkgJsonPath;
|
|
316
|
+
try {
|
|
317
|
+
pkgJsonPath = sdkRequire.resolve('vscode-jsonrpc/package.json');
|
|
318
|
+
} catch {
|
|
319
|
+
const mainPath = sdkRequire.resolve('vscode-jsonrpc');
|
|
320
|
+
let dir = dirname(mainPath);
|
|
321
|
+
for (let i = 0; i < 5; i++) {
|
|
322
|
+
const candidate = join(dir, 'package.json');
|
|
323
|
+
try {
|
|
324
|
+
const p = JSON.parse(readFileSync(candidate, 'utf-8'));
|
|
325
|
+
if (p.name === 'vscode-jsonrpc') {
|
|
326
|
+
pkgJsonPath = candidate;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
} catch { /* continue */ }
|
|
330
|
+
dir = dirname(dir);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (!pkgJsonPath) return;
|
|
335
|
+
|
|
336
|
+
const pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf-8'));
|
|
337
|
+
if (pkg.exports && pkg.exports['./node'] && pkg.exports['./node.js']) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
pkg.exports = {
|
|
342
|
+
'.': pkg.main || './lib/node/main.js',
|
|
343
|
+
'./node': './node.js',
|
|
344
|
+
'./node.js': './node.js',
|
|
345
|
+
'./browser': './browser.js',
|
|
346
|
+
'./browser.js': './browser.js',
|
|
347
|
+
};
|
|
348
|
+
writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, '\t') + '\n');
|
|
349
|
+
debugLog('[Copilot SDK] Patched vscode-jsonrpc exports for ESM compatibility');
|
|
350
|
+
} catch (err) {
|
|
351
|
+
debugLog('[Copilot SDK] Could not patch vscode-jsonrpc: %s', err.message);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
293
355
|
/**
|
|
294
356
|
* Dynamically import Copilot SDK (lazy loading)
|
|
295
357
|
*/
|
|
296
358
|
async function getCopilotSDK() {
|
|
359
|
+
ensureVscodeJsonrpcExports();
|
|
297
360
|
try {
|
|
298
361
|
const { CopilotClient } = await import('@github/copilot-sdk');
|
|
299
362
|
return CopilotClient;
|
|
300
363
|
} catch (error) {
|
|
301
364
|
throw new CopilotProviderError(
|
|
302
|
-
|
|
365
|
+
`Copilot SDK import failed: ${error.message}`,
|
|
303
366
|
ErrorCodes.API_ERROR,
|
|
304
367
|
error,
|
|
305
368
|
);
|
|
@@ -866,13 +929,13 @@ export const copilotProvider = {
|
|
|
866
929
|
debugError('[Copilot SDK] Execution error', error);
|
|
867
930
|
|
|
868
931
|
if (
|
|
869
|
-
error.message?.includes('authentication') ||
|
|
870
|
-
error.message?.includes('auth') ||
|
|
871
932
|
error.message?.includes('not authenticated') ||
|
|
872
|
-
error.message?.includes('
|
|
933
|
+
error.message?.includes('authentication failed') ||
|
|
934
|
+
error.message?.includes('not logged in') ||
|
|
935
|
+
error.message?.includes('login required')
|
|
873
936
|
) {
|
|
874
937
|
throw new CopilotProviderError(
|
|
875
|
-
|
|
938
|
+
`Copilot SDK authentication failed. Ensure GitHub CLI is authenticated (gh auth login) and you have an active Copilot subscription. Original error: ${error.message}`,
|
|
876
939
|
ErrorCodes.INVALID_API_KEY,
|
|
877
940
|
error,
|
|
878
941
|
);
|