@zonease/happy 0.6.42 → 0.6.44
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/dist/{api-CIE4_cWd.cjs → api-Ct7Z1lwF.cjs} +65 -5
- package/dist/{api-Ew6xr81i.mjs → api-D3j3YL3m.mjs} +65 -5
- package/dist/{auth-G9fZpVJ2.cjs → auth-B9kOli6i.cjs} +2 -2
- package/dist/{auth-BzYevJo2.mjs → auth-C2ZyAGMu.mjs} +4 -4
- package/dist/{auth-Q2STUNI-.mjs → auth-DPe89SQx.mjs} +2 -2
- package/dist/{auth-Dor79zTL.cjs → auth-W1aK_a-P.cjs} +4 -4
- package/dist/{browser-qDIIAL7S.cjs → browser-BPEhi6te.cjs} +1 -1
- package/dist/{browser-BI7s-V8E.mjs → browser-Byx5gq-W.mjs} +1 -1
- package/dist/{claudeLocal-Db2tDC4X.mjs → claudeLocal-BtxBYzs7.mjs} +1 -1
- package/dist/{claudeLocal-f4uBLJaM.cjs → claudeLocal-CcarNVE9.cjs} +1 -1
- package/dist/{config-CHjDs8AS.mjs → config-DJLOlgjr.mjs} +1 -1
- package/dist/{config-CSBlEik9.cjs → config-Djr2JMWO.cjs} +1 -1
- package/dist/{connect-O_nA5BOC.mjs → connect-PrUuHNLU.mjs} +4 -4
- package/dist/{connect-CJoTliii.cjs → connect-rcgRx9US.cjs} +4 -4
- package/dist/{controlClient-DoS9JqQC.mjs → controlClient-DSiES8Un.mjs} +1 -1
- package/dist/{controlClient-CEz_p1zc.cjs → controlClient-FDsMeGVn.cjs} +1 -1
- package/dist/{cursorApprovalHook-DRAHfTXU.cjs → cursorApprovalHook-CTJiiPO6.cjs} +29 -11
- package/dist/{cursorApprovalHook-B0v1kGa7.mjs → cursorApprovalHook-DGYeNaLe.mjs} +29 -11
- package/dist/{cursorApprovalServer-DzY8yJlI.cjs → cursorApprovalServer-C_wqI7wm.cjs} +109 -8
- package/dist/{cursorApprovalServer-JjPkdjGR.mjs → cursorApprovalServer-fjPBXSAb.mjs} +109 -10
- package/dist/{deviceKeys-B4aqjnE6.mjs → deviceKeys-BYHzWSyg.mjs} +2 -2
- package/dist/{deviceKeys-DyUn0bEx.cjs → deviceKeys-DPut1U07.cjs} +2 -2
- package/dist/{doctor-DRnft_5-.mjs → doctor-BA28TuMy.mjs} +2 -2
- package/dist/{doctor-BJSuVRUZ.cjs → doctor-B_W7odmC.cjs} +2 -2
- package/dist/{downloadImage-Cijmufpr.cjs → downloadImage-B7MKUI0u.cjs} +1 -372
- package/dist/downloadImage-DKWzC11M.mjs +485 -0
- package/dist/{enroll-CysDL6ee.mjs → enroll-Bc3Lke1H.mjs} +3 -3
- package/dist/{enroll-C2gunHdt.cjs → enroll-Blqx_Kg8.cjs} +3 -3
- package/dist/{evidence-DPutCuUr.mjs → evidence-D8nvQ8pQ.mjs} +1 -1
- package/dist/{evidence-DsQ-h-_W.cjs → evidence-jfqT04hc.cjs} +1 -1
- package/dist/{formatImageMessage-6aV9YFWr.mjs → formatImageMessage-BFWnadBR.mjs} +1 -1
- package/dist/{formatImageMessage-BPK_Ivfe.cjs → formatImageMessage-CZeSzoFO.cjs} +1 -1
- package/dist/index.cjs +50 -46
- package/dist/index.mjs +50 -46
- package/dist/{install-DBg0xQ3g.mjs → install-BvuadnKW.mjs} +1 -1
- package/dist/{install-BsTA2tZn.mjs → install-ChK8Eb58.mjs} +2 -2
- package/dist/{install-Tyhs6rUp.cjs → install-DFmp8KKp.cjs} +1 -1
- package/dist/{install-DlOppA-e.cjs → install-nJv8rYWA.cjs} +2 -2
- package/dist/lib.cjs +3 -3
- package/dist/lib.d.cts +1 -0
- package/dist/lib.d.mts +1 -0
- package/dist/lib.mjs +3 -3
- package/dist/{loadableToolOutput-DPGTtKJM.cjs → loadableToolOutput-CqMfcEh7.cjs} +2 -2
- package/dist/{loadableToolOutput-2dMPAp4N.mjs → loadableToolOutput-D6crYom_.mjs} +2 -2
- package/dist/{persistence-D9tMm6bj.mjs → persistence-BXtirP1k.mjs} +1 -1
- package/dist/{persistence-BcQmjobZ.cjs → persistence-DOgft4tZ.cjs} +1 -1
- package/dist/{push-Dxsugkes.mjs → push-188EjPTP.mjs} +6 -6
- package/dist/{push-Cnm6JQMD.cjs → push-DykEVhRR.cjs} +6 -6
- package/dist/registerKillSessionHandler-6loIZYD9.mjs +407 -0
- package/dist/registerKillSessionHandler-ks8iPY9a.cjs +411 -0
- package/dist/{run-CiPWWhXt.cjs → run-DSJ7IIWW.cjs} +10 -8
- package/dist/{run-BEflQaQ2.mjs → run-Dp4_De-r.mjs} +10 -8
- package/dist/{runClaude-BVXsyCHb.cjs → runClaude-C3be35z0.cjs} +26 -26
- package/dist/{runClaude-sPkSqHWY.mjs → runClaude-gj4urJvB.mjs} +21 -21
- package/dist/{runCodex-C4rHkIyw.mjs → runCodex-DRZidxNB.mjs} +26 -26
- package/dist/{runCodex-BAwhdmSA.cjs → runCodex-p_fToj9T.cjs} +28 -28
- package/dist/{runCursor-CD5wC3gA.cjs → runCursor-CJlqkSYR.cjs} +210 -34
- package/dist/{runCursor-DiHLWMs8.mjs → runCursor-SFd9G7X_.mjs} +210 -34
- package/dist/{runGemini-B-93gOqB.mjs → runGemini-BOsfh6dX.mjs} +17 -17
- package/dist/{runGemini-Cto-adir.cjs → runGemini-lxvXq70R.cjs} +19 -19
- package/dist/{runOneShot-BfIzE9W4.cjs → runOneShot-BExFkHmA.cjs} +2 -2
- package/dist/{runOneShot-DGjlYVhR.mjs → runOneShot-CtzlkF1l.mjs} +2 -2
- package/dist/{serve-CqL6NWDr.cjs → serve-Bl1Caf6x.cjs} +6 -6
- package/dist/{serve-ttlqF5jn.mjs → serve-DfvSXAD2.mjs} +6 -6
- package/dist/{session-BZhGpQUJ.cjs → session--R6FqsxL.cjs} +5 -5
- package/dist/{session-Co0REU9e.mjs → session-BSzNJiAb.mjs} +5 -5
- package/dist/{sessionKeyCache-BwFUGgMs.cjs → sessionKeyCache-CVkksG68.cjs} +1 -1
- package/dist/{sessionKeyCache-pXTjpETo.mjs → sessionKeyCache-DYiCIvYC.mjs} +1 -1
- package/dist/{sessionList-fG5uAPzU.cjs → sessionList-C1q9fy5j.cjs} +2 -2
- package/dist/{sessionList-DaufR-sA.mjs → sessionList-D3pCseut.mjs} +2 -2
- package/dist/{sessionSummary-CjZPt6nr.cjs → sessionSummary-CUZxEBEZ.cjs} +3 -3
- package/dist/{sessionSummary-Dv6dPABg.mjs → sessionSummary-WpOlgXe1.mjs} +3 -3
- package/dist/{setupOfflineReconnection-DW5il97B.mjs → setupOfflineReconnection-BeWF3SGN.mjs} +5 -3
- package/dist/{setupOfflineReconnection-B6coH9QN.cjs → setupOfflineReconnection-CixoiWTS.cjs} +7 -5
- package/dist/{spawnHappyCLI-DhUeycct.mjs → spawnHappyCLI-Cyc-69jO.mjs} +1 -1
- package/dist/{spawnHappyCLI-Cfu7C1uM.cjs → spawnHappyCLI-hRc7u16s.cjs} +1 -1
- package/dist/{ssh-C4YTSHXL.cjs → ssh-B_TYtrys.cjs} +5 -5
- package/dist/{ssh-8tPIKk-i.mjs → ssh-BsxAgWgG.mjs} +5 -5
- package/dist/{task-DFW-PecP.cjs → task-BInh42e3.cjs} +6 -6
- package/dist/{task-CH-oidFy.mjs → task-BS4usaxx.mjs} +6 -6
- package/dist/{uninstall-CeioRZNI.mjs → uninstall-BKuDaZKB.mjs} +2 -2
- package/dist/{uninstall-yTSL3X6Y.cjs → uninstall-DNFGxNLl.cjs} +2 -2
- package/dist/{update-Bju28vNP.cjs → update-B9LoI5l8.cjs} +3 -3
- package/dist/{update-Derd2hoX.mjs → update-DC300VOW.mjs} +3 -3
- package/package.json +1 -1
- package/dist/downloadImage-BpVF7A79.mjs +0 -854
- package/dist/gitWorktree-C6jLoaMw.cjs +0 -39
- package/dist/gitWorktree-CzJDU2BV.mjs +0 -37
|
@@ -1,34 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var logger = require('./persistence-
|
|
3
|
+
var logger = require('./persistence-DOgft4tZ.cjs');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
|
-
var path = require('node:path');
|
|
6
|
-
var projectPath = require('./projectPath-ChLhdOyt.cjs');
|
|
7
|
-
var mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
8
|
-
var node_http = require('node:http');
|
|
9
|
-
var streamableHttp_js = require('@modelcontextprotocol/sdk/server/streamableHttp.js');
|
|
10
|
-
var types_js = require('@modelcontextprotocol/sdk/types.js');
|
|
11
|
-
var z = require('zod');
|
|
12
|
-
var deviceKeys = require('./deviceKeys-DyUn0bEx.cjs');
|
|
13
|
-
var node_crypto = require('node:crypto');
|
|
14
|
-
var prompt = require('./prompt-BTWDZZO0.cjs');
|
|
15
|
-
require('./mcpToolSchemas-DK42yoZ_.cjs');
|
|
16
|
-
require('./index-BeKrqPYR.cjs');
|
|
17
5
|
var axios = require('axios');
|
|
18
|
-
require('node:events');
|
|
19
|
-
require('socket.io-client');
|
|
20
|
-
require('./api-CIE4_cWd.cjs');
|
|
21
|
-
require('tweetnacl');
|
|
22
|
-
require('ws');
|
|
23
|
-
require('@stablelib/base64');
|
|
24
|
-
require('node:os');
|
|
25
|
-
require('node:fs/promises');
|
|
26
|
-
require('node:fs');
|
|
27
|
-
require('node:readline');
|
|
28
|
-
require('node:child_process');
|
|
29
|
-
require('expo-server-sdk');
|
|
30
|
-
require('chalk');
|
|
31
|
-
require('./types-DWeB7aqh.cjs');
|
|
32
6
|
|
|
33
7
|
function parseCompact(message) {
|
|
34
8
|
const trimmed = message.trim();
|
|
@@ -427,338 +401,6 @@ function hashObject(obj, options, encoding = "hex") {
|
|
|
427
401
|
return crypto.createHash("sha256").update(jsonString).digest(encoding);
|
|
428
402
|
}
|
|
429
403
|
|
|
430
|
-
function createMcpServer(client, options) {
|
|
431
|
-
const mcp = new mcp_js.McpServer({
|
|
432
|
-
name: "Happy MCP",
|
|
433
|
-
version: "1.0.0"
|
|
434
|
-
});
|
|
435
|
-
const handler = async (title) => {
|
|
436
|
-
logger.logger.debug("[happyMCP] Changing title to:", title);
|
|
437
|
-
if (client.isTitlePinned) {
|
|
438
|
-
return { success: false, error: "Title is pinned by user and cannot be changed automatically" };
|
|
439
|
-
}
|
|
440
|
-
try {
|
|
441
|
-
client.sendClaudeSessionMessage({
|
|
442
|
-
type: "summary",
|
|
443
|
-
summary: title,
|
|
444
|
-
leafUuid: node_crypto.randomUUID()
|
|
445
|
-
});
|
|
446
|
-
return { success: true };
|
|
447
|
-
} catch (error) {
|
|
448
|
-
return { success: false, error: String(error) };
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
mcp.registerTool("device_list", {
|
|
452
|
-
description: "List enrolled Happy devices (servers and computers) with their online state. Use before device_exec when you need a device id.",
|
|
453
|
-
title: "List Devices",
|
|
454
|
-
inputSchema: {}
|
|
455
|
-
}, async () => {
|
|
456
|
-
const credentials = await logger.readCredentials();
|
|
457
|
-
if (!credentials) {
|
|
458
|
-
return { content: [{ type: "text", text: "No Happy credentials on this machine." }] };
|
|
459
|
-
}
|
|
460
|
-
try {
|
|
461
|
-
const devices = await deviceKeys.listDevices(credentials);
|
|
462
|
-
const target = client.targetDevices.map((device) => device.id);
|
|
463
|
-
const lines = devices.map((device) => {
|
|
464
|
-
const marks = [device.active ? "online" : "offline"];
|
|
465
|
-
if (target.includes(device.id)) marks.push("session default");
|
|
466
|
-
return `${device.id} ${device.name}${device.platform ? ` (${device.platform})` : ""} [${marks.join(", ")}]${device.description ? ` \u2014 ${device.description}` : ""}`;
|
|
467
|
-
});
|
|
468
|
-
return { content: [{ type: "text", text: lines.length ? lines.join("\n") : "No devices enrolled yet." }] };
|
|
469
|
-
} catch (error) {
|
|
470
|
-
return { content: [{ type: "text", text: `Failed to list devices: ${error instanceof Error ? error.message : String(error)}` }] };
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
mcp.registerTool("device_exec", {
|
|
474
|
-
description: "Run a shell command on an enrolled device (a server or computer registered in Happy). Omit deviceId to use the device the user selected for this session. Returns stdout, stderr and exit code.",
|
|
475
|
-
title: "Run Command on Device",
|
|
476
|
-
inputSchema: {
|
|
477
|
-
command: z.z.string().describe("Shell command to run on the device"),
|
|
478
|
-
deviceId: z.z.string().optional().describe("Target device id. Defaults to the session's selected device."),
|
|
479
|
-
cwd: z.z.string().optional().describe("Working directory on the device"),
|
|
480
|
-
timeout: z.z.number().optional().describe("Timeout in milliseconds (default 60000)")
|
|
481
|
-
}
|
|
482
|
-
}, async (args) => {
|
|
483
|
-
const credentials = await logger.readCredentials();
|
|
484
|
-
if (!credentials) {
|
|
485
|
-
return { content: [{ type: "text", text: "No Happy credentials on this machine." }] };
|
|
486
|
-
}
|
|
487
|
-
const targets = client.targetDevices;
|
|
488
|
-
const deviceId = args.deviceId || (targets.length === 1 ? targets[0].id : null);
|
|
489
|
-
if (!deviceId && targets.length > 1) {
|
|
490
|
-
return { content: [{ type: "text", text: `This session targets several devices \u2014 pass deviceId: ${targets.map((device) => `${device.name} (${device.id})`).join(", ")}` }] };
|
|
491
|
-
}
|
|
492
|
-
if (!deviceId) {
|
|
493
|
-
return { content: [{ type: "text", text: "No device selected for this session. Pick one in the app or pass deviceId (see device_list)." }] };
|
|
494
|
-
}
|
|
495
|
-
try {
|
|
496
|
-
const result = await deviceKeys.deviceExec(client.rpcSocket, credentials, deviceId, args.command, {
|
|
497
|
-
cwd: args.cwd,
|
|
498
|
-
timeout: args.timeout,
|
|
499
|
-
deviceKeyBase64: targets.find((device) => device.id === deviceId)?.key ?? null
|
|
500
|
-
});
|
|
501
|
-
const parts = [`exit code: ${result.exitCode}`];
|
|
502
|
-
if (result.stdout) parts.push(`stdout:
|
|
503
|
-
${result.stdout}`);
|
|
504
|
-
if (result.stderr) parts.push(`stderr:
|
|
505
|
-
${result.stderr}`);
|
|
506
|
-
return { content: [{ type: "text", text: parts.join("\n\n") }] };
|
|
507
|
-
} catch (error) {
|
|
508
|
-
return { content: [{ type: "text", text: `Device command failed: ${error instanceof Error ? error.message : String(error)}` }] };
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
mcp.registerTool("change_title", {
|
|
512
|
-
description: "Change the title of the current chat session",
|
|
513
|
-
title: "Change Chat Title",
|
|
514
|
-
inputSchema: {
|
|
515
|
-
title: z.z.string().describe("The new title for the chat session")
|
|
516
|
-
}
|
|
517
|
-
}, async (args) => {
|
|
518
|
-
const response = await handler(args.title);
|
|
519
|
-
logger.logger.debug("[happyMCP] Response:", response);
|
|
520
|
-
if (response.success) {
|
|
521
|
-
return {
|
|
522
|
-
content: [
|
|
523
|
-
{
|
|
524
|
-
type: "text",
|
|
525
|
-
text: `Successfully changed chat title to: "${args.title}"`
|
|
526
|
-
}
|
|
527
|
-
],
|
|
528
|
-
isError: false
|
|
529
|
-
};
|
|
530
|
-
} else {
|
|
531
|
-
return {
|
|
532
|
-
content: [
|
|
533
|
-
{
|
|
534
|
-
type: "text",
|
|
535
|
-
text: `Failed to change chat title: ${response.error || "Unknown error"}`
|
|
536
|
-
}
|
|
537
|
-
],
|
|
538
|
-
isError: true
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
mcp.registerTool("preview_html", {
|
|
543
|
-
description: "Preview an HTML page in the client app. The HTML must be a complete, self-contained document with all CSS and JS inlined.",
|
|
544
|
-
title: "Preview HTML",
|
|
545
|
-
inputSchema: {
|
|
546
|
-
html: z.z.string().describe("Complete self-contained HTML document string"),
|
|
547
|
-
title: z.z.string().optional().describe("Display title for the preview")
|
|
548
|
-
}
|
|
549
|
-
}, async (args) => {
|
|
550
|
-
logger.logger.debug("[happyMCP] Preview HTML:", args.title || "Untitled");
|
|
551
|
-
return {
|
|
552
|
-
content: [{
|
|
553
|
-
type: "text",
|
|
554
|
-
text: `HTML preview ready: ${args.title || "Untitled"}`
|
|
555
|
-
}],
|
|
556
|
-
isError: false
|
|
557
|
-
};
|
|
558
|
-
});
|
|
559
|
-
return mcp;
|
|
560
|
-
}
|
|
561
|
-
async function startHappyServer(client) {
|
|
562
|
-
const transports = /* @__PURE__ */ new Map();
|
|
563
|
-
const enableOrchestratorTools = prompt.shouldEnableOrchestratorTools();
|
|
564
|
-
const toolNames = ["change_title", "preview_html", "device_list", "device_exec"];
|
|
565
|
-
const originalConsoleError = console.error;
|
|
566
|
-
console.error = (...args) => {
|
|
567
|
-
logger.logger.debug("[happyMCP] console.error:", ...args);
|
|
568
|
-
originalConsoleError.apply(console, args);
|
|
569
|
-
};
|
|
570
|
-
const server = node_http.createServer(async (req, res) => {
|
|
571
|
-
const sessionId = req.headers["mcp-session-id"];
|
|
572
|
-
logger.logger.debug("[happyMCP] Received request:", req.method, req.url, "sessionId:", sessionId);
|
|
573
|
-
try {
|
|
574
|
-
if (req.method === "POST") {
|
|
575
|
-
const body = await readRequestBody(req);
|
|
576
|
-
const parsedBody = JSON.parse(body);
|
|
577
|
-
let transport;
|
|
578
|
-
if (sessionId && transports.has(sessionId)) {
|
|
579
|
-
transport = transports.get(sessionId);
|
|
580
|
-
logger.logger.debug("[happyMCP] Reusing transport for session:", sessionId);
|
|
581
|
-
} else if (!sessionId && types_js.isInitializeRequest(parsedBody)) {
|
|
582
|
-
logger.logger.debug("[happyMCP] New initialize request, creating transport");
|
|
583
|
-
transport = new streamableHttp_js.StreamableHTTPServerTransport({
|
|
584
|
-
sessionIdGenerator: () => node_crypto.randomUUID(),
|
|
585
|
-
onsessioninitialized: (newSessionId) => {
|
|
586
|
-
logger.logger.debug("[happyMCP] Session initialized:", newSessionId);
|
|
587
|
-
transports.set(newSessionId, transport);
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
transport.onclose = () => {
|
|
591
|
-
const sid = transport.sessionId;
|
|
592
|
-
if (sid && transports.has(sid)) {
|
|
593
|
-
logger.logger.debug("[happyMCP] Transport closed, removing session:", sid);
|
|
594
|
-
transports.delete(sid);
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
transport.onerror = (error) => {
|
|
598
|
-
logger.logger.debug("[happyMCP] Transport error:", error);
|
|
599
|
-
};
|
|
600
|
-
const mcp = createMcpServer(client, { enableOrchestratorTools });
|
|
601
|
-
await mcp.connect(transport);
|
|
602
|
-
await transport.handleRequest(req, res, parsedBody);
|
|
603
|
-
logger.logger.debug("[happyMCP] Initialize request handled successfully");
|
|
604
|
-
return;
|
|
605
|
-
} else {
|
|
606
|
-
logger.logger.debug("[happyMCP] Bad request: no session ID and not initialize");
|
|
607
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
608
|
-
res.end(JSON.stringify({
|
|
609
|
-
jsonrpc: "2.0",
|
|
610
|
-
error: {
|
|
611
|
-
code: -32e3,
|
|
612
|
-
message: "Bad Request: No valid session ID provided"
|
|
613
|
-
},
|
|
614
|
-
id: null
|
|
615
|
-
}));
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
await transport.handleRequest(req, res, parsedBody);
|
|
619
|
-
logger.logger.debug("[happyMCP] Request handled successfully");
|
|
620
|
-
} else if (req.method === "GET" || req.method === "DELETE") {
|
|
621
|
-
if (!sessionId || !transports.has(sessionId)) {
|
|
622
|
-
logger.logger.debug("[happyMCP] Bad request: invalid session for GET/DELETE");
|
|
623
|
-
res.writeHead(400, { "Content-Type": "text/plain" });
|
|
624
|
-
res.end("Invalid or missing session ID");
|
|
625
|
-
return;
|
|
626
|
-
}
|
|
627
|
-
const transport = transports.get(sessionId);
|
|
628
|
-
await transport.handleRequest(req, res);
|
|
629
|
-
logger.logger.debug("[happyMCP] GET/DELETE request handled successfully");
|
|
630
|
-
} else {
|
|
631
|
-
res.writeHead(405, { "Content-Type": "text/plain" });
|
|
632
|
-
res.end("Method not allowed");
|
|
633
|
-
}
|
|
634
|
-
} catch (error) {
|
|
635
|
-
logger.logger.debug("[happyMCP] Error handling request:", error);
|
|
636
|
-
if (!res.headersSent) {
|
|
637
|
-
res.writeHead(500).end();
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
const baseUrl = await new Promise((resolve) => {
|
|
642
|
-
server.listen(0, "127.0.0.1", () => {
|
|
643
|
-
const addr = server.address();
|
|
644
|
-
resolve(new URL(`http://127.0.0.1:${addr.port}`));
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
logger.logger.debug("[happyMCP] Server started at:", baseUrl.toString());
|
|
648
|
-
return {
|
|
649
|
-
url: baseUrl.toString(),
|
|
650
|
-
toolNames,
|
|
651
|
-
stop: async () => {
|
|
652
|
-
logger.logger.debug("[happyMCP] Stopping server");
|
|
653
|
-
for (const [sessionId, transport] of transports) {
|
|
654
|
-
logger.logger.debug("[happyMCP] Closing transport for session:", sessionId);
|
|
655
|
-
try {
|
|
656
|
-
await transport.close();
|
|
657
|
-
} catch (error) {
|
|
658
|
-
logger.logger.debug("[happyMCP] Error closing transport:", error);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
transports.clear();
|
|
662
|
-
server.close();
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
function readRequestBody(req) {
|
|
667
|
-
return new Promise((resolve, reject) => {
|
|
668
|
-
let body = "";
|
|
669
|
-
req.on("data", (chunk) => body += chunk);
|
|
670
|
-
req.on("end", () => resolve(body));
|
|
671
|
-
req.on("error", reject);
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const getBridgeCommand = () => path.join(projectPath.projectPath(), "bin", "happy-mcp.mjs");
|
|
676
|
-
function adaptForClaude(def) {
|
|
677
|
-
return { type: "http", url: def.url, ...def.headers && { headers: def.headers } };
|
|
678
|
-
}
|
|
679
|
-
function adaptForStdio(def) {
|
|
680
|
-
const args = ["--url", def.url];
|
|
681
|
-
if (def.headers) {
|
|
682
|
-
for (const [k, v] of Object.entries(def.headers)) {
|
|
683
|
-
args.push("--header", `${k}: ${v}`);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
return { command: getBridgeCommand(), args };
|
|
687
|
-
}
|
|
688
|
-
function adaptForHttp(def) {
|
|
689
|
-
return { type: "http", url: def.url, headers: def.headers || {} };
|
|
690
|
-
}
|
|
691
|
-
async function createMcpContext(session) {
|
|
692
|
-
const happyServer = await startHappyServer(session);
|
|
693
|
-
const servers = {
|
|
694
|
-
happy: {
|
|
695
|
-
url: happyServer.url,
|
|
696
|
-
toolNames: happyServer.toolNames,
|
|
697
|
-
stop: () => happyServer.stop()
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
const extraServersJson = process.env.HAPPY_EXTRA_MCP_SERVERS;
|
|
701
|
-
if (extraServersJson) {
|
|
702
|
-
try {
|
|
703
|
-
const extraServers = JSON.parse(extraServersJson);
|
|
704
|
-
for (const srv of extraServers) {
|
|
705
|
-
servers[srv.name] = {
|
|
706
|
-
url: srv.url,
|
|
707
|
-
toolNames: [],
|
|
708
|
-
// External MCP — tools discovered by agent, not whitelisted
|
|
709
|
-
headers: srv.headers,
|
|
710
|
-
stop: () => {
|
|
711
|
-
}
|
|
712
|
-
// No lifecycle management for external servers
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
} catch (e) {
|
|
716
|
-
console.warn("Failed to parse HAPPY_EXTRA_MCP_SERVERS:", e);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
return {
|
|
720
|
-
configForClaude() {
|
|
721
|
-
const result = {};
|
|
722
|
-
for (const [name, def] of Object.entries(servers)) {
|
|
723
|
-
result[name] = adaptForClaude(def);
|
|
724
|
-
}
|
|
725
|
-
return result;
|
|
726
|
-
},
|
|
727
|
-
configForStdio() {
|
|
728
|
-
const result = {};
|
|
729
|
-
for (const [name, def] of Object.entries(servers)) {
|
|
730
|
-
result[name] = adaptForStdio(def);
|
|
731
|
-
}
|
|
732
|
-
return result;
|
|
733
|
-
},
|
|
734
|
-
configForHttp() {
|
|
735
|
-
const result = {};
|
|
736
|
-
for (const [name, def] of Object.entries(servers)) {
|
|
737
|
-
result[name] = adaptForHttp(def);
|
|
738
|
-
}
|
|
739
|
-
return result;
|
|
740
|
-
},
|
|
741
|
-
allowedToolNames() {
|
|
742
|
-
return Object.entries(servers).flatMap(
|
|
743
|
-
([name, def]) => def.toolNames.map((tool) => `mcp__${name}__${tool}`)
|
|
744
|
-
);
|
|
745
|
-
},
|
|
746
|
-
normalizeToolName(rawName) {
|
|
747
|
-
for (const [name, def] of Object.entries(servers)) {
|
|
748
|
-
if (def.toolNames.includes(rawName)) {
|
|
749
|
-
return `mcp:${name}:${rawName}`;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
return rawName;
|
|
753
|
-
},
|
|
754
|
-
stop() {
|
|
755
|
-
for (const def of Object.values(servers)) {
|
|
756
|
-
def.stop();
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
|
|
762
404
|
class MessageBuffer {
|
|
763
405
|
messages = [];
|
|
764
406
|
listeners = [];
|
|
@@ -829,17 +471,6 @@ class MessageBuffer {
|
|
|
829
471
|
}
|
|
830
472
|
}
|
|
831
473
|
|
|
832
|
-
function registerKillSessionHandler(rpcHandlerManager, killThisHappy) {
|
|
833
|
-
rpcHandlerManager.registerHandler("killSession", async () => {
|
|
834
|
-
logger.logger.debug("Kill session request received");
|
|
835
|
-
void killThisHappy();
|
|
836
|
-
return {
|
|
837
|
-
success: true,
|
|
838
|
-
message: "Killing happy-cli process"
|
|
839
|
-
};
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
|
|
843
474
|
async function downloadImage(url) {
|
|
844
475
|
const response = await axios.get(url, {
|
|
845
476
|
responseType: "arraybuffer"
|
|
@@ -855,9 +486,7 @@ async function downloadImage(url) {
|
|
|
855
486
|
|
|
856
487
|
exports.MessageBuffer = MessageBuffer;
|
|
857
488
|
exports.MessageQueue2 = MessageQueue2;
|
|
858
|
-
exports.createMcpContext = createMcpContext;
|
|
859
489
|
exports.downloadImage = downloadImage;
|
|
860
490
|
exports.hashObject = hashObject;
|
|
861
491
|
exports.parseClear = parseClear;
|
|
862
492
|
exports.parseSpecialCommand = parseSpecialCommand;
|
|
863
|
-
exports.registerKillSessionHandler = registerKillSessionHandler;
|