@slock-ai/daemon 0.55.0 → 0.55.1-play.20260530150714

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.
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  daemonFetch,
4
4
  executeJsonRequest
5
- } from "./chunk-VOZJ2ELH.js";
5
+ } from "./chunk-M2KQBJR3.js";
6
6
 
7
7
  // src/chat-bridge.ts
8
8
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -142,6 +142,10 @@ async function executeResponseRequest(url, init, {
142
142
  import { HttpsProxyAgent } from "https-proxy-agent";
143
143
  import { ProxyAgent } from "undici";
144
144
  var fetchDispatcherCache = /* @__PURE__ */ new Map();
145
+ function getFetchPreResponseTimeoutMs(env) {
146
+ const parsed = Number.parseInt(env.SLOCK_DAEMON_FETCH_PRE_RESPONSE_TIMEOUT_MS || "", 10);
147
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : 3e4;
148
+ }
145
149
  function getDefaultPort(protocol) {
146
150
  switch (protocol) {
147
151
  case "https:":
@@ -196,24 +200,53 @@ function buildWebSocketOptions(wsUrl, env) {
196
200
  agent: new HttpsProxyAgent(proxyUrl)
197
201
  };
198
202
  }
199
- function buildFetchDispatcher(targetUrl, env) {
203
+ function resolveProxyUrl(targetUrl, env) {
200
204
  const proxyUrl = getProxyUrlForTarget(targetUrl, env);
201
205
  if (!proxyUrl) return void 0;
202
206
  if (shouldBypassProxy(targetUrl, env)) return void 0;
207
+ return proxyUrl;
208
+ }
209
+ function buildFetchDispatcher(targetUrl, env) {
210
+ const proxyUrl = resolveProxyUrl(targetUrl, env);
211
+ if (!proxyUrl) return void 0;
203
212
  const cached = fetchDispatcherCache.get(proxyUrl);
204
213
  if (cached) return cached;
205
- const dispatcher = new ProxyAgent(proxyUrl);
214
+ const timeoutMs = getFetchPreResponseTimeoutMs(env);
215
+ const dispatcher = new ProxyAgent({
216
+ uri: proxyUrl,
217
+ // All three are pre-response and body-agnostic (see getFetchPreResponseTimeoutMs):
218
+ // headersTimeout = headers-hang leg; requestTls.timeout = CONNECT-tunnel
219
+ // establish leg; connect.timeout = socket to the proxy itself (defensive).
220
+ connect: { timeout: timeoutMs },
221
+ requestTls: { timeout: timeoutMs },
222
+ headersTimeout: timeoutMs
223
+ });
206
224
  fetchDispatcherCache.set(proxyUrl, dispatcher);
207
225
  return dispatcher;
208
226
  }
227
+ function evictFetchDispatcher(targetUrl, env) {
228
+ const proxyUrl = resolveProxyUrl(targetUrl, env);
229
+ if (!proxyUrl) return false;
230
+ const cached = fetchDispatcherCache.get(proxyUrl);
231
+ if (!cached) return false;
232
+ fetchDispatcherCache.delete(proxyUrl);
233
+ void Promise.resolve().then(() => cached.close()).catch(() => cached.destroy?.(new Error("evicted"))).catch(() => {
234
+ });
235
+ return true;
236
+ }
209
237
 
210
238
  // src/daemonFetch.ts
211
239
  function withDaemonFetchProxy(input, init = {}, env = process.env) {
212
240
  const dispatcher = buildFetchDispatcher(input.toString(), env);
213
241
  return dispatcher ? { ...init, dispatcher } : init;
214
242
  }
215
- function daemonFetch(input, init, env = process.env) {
216
- return fetch(input, withDaemonFetchProxy(input, init, env));
243
+ async function daemonFetch(input, init, env = process.env) {
244
+ try {
245
+ return await fetch(input, withDaemonFetchProxy(input, init, env));
246
+ } catch (err) {
247
+ evictFetchDispatcher(input.toString(), env);
248
+ throw err;
249
+ }
217
250
  }
218
251
 
219
252
  export {