@maintainer-pro/ai-bridge 0.1.11 → 0.1.12

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/daemon.mjs +31 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maintainer-pro/ai-bridge",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Local bridge daemon that pairs a machine to Maintainer Pro and configures multiple client sandboxes.",
5
5
  "keywords": [
6
6
  "maintainer-pro",
package/src/daemon.mjs CHANGED
@@ -2205,9 +2205,16 @@ const embeddedChat = new Map();
2205
2205
  /** @type {Map<string, Promise<object | null>>} */
2206
2206
  const embeddedChatStarting = new Map();
2207
2207
 
2208
- const PROXY_CHUNK_BYTES = 32 * 1024;
2208
+ const PROXY_CHUNK_BYTES = 256 * 1024;
2209
2209
  /** @type {Map<string, import("node:http").ClientRequest>} */
2210
2210
  const proxyHttpReqs = new Map();
2211
+ /** Reuse sockets to the local app — Next/Vite fetch many files per page. */
2212
+ const proxyKeepAliveAgent = new http.Agent({
2213
+ keepAlive: true,
2214
+ maxSockets: 64,
2215
+ maxFreeSockets: 16,
2216
+ timeout: 30_000,
2217
+ });
2211
2218
  /** @type {Map<string, WebSocket>} */
2212
2219
  const proxyLocalSockets = new Map();
2213
2220
  /** @type {Record<string, unknown> | null} */
@@ -2463,7 +2470,7 @@ function handleProxyHttpFromAdmin(msg) {
2463
2470
  path,
2464
2471
  method,
2465
2472
  headers,
2466
- agent: false,
2473
+ agent: proxyKeepAliveAgent,
2467
2474
  },
2468
2475
  (res) => {
2469
2476
  /** @type {Record<string, string>} */
@@ -2589,10 +2596,27 @@ function attachProxyLocalWs(id, socket) {
2589
2596
  });
2590
2597
  }
2591
2598
 
2592
- function openProxyLocalWs(id, port, path) {
2599
+ function wsProtocolsFromMsg(msg) {
2600
+ if (Array.isArray(msg?.protocols)) {
2601
+ return msg.protocols.map((p) => String(p || "").trim()).filter(Boolean);
2602
+ }
2603
+ const headers = msg?.headers && typeof msg.headers === "object" ? msg.headers : {};
2604
+ const raw = headers["sec-websocket-protocol"] || headers["Sec-WebSocket-Protocol"] || "";
2605
+ return String(raw)
2606
+ .split(",")
2607
+ .map((part) => part.trim())
2608
+ .filter(Boolean);
2609
+ }
2610
+
2611
+ function openProxyLocalWs(id, port, path, protocols) {
2593
2612
  let socket;
2594
2613
  try {
2595
- socket = new WebSocket(`ws://127.0.0.1:${port}${path}`);
2614
+ const url = `ws://127.0.0.1:${port}${path}`;
2615
+ const proto = Array.isArray(protocols)
2616
+ ? protocols.map((p) => String(p || "").trim()).filter(Boolean)
2617
+ : [];
2618
+ // Vite HMR only accepts upgrades with subprotocol `vite-hmr` / `vite-ping`.
2619
+ socket = proto.length ? new WebSocket(url, proto) : new WebSocket(url);
2596
2620
  } catch (err) {
2597
2621
  bridgeSend({
2598
2622
  type: "proxy.ws.error",
@@ -2615,6 +2639,7 @@ function handleProxyWsOpenFromAdmin(msg) {
2615
2639
  return;
2616
2640
  }
2617
2641
  const path = safeProxyPath(msg.path);
2642
+ const protocols = wsProtocolsFromMsg(msg);
2618
2643
  if (isAiServerAppId(appId, ws)) {
2619
2644
  void (async () => {
2620
2645
  const embedded = await ensureEmbeddedChat(ws);
@@ -2623,7 +2648,7 @@ function handleProxyWsOpenFromAdmin(msg) {
2623
2648
  bridgeSend({ type: "proxy.ws.error", id, error: "AI chat is not running" });
2624
2649
  return;
2625
2650
  }
2626
- openProxyLocalWs(id, port, path);
2651
+ openProxyLocalWs(id, port, path, protocols);
2627
2652
  })();
2628
2653
  return;
2629
2654
  }
@@ -2632,7 +2657,7 @@ function handleProxyWsOpenFromAdmin(msg) {
2632
2657
  bridgeSend({ type: "proxy.ws.error", id, error: "No local port mapped" });
2633
2658
  return;
2634
2659
  }
2635
- openProxyLocalWs(id, port, path);
2660
+ openProxyLocalWs(id, port, path, protocols);
2636
2661
  }
2637
2662
 
2638
2663
  function handleProxyWsFrameFromAdmin(msg) {