converse-mcp-server 2.20.7 → 2.20.9
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 +19 -61
package/package.json
CHANGED
package/src/providers/copilot.js
CHANGED
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
* - Requires GitHub CLI authenticated (gh auth login) with active Copilot subscription
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
17
|
-
import { dirname, join } from 'path';
|
|
18
|
-
import { fileURLToPath } from 'url';
|
|
15
|
+
import { register } from 'node:module';
|
|
19
16
|
import { debugLog, debugError } from '../utils/console.js';
|
|
20
17
|
import { ProviderError, ErrorCodes, StopReasons } from './interface.js';
|
|
21
18
|
|
|
@@ -295,68 +292,27 @@ function isCopilotSDKAvailable() {
|
|
|
295
292
|
}
|
|
296
293
|
|
|
297
294
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* "vscode-jsonrpc/node
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* Runs once, skips silently on failure (e.g. read-only node_modules).
|
|
295
|
+
* Register a module resolution hook to fix the extensionless
|
|
296
|
+
* "vscode-jsonrpc/node" import in @github/copilot-sdk >=0.1.29.
|
|
297
|
+
* The SDK's session.js imports "vscode-jsonrpc/node" without a .js extension,
|
|
298
|
+
* which fails under Node.js strict ESM resolution. The hook rewrites it to
|
|
299
|
+
* "vscode-jsonrpc/node.js". Runs once, works regardless of package manager.
|
|
304
300
|
*/
|
|
305
|
-
let
|
|
306
|
-
function
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
}
|
|
301
|
+
let _hookRegistered = false;
|
|
302
|
+
function ensureJsonrpcResolveHook() {
|
|
303
|
+
if (_hookRegistered) return;
|
|
304
|
+
_hookRegistered = true;
|
|
305
|
+
register(`data:text/javascript,${encodeURIComponent(
|
|
306
|
+
'export function resolve(s,c,n){' +
|
|
307
|
+
'return s==="vscode-jsonrpc/node"?n("vscode-jsonrpc/node.js",c):n(s,c);}',
|
|
308
|
+
)}`);
|
|
353
309
|
}
|
|
354
310
|
|
|
355
311
|
/**
|
|
356
312
|
* Dynamically import Copilot SDK (lazy loading)
|
|
357
313
|
*/
|
|
358
314
|
async function getCopilotSDK() {
|
|
359
|
-
|
|
315
|
+
ensureJsonrpcResolveHook();
|
|
360
316
|
try {
|
|
361
317
|
const { CopilotClient } = await import('@github/copilot-sdk');
|
|
362
318
|
return CopilotClient;
|
|
@@ -717,10 +673,12 @@ async function* createStreamingGenerator(client, prompt, options, signal, config
|
|
|
717
673
|
let done = false;
|
|
718
674
|
let streamError = null;
|
|
719
675
|
let usageData = null;
|
|
676
|
+
let receivedDeltas = false;
|
|
720
677
|
|
|
721
678
|
const unsubscribe = session.on((event) => {
|
|
722
679
|
switch (event.type) {
|
|
723
680
|
case 'assistant.message_delta':
|
|
681
|
+
receivedDeltas = true;
|
|
724
682
|
eventQueue.push({
|
|
725
683
|
type: 'delta',
|
|
726
684
|
data: { textDelta: event.data.deltaContent },
|
|
@@ -728,8 +686,8 @@ async function* createStreamingGenerator(client, prompt, options, signal, config
|
|
|
728
686
|
break;
|
|
729
687
|
|
|
730
688
|
case 'assistant.message':
|
|
731
|
-
// Final complete message — use
|
|
732
|
-
if (event.data.content) {
|
|
689
|
+
// Final complete message — only use if no streaming deltas were received
|
|
690
|
+
if (!receivedDeltas && event.data.content) {
|
|
733
691
|
eventQueue.push({
|
|
734
692
|
type: 'delta',
|
|
735
693
|
data: { textDelta: event.data.content },
|