@slock-ai/daemon 0.48.0 → 0.49.0

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.
@@ -41,75 +41,6 @@ var logger = {
41
41
  }
42
42
  };
43
43
 
44
- // src/proxy.ts
45
- import { HttpsProxyAgent } from "https-proxy-agent";
46
- import { ProxyAgent } from "undici";
47
- var fetchDispatcherCache = /* @__PURE__ */ new Map();
48
- function getDefaultPort(protocol) {
49
- switch (protocol) {
50
- case "https:":
51
- case "wss:":
52
- return "443";
53
- case "http:":
54
- case "ws:":
55
- return "80";
56
- default:
57
- return "";
58
- }
59
- }
60
- function hostMatchesNoProxyEntry(hostname, ruleHost) {
61
- if (!ruleHost) return false;
62
- const normalizedRule = ruleHost.replace(/^\*\./, ".").replace(/^\./, "").toLowerCase();
63
- const normalizedHost = hostname.toLowerCase();
64
- return normalizedHost === normalizedRule || normalizedHost.endsWith(`.${normalizedRule}`);
65
- }
66
- function getProxyUrlForTarget(targetUrl, env) {
67
- const protocol = new URL(targetUrl).protocol;
68
- switch (protocol) {
69
- case "wss:":
70
- return env.WSS_PROXY || env.wss_proxy || env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy;
71
- case "ws:":
72
- return env.WS_PROXY || env.ws_proxy || env.HTTP_PROXY || env.http_proxy || env.ALL_PROXY || env.all_proxy;
73
- case "https:":
74
- return env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy;
75
- case "http:":
76
- return env.HTTP_PROXY || env.http_proxy || env.ALL_PROXY || env.all_proxy;
77
- default:
78
- return env.ALL_PROXY || env.all_proxy;
79
- }
80
- }
81
- function shouldBypassProxy(targetUrl, env) {
82
- const rawNoProxy = env.NO_PROXY || env.no_proxy;
83
- if (!rawNoProxy) return false;
84
- const url = new URL(targetUrl);
85
- const hostname = url.hostname.toLowerCase();
86
- const port = url.port || getDefaultPort(url.protocol);
87
- return rawNoProxy.split(",").map((entry) => entry.trim()).filter(Boolean).some((entry) => {
88
- if (entry === "*") return true;
89
- const [ruleHost, rulePort] = entry.split(":", 2);
90
- if (rulePort && rulePort !== port) return false;
91
- return hostMatchesNoProxyEntry(hostname, ruleHost);
92
- });
93
- }
94
- function buildWebSocketOptions(wsUrl, env) {
95
- const proxyUrl = getProxyUrlForTarget(wsUrl, env);
96
- if (!proxyUrl) return void 0;
97
- if (shouldBypassProxy(wsUrl, env)) return void 0;
98
- return {
99
- agent: new HttpsProxyAgent(proxyUrl)
100
- };
101
- }
102
- function buildFetchDispatcher(targetUrl, env) {
103
- const proxyUrl = getProxyUrlForTarget(targetUrl, env);
104
- if (!proxyUrl) return void 0;
105
- if (shouldBypassProxy(targetUrl, env)) return void 0;
106
- const cached = fetchDispatcherCache.get(proxyUrl);
107
- if (cached) return cached;
108
- const dispatcher = new ProxyAgent(proxyUrl);
109
- fetchDispatcherCache.set(proxyUrl, dispatcher);
110
- return dispatcher;
111
- }
112
-
113
44
  // src/chatBridgeRequest.ts
114
45
  var DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS = Number.parseInt(
115
46
  process.env.SLOCK_CHAT_BRIDGE_TOOL_TIMEOUT_MS || "",
@@ -207,55 +138,81 @@ async function executeResponseRequest(url, init, {
207
138
  }
208
139
  }
209
140
 
210
- // src/slockHome.ts
211
- import os from "os";
212
- import path from "path";
213
- import { existsSync } from "fs";
214
- var SLOCK_HOME_ENV = "SLOCK_HOME";
215
- function resolveDefaultSlockHome(homeDir = os.homedir()) {
216
- return path.resolve(path.join(homeDir, ".slock"));
141
+ // src/proxy.ts
142
+ import { HttpsProxyAgent } from "https-proxy-agent";
143
+ import { ProxyAgent } from "undici";
144
+ var fetchDispatcherCache = /* @__PURE__ */ new Map();
145
+ function getDefaultPort(protocol) {
146
+ switch (protocol) {
147
+ case "https:":
148
+ case "wss:":
149
+ return "443";
150
+ case "http:":
151
+ case "ws:":
152
+ return "80";
153
+ default:
154
+ return "";
155
+ }
156
+ }
157
+ function hostMatchesNoProxyEntry(hostname, ruleHost) {
158
+ if (!ruleHost) return false;
159
+ const normalizedRule = ruleHost.replace(/^\*\./, ".").replace(/^\./, "").toLowerCase();
160
+ const normalizedHost = hostname.toLowerCase();
161
+ return normalizedHost === normalizedRule || normalizedHost.endsWith(`.${normalizedRule}`);
162
+ }
163
+ function getProxyUrlForTarget(targetUrl, env) {
164
+ const protocol = new URL(targetUrl).protocol;
165
+ switch (protocol) {
166
+ case "wss:":
167
+ return env.WSS_PROXY || env.wss_proxy || env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy;
168
+ case "ws:":
169
+ return env.WS_PROXY || env.ws_proxy || env.HTTP_PROXY || env.http_proxy || env.ALL_PROXY || env.all_proxy;
170
+ case "https:":
171
+ return env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy;
172
+ case "http:":
173
+ return env.HTTP_PROXY || env.http_proxy || env.ALL_PROXY || env.all_proxy;
174
+ default:
175
+ return env.ALL_PROXY || env.all_proxy;
176
+ }
217
177
  }
218
- function resolveSlockHome(env = process.env, homeDir = os.homedir()) {
219
- const raw = env[SLOCK_HOME_ENV]?.trim();
220
- const root = raw && raw.length > 0 ? raw : resolveDefaultSlockHome(homeDir);
221
- return path.resolve(root);
178
+ function shouldBypassProxy(targetUrl, env) {
179
+ const rawNoProxy = env.NO_PROXY || env.no_proxy;
180
+ if (!rawNoProxy) return false;
181
+ const url = new URL(targetUrl);
182
+ const hostname = url.hostname.toLowerCase();
183
+ const port = url.port || getDefaultPort(url.protocol);
184
+ return rawNoProxy.split(",").map((entry) => entry.trim()).filter(Boolean).some((entry) => {
185
+ if (entry === "*") return true;
186
+ const [ruleHost, rulePort] = entry.split(":", 2);
187
+ if (rulePort && rulePort !== port) return false;
188
+ return hostMatchesNoProxyEntry(hostname, ruleHost);
189
+ });
222
190
  }
223
- function resolveSlockHomePath(childPath, slockHome = resolveSlockHome()) {
224
- return path.join(slockHome, childPath);
191
+ function buildWebSocketOptions(wsUrl, env) {
192
+ const proxyUrl = getProxyUrlForTarget(wsUrl, env);
193
+ if (!proxyUrl) return void 0;
194
+ if (shouldBypassProxy(wsUrl, env)) return void 0;
195
+ return {
196
+ agent: new HttpsProxyAgent(proxyUrl)
197
+ };
225
198
  }
226
- function listLegacySlockStatePaths(slockHome = resolveSlockHome(), homeDir = os.homedir()) {
227
- const defaultHome = resolveDefaultSlockHome(homeDir);
228
- if (path.resolve(slockHome) === defaultHome) return [];
229
- const candidates = [
230
- {
231
- path: path.join(defaultHome, "agents"),
232
- destination: path.join(slockHome, "agents"),
233
- description: "agent workspaces and per-agent runtime wrapper state"
234
- },
235
- {
236
- path: path.join(defaultHome, "machines"),
237
- destination: path.join(slockHome, "machines"),
238
- description: "daemon machine locks, local traces, and machine-scoped state"
239
- },
240
- {
241
- path: path.join(defaultHome, "attachments"),
242
- destination: path.join(slockHome, "attachments"),
243
- description: "chat bridge attachment download cache"
244
- }
245
- ];
246
- return candidates.filter((candidate) => existsSync(candidate.path));
199
+ function buildFetchDispatcher(targetUrl, env) {
200
+ const proxyUrl = getProxyUrlForTarget(targetUrl, env);
201
+ if (!proxyUrl) return void 0;
202
+ if (shouldBypassProxy(targetUrl, env)) return void 0;
203
+ const cached = fetchDispatcherCache.get(proxyUrl);
204
+ if (cached) return cached;
205
+ const dispatcher = new ProxyAgent(proxyUrl);
206
+ fetchDispatcherCache.set(proxyUrl, dispatcher);
207
+ return dispatcher;
247
208
  }
248
209
 
249
210
  export {
250
211
  subscribeDaemonLogs,
251
212
  logger,
252
- buildWebSocketOptions,
253
- buildFetchDispatcher,
254
213
  DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS,
255
214
  executeJsonRequest,
256
215
  executeResponseRequest,
257
- SLOCK_HOME_ENV,
258
- resolveSlockHome,
259
- resolveSlockHomePath,
260
- listLegacySlockStatePaths
216
+ buildWebSocketOptions,
217
+ buildFetchDispatcher
261
218
  };