@certalis/agent-smith 0.1.7 → 0.1.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/README.md CHANGED
@@ -85,26 +85,33 @@ startServer({
85
85
 
86
86
  Codex works the same way with an OpenAI API key and an `openai-responses` pool.
87
87
 
88
- ## Connect an authorized caller to a private shared pool
88
+ ## Connect an authorized caller to a shared pool
89
89
 
90
- The agents service and a laptop can send requests to one proxy with a
91
- forwarding key. Put the server and callers on a private network first; the
92
- recommended WireGuard shape is documented in the
93
- [private-network guide](docs/private-network.md). It keeps the database and
94
- provider tokens on the server, and exposes the proxy only on the private
95
- network.
90
+ The agents service and laptops can use one server-side pool through the
91
+ [authenticated HTTPS entrance](docs/https-edge.md) on managed HTTP hosts such as
92
+ Render. HTTPS needs no VPN or extra server: an existing web service forwards
93
+ only inference to the pool's private socket. Each device has its own revocable
94
+ key; provider tokens and the single database stay on the server.
96
95
 
97
- This is connectivity only, not team tenancy: the shared forwarding key does
98
- not identify an individual caller or enforce per-client fairness. Do not
99
- distribute it team-wide until the B2/W7 tenancy work exists.
96
+ Device keys allow independent revocation and cannot read management data.
97
+ This does not add per-client fairness or budgets.
100
98
 
101
- Copy [`private-network-client.json`](examples/config/private-network-client.json)
102
- into your private Agent-smith config. Put the forwarding key in the owner-only
103
- file named by `proxy_key_file`, not in the JSON or a shell profile. `base_url`
104
- is the private endpoint visible to that machine, not a second pool. The key can
105
- spend from the pool, but cannot administer it.
99
+ Copy [`https-client.json`](examples/config/https-client.json) into your private
100
+ Agent-smith config. Put the device key in the owner-only file named by
101
+ `proxy_key_file`, not in the JSON or a shell profile. `base_url` is the endpoint
102
+ visible to your machine, not a second pool. The key can spend from the pool, but
103
+ cannot administer it. Remote client routing is off by default: set
104
+ `client.enabled` to `true` when this machine should use the shared pool.
106
105
 
107
- Then install the normal `claude` and `codex` wrappers once:
106
+ An SSH tunnel remains an option for development. Use
107
+ [`team-client.json`](examples/config/team-client.json) and forward its local port
108
+ to the private server:
109
+
110
+ ```bash
111
+ ssh -N -L 18181:127.0.0.1:8080 agent-smith-pool
112
+ ```
113
+
114
+ Then apply the flag with the normal client setup command:
108
115
 
109
116
  ```bash
110
117
  agent-smith install-client
@@ -112,9 +119,12 @@ agent-smith install-client
112
119
 
113
120
  Open a new terminal and use `claude` or `codex` normally. The wrappers only add
114
121
  their own marked `PATH` entry; they do not replace the real binaries or start a
115
- second proxy. Edit the `client` section and rerun `agent-smith install-client`
116
- when the private address changes; do not hand-edit the generated wrappers. The
117
- forwarding key is for inference, not dashboard or management access.
122
+ second proxy. The forwarding key is for inference, not dashboard or management
123
+ access.
124
+
125
+ To switch back to ordinary local Claude Code/Codex, set `client.enabled` to
126
+ `false` and run `agent-smith install-client` again. It removes only its wrappers
127
+ and marked shell entry; it does not change the real clients or their credentials.
118
128
 
119
129
  ## Configuration
120
130
 
@@ -190,14 +200,15 @@ to `acme` and are sent as `acme-large`. `acme` serves no other model.
190
200
  ```
191
201
 
192
202
  **A laptop using a private shared pool**
193
- ([`private-network-client.json`](examples/config/private-network-client.json)).
194
- The address is reachable only through the private network described in the
195
- [deployment guide](docs/private-network.md).
203
+ ([`team-client.json`](examples/config/team-client.json)). The example uses an
204
+ SSH-local port; use the direct private origin instead on a host that can reach
205
+ the pool without SSH.
196
206
 
197
207
  ```json
198
208
  {
199
209
  "client": {
200
- "base_url": "http://10.76.0.1:8080",
210
+ "enabled": false,
211
+ "base_url": "http://127.0.0.1:18181",
201
212
  "proxy_key_file": "~/.config/ccflare/team-pool.key"
202
213
  }
203
214
  }
package/dist/bin.js CHANGED
@@ -1421,6 +1421,8 @@ function sanitizeClientRouting(value) {
1421
1421
  if (!isRecord(value))
1422
1422
  return;
1423
1423
  const client = {};
1424
+ if (typeof value.enabled === "boolean")
1425
+ client.enabled = value.enabled;
1424
1426
  if (typeof value.base_url === "string") {
1425
1427
  try {
1426
1428
  const url = new URL(value.base_url);
@@ -1726,6 +1728,7 @@ var init_src4 = __esm(() => {
1726
1728
  getClientRouting() {
1727
1729
  const client = this.data.client;
1728
1730
  return {
1731
+ enabled: client?.enabled === true,
1729
1732
  ...client?.base_url && { baseUrl: client.base_url },
1730
1733
  ...client?.proxy_key_file && {
1731
1734
  proxyKeyFile: client.proxy_key_file
@@ -4636,7 +4639,8 @@ var init_base = __esm(() => {
4636
4639
  TRANSPORT_HEADERS_TO_DELETE = [
4637
4640
  "host",
4638
4641
  "accept-encoding",
4639
- "content-encoding"
4642
+ "content-encoding",
4643
+ "transfer-encoding"
4640
4644
  ];
4641
4645
  CLIENT_CREDENTIAL_HEADERS_TO_DELETE = [
4642
4646
  "api-key",
@@ -11670,8 +11674,71 @@ var init_src10 = __esm(() => {
11670
11674
  init_websocket_proxy();
11671
11675
  });
11672
11676
 
11677
+ // ../../packages/runtime-server/src/device-keys.ts
11678
+ import { createHash as createHash3, timingSafeEqual } from "crypto";
11679
+ import {
11680
+ closeSync,
11681
+ constants,
11682
+ fstatSync,
11683
+ openSync,
11684
+ readFileSync as readFileSync2
11685
+ } from "fs";
11686
+ import { isAbsolute as isAbsolute2 } from "path";
11687
+ function deviceKeyMatches(key, path) {
11688
+ if (!key || !path || !isAbsolute2(path) || !/^[\x21-\x7e]{32,512}$/.test(key))
11689
+ return false;
11690
+ let fd;
11691
+ try {
11692
+ fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
11693
+ const stat = fstatSync(fd);
11694
+ if (!stat.isFile() || stat.size > MAX_REGISTRY_BYTES || (stat.mode & 63) !== 0 || stat.uid !== process.getuid?.() && stat.uid !== 0)
11695
+ return false;
11696
+ const registry = JSON.parse(readFileSync2(fd, "utf8"));
11697
+ if (!registry || typeof registry !== "object" || Array.isArray(registry))
11698
+ return false;
11699
+ const entries = Object.entries(registry);
11700
+ if (entries.length > MAX_DEVICES || entries.some(([name, digest2]) => !/^[-a-zA-Z0-9_]{1,64}$/.test(name) || typeof digest2 !== "string" || !/^[a-f0-9]{64}$/.test(digest2)))
11701
+ return false;
11702
+ const digest = createHash3("sha256").update(key).digest();
11703
+ return entries.some(([, expected]) => timingSafeEqual(digest, Buffer.from(expected, "hex")));
11704
+ } catch {
11705
+ return false;
11706
+ } finally {
11707
+ if (fd !== undefined)
11708
+ closeSync(fd);
11709
+ }
11710
+ }
11711
+ var MAX_REGISTRY_BYTES, MAX_DEVICES = 128;
11712
+ var init_device_keys = __esm(() => {
11713
+ MAX_REGISTRY_BYTES = 32 * 1024;
11714
+ });
11715
+
11716
+ // ../../packages/runtime-server/src/inference-routes.ts
11717
+ function isInferenceRoute(method, path) {
11718
+ return INFERENCE_ROUTES.has(`${method} ${path}`);
11719
+ }
11720
+ function isDeviceRoute(method, path) {
11721
+ return method === "GET" && path === "/health" || isInferenceRoute(method, path);
11722
+ }
11723
+ var INFERENCE_ROUTES;
11724
+ var init_inference_routes = __esm(() => {
11725
+ INFERENCE_ROUTES = new Set([
11726
+ "POST /v1/claude-code/v1/messages",
11727
+ "POST /v1/claude-code/v1/messages/count_tokens",
11728
+ "POST /v1/pool/anthropic-messages/v1/messages",
11729
+ "POST /v1/pool/anthropic-messages/v1/messages/count_tokens",
11730
+ "POST /v1/codex/responses",
11731
+ "POST /v1/pool/openai-responses/responses"
11732
+ ]);
11733
+ for (const route of [...INFERENCE_ROUTES]) {
11734
+ if (route.endsWith("/messages") || route.endsWith("/count_tokens")) {
11735
+ INFERENCE_ROUTES.add(`${route}?beta=true`);
11736
+ }
11737
+ }
11738
+ });
11739
+
11673
11740
  // ../../packages/runtime-server/src/exposure.ts
11674
- import { timingSafeEqual } from "crypto";
11741
+ import { timingSafeEqual as timingSafeEqual2 } from "crypto";
11675
11742
  function requestAddress(server, req) {
11676
11743
  if (!server || typeof server.requestIP !== "function") {
11677
11744
  return { address: undefined, hasRequestIp: false };
@@ -11684,25 +11751,14 @@ function requestAddress(server, req) {
11684
11751
  function configuredKey(value) {
11685
11752
  return typeof value === "string" && value.length > 0 ? value : undefined;
11686
11753
  }
11687
- function configuredBindHosts(value) {
11688
- if (value === undefined)
11689
- return;
11690
- const bindHosts = [
11691
- ...new Set(value.split(",").map((host) => host.trim()).filter(Boolean))
11692
- ];
11693
- return bindHosts.length > 0 ? bindHosts : undefined;
11694
- }
11695
11754
  function createExposureConfig(config) {
11696
11755
  const configuredHost = configuredKey(process.env.CF_HOST) ?? configuredKey(config.get("host"));
11697
- const bindHosts = configuredBindHosts(process.env.CF_BIND_HOSTS) ?? [
11698
- configuredHost ?? "127.0.0.1"
11699
- ];
11700
11756
  const configuredTrustLoopback = process.env.CF_TRUST_LOOPBACK;
11701
11757
  return {
11702
11758
  adminKey: configuredKey(process.env.CF_ADMIN_KEY),
11703
- bindHost: bindHosts[0],
11704
- bindHosts,
11759
+ bindHost: configuredHost ?? "127.0.0.1",
11705
11760
  proxyKey: configuredKey(process.env.CF_PROXY_KEY),
11761
+ clientKeysFile: configuredKey(process.env.CF_CLIENT_KEYS_FILE),
11706
11762
  trustLoopback: configuredTrustLoopback === undefined ? config.get("trust_loopback") !== false : configuredTrustLoopback !== "false"
11707
11763
  };
11708
11764
  }
@@ -11716,10 +11772,10 @@ function isLoopbackAddress(address) {
11716
11772
  return address === "127.0.0.1" || address === "::1" || address === "::ffff:127.0.0.1";
11717
11773
  }
11718
11774
  function safeKeyEqual(candidate, expected) {
11719
- if (!candidate || !expected || candidate.length !== expected.length) {
11775
+ if (!candidate || !expected || Buffer.byteLength(candidate) !== Buffer.byteLength(expected)) {
11720
11776
  return false;
11721
11777
  }
11722
- return timingSafeEqual(Buffer.from(candidate), Buffer.from(expected));
11778
+ return timingSafeEqual2(Buffer.from(candidate), Buffer.from(expected));
11723
11779
  }
11724
11780
  function bearerToken(req) {
11725
11781
  const authorization = req.headers.get("authorization");
@@ -11740,6 +11796,9 @@ function keyRole(req, url, config) {
11740
11796
  if (isResponsesInferenceRoute(url.pathname) && safeKeyEqual(bearerToken(req), config.proxyKey)) {
11741
11797
  return "proxy";
11742
11798
  }
11799
+ if (deviceKeyMatches(apiKey, config.clientKeysFile) || isResponsesInferenceRoute(url.pathname) && deviceKeyMatches(bearerToken(req), config.clientKeysFile)) {
11800
+ return "device";
11801
+ }
11743
11802
  return null;
11744
11803
  }
11745
11804
  function hostnameFromHostHeader(host) {
@@ -11753,7 +11812,7 @@ function hostnameFromHostHeader(host) {
11753
11812
  function isWildcardHost(host) {
11754
11813
  return host === "0.0.0.0" || host === "::";
11755
11814
  }
11756
- function isLocalHostHeader(hostHeader, bindHosts) {
11815
+ function isLocalHostHeader(hostHeader, bindHost) {
11757
11816
  if (hostHeader === null) {
11758
11817
  return true;
11759
11818
  }
@@ -11761,8 +11820,7 @@ function isLocalHostHeader(hostHeader, bindHosts) {
11761
11820
  if (!hostname) {
11762
11821
  return false;
11763
11822
  }
11764
- const configuredHosts = typeof bindHosts === "string" ? [bindHosts] : bindHosts;
11765
- return LOOPBACK_HOSTS.has(hostname) || configuredHosts.some((bindHost) => !isWildcardHost(bindHost) && hostname === bindHost.toLowerCase());
11823
+ return LOOPBACK_HOSTS.has(hostname) || !isWildcardHost(bindHost) && hostname === bindHost.toLowerCase();
11766
11824
  }
11767
11825
  function isSameOriginManagementRequest(req, url) {
11768
11826
  const fetchSite = req.headers.get("sec-fetch-site");
@@ -11777,12 +11835,15 @@ function jsonError(status, message) {
11777
11835
  }
11778
11836
  function exposureFailure(req, url, server, config) {
11779
11837
  const remote = requestAddress(server, req);
11780
- const loopbackExempt = config.trustLoopback && (remote.hasRequestIp ? isLoopbackAddress(remote.address) : isLocalHostHeader(url.host, config.bindHosts)) && !isForwardedRequest(req.headers);
11838
+ const loopbackExempt = config.trustLoopback && (remote.hasRequestIp ? isLoopbackAddress(remote.address) : isLocalHostHeader(url.host, config.bindHost)) && !isForwardedRequest(req.headers);
11781
11839
  const role = keyRole(req, url, config);
11840
+ if (role === "device" && !isDeviceRoute(req.method, url.pathname + url.search)) {
11841
+ return jsonError(403, "Device keys only allow health and inference");
11842
+ }
11782
11843
  if (!role && !loopbackExempt) {
11783
11844
  return jsonError(401, "A proxy key is required for this request");
11784
11845
  }
11785
- if (!role && !isLocalHostHeader(req.headers.get("host"), config.bindHosts)) {
11846
+ if (!role && !isLocalHostHeader(req.headers.get("host"), config.bindHost)) {
11786
11847
  return jsonError(403, "Host header is not allowed for a loopback request");
11787
11848
  }
11788
11849
  if (url.pathname.startsWith("/api/")) {
@@ -11799,6 +11860,8 @@ function exposureFailure(req, url, server, config) {
11799
11860
  }
11800
11861
  var FORWARDED_HEADERS, LOOPBACK_HOSTS, MUTATING_METHODS;
11801
11862
  var init_exposure = __esm(() => {
11863
+ init_device_keys();
11864
+ init_inference_routes();
11802
11865
  FORWARDED_HEADERS = [
11803
11866
  "forwarded",
11804
11867
  "x-forwarded-for",
@@ -11952,10 +12015,10 @@ var init_bootstrap_runtime = __esm(() => {
11952
12015
  });
11953
12016
 
11954
12017
  // ../../packages/runtime-server/src/dashboard-assets.ts
11955
- import { readFileSync as readFileSync2 } from "fs";
11956
- import { dirname as dirname3, isAbsolute as isAbsolute2, join as join7, resolve as resolve2 } from "path";
12018
+ import { readFileSync as readFileSync3 } from "fs";
12019
+ import { dirname as dirname3, isAbsolute as isAbsolute3, join as join7, resolve as resolve2 } from "path";
11957
12020
  function resolveConfiguredPath(configuredPath) {
11958
- return isAbsolute2(configuredPath) ? configuredPath : resolve2(process.cwd(), configuredPath);
12021
+ return isAbsolute3(configuredPath) ? configuredPath : resolve2(process.cwd(), configuredPath);
11959
12022
  }
11960
12023
  function resolveDashboardManifestPath() {
11961
12024
  const configuredManifestPath = process.env[DASHBOARD_MANIFEST_PATH_ENV]?.trim();
@@ -11977,7 +12040,7 @@ function loadDashboardAssets() {
11977
12040
  }
11978
12041
  const manifestPath = resolveDashboardManifestPath();
11979
12042
  dashboardAssets = {
11980
- manifest: JSON.parse(readFileSync2(manifestPath, "utf8")),
12043
+ manifest: JSON.parse(readFileSync3(manifestPath, "utf8")),
11981
12044
  distDir: dirname3(manifestPath)
11982
12045
  };
11983
12046
  return dashboardAssets;
@@ -12066,7 +12129,6 @@ function createServerFetchHandler({
12066
12129
  withDashboard,
12067
12130
  exposureConfig = {
12068
12131
  bindHost: "127.0.0.1",
12069
- bindHosts: ["127.0.0.1"],
12070
12132
  trustLoopback: true
12071
12133
  },
12072
12134
  handleProxyRequest = handleProxy,
@@ -12187,7 +12249,7 @@ var init_startup_maintenance = __esm(() => {
12187
12249
  });
12188
12250
 
12189
12251
  // ../../packages/runtime-server/src/index.ts
12190
- import { isAbsolute as isAbsolute3 } from "path";
12252
+ import { isAbsolute as isAbsolute4 } from "path";
12191
12253
  var {serve } = globalThis.Bun;
12192
12254
  function stopRetentionMaintenance() {
12193
12255
  if (stopRetentionJob) {
@@ -12213,10 +12275,8 @@ async function stopServerRuntime() {
12213
12275
  serverStopPromise = (async () => {
12214
12276
  const errors2 = [];
12215
12277
  const activeServer = serverInstance;
12216
- const activeAdditionalServers = additionalServerInstances;
12217
12278
  const activeUnixServer = unixServerInstance;
12218
12279
  serverInstance = null;
12219
- additionalServerInstances = [];
12220
12280
  unixServerInstance = null;
12221
12281
  try {
12222
12282
  await activeUnixServer?.stop(true);
@@ -12228,13 +12288,6 @@ async function stopServerRuntime() {
12228
12288
  } catch (error) {
12229
12289
  errors2.push(toError("Failed to stop Bun server", error));
12230
12290
  }
12231
- for (const [index, server] of activeAdditionalServers.entries()) {
12232
- try {
12233
- await server.stop(true);
12234
- } catch (error) {
12235
- errors2.push(toError(`Failed to stop additional Bun server ${index + 1}`, error));
12236
- }
12237
- }
12238
12291
  stopRetentionMaintenance();
12239
12292
  try {
12240
12293
  await waitForProxyBackgroundTasks();
@@ -12267,7 +12320,7 @@ async function stopServerRuntime() {
12267
12320
  }
12268
12321
  }
12269
12322
  function startServer(options) {
12270
- if (options?.additionalUnixSocket !== undefined && !isAbsolute3(options.additionalUnixSocket)) {
12323
+ if (options?.additionalUnixSocket !== undefined && !isAbsolute4(options.additionalUnixSocket)) {
12271
12324
  throw new Error("Additional Unix socket must be an absolute path");
12272
12325
  }
12273
12326
  if (serverInstance) {
@@ -12313,16 +12366,6 @@ function startServer(options) {
12313
12366
  fetch: fetchHandler,
12314
12367
  websocket: websocketProxyHandler
12315
12368
  });
12316
- const activePort2 = serverInstance.port ?? runtimeConfig2.port;
12317
- for (const hostname of exposureConfig.bindHosts.slice(1)) {
12318
- additionalServerInstances.push(serve({
12319
- hostname,
12320
- port: activePort2,
12321
- idleTimeout: NETWORK.IDLE_TIMEOUT_MAX,
12322
- fetch: fetchHandler,
12323
- websocket: websocketProxyHandler
12324
- }));
12325
- }
12326
12369
  } catch (error) {
12327
12370
  stopServerRuntime().catch(() => {
12328
12371
  lifecycleLog.error("Failed to clean up after listener startup failure");
@@ -12358,7 +12401,7 @@ async function handleGracefulShutdown(signal) {
12358
12401
  process.exit(1);
12359
12402
  }
12360
12403
  }
12361
- var serverLog, lifecycleLog, serverInstance = null, additionalServerInstances, unixServerInstance = null, stopRetentionJob = null, serverStopPromise = null;
12404
+ var serverLog, lifecycleLog, serverInstance = null, unixServerInstance = null, stopRetentionJob = null, serverStopPromise = null;
12362
12405
  var init_src11 = __esm(() => {
12363
12406
  init_src9();
12364
12407
  init_src2();
@@ -12376,7 +12419,6 @@ var init_src11 = __esm(() => {
12376
12419
  lifecycleLog = new Logger("ServerLifecycle", 1 /* INFO */, {
12377
12420
  silentConsole: false
12378
12421
  });
12379
- additionalServerInstances = [];
12380
12422
  process.on("SIGINT", () => handleGracefulShutdown("SIGINT"));
12381
12423
  process.on("SIGTERM", () => handleGracefulShutdown("SIGTERM"));
12382
12424
  if (false) {}
@@ -13991,10 +14033,10 @@ var init_args = () => {};
13991
14033
  import {
13992
14034
  accessSync,
13993
14035
  chmodSync as chmodSync2,
13994
- constants as constants2,
14036
+ constants as constants3,
13995
14037
  existsSync as existsSync3,
13996
14038
  mkdirSync as mkdirSync4,
13997
- readFileSync as readFileSync3,
14039
+ readFileSync as readFileSync4,
13998
14040
  statSync as statSync3,
13999
14041
  unlinkSync as unlinkSync2,
14000
14042
  writeFileSync as writeFileSync2
@@ -14025,7 +14067,7 @@ function validateProxyKeyFile(proxyKeyFile) {
14025
14067
  if ((metadata.mode & 63) !== 0) {
14026
14068
  throw new Error("Agent-smith forwarding-key file must be owner-only");
14027
14069
  }
14028
- const key = readFileSync3(resolvedPath, "utf8").trim();
14070
+ const key = readFileSync4(resolvedPath, "utf8").trim();
14029
14071
  if (!/^[\x21-\x7e]{1,512}$/.test(key)) {
14030
14072
  throw new Error("Agent-smith forwarding-key file is invalid");
14031
14073
  }
@@ -14111,7 +14153,7 @@ function getLocalRoutingPaths() {
14111
14153
  }
14112
14154
  function isExecutable(path) {
14113
14155
  try {
14114
- accessSync(path, constants2.X_OK);
14156
+ accessSync(path, constants3.X_OK);
14115
14157
  return true;
14116
14158
  } catch {
14117
14159
  return false;
@@ -14131,7 +14173,7 @@ function readSavedClientPaths(statePath) {
14131
14173
  if (!existsSync3(statePath))
14132
14174
  return null;
14133
14175
  try {
14134
- const saved = JSON.parse(readFileSync3(statePath, "utf8"));
14176
+ const saved = JSON.parse(readFileSync4(statePath, "utf8"));
14135
14177
  if (typeof saved === "object" && saved !== null) {
14136
14178
  const { claudePath, codexPath } = saved;
14137
14179
  const validClaude = typeof claudePath === "string" && isExecutable(claudePath) ? claudePath : undefined;
@@ -14149,7 +14191,7 @@ function getLocalRoutingStatus(paths2 = {}) {
14149
14191
  const shellProfile = paths2.shellProfile ?? defaults.shellProfile;
14150
14192
  let shellProfileHasRouting = false;
14151
14193
  try {
14152
- shellProfileHasRouting = existsSync3(shellProfile) && readFileSync3(shellProfile, "utf8").includes(ROUTING_BEGIN);
14194
+ shellProfileHasRouting = existsSync3(shellProfile) && readFileSync4(shellProfile, "utf8").includes(ROUTING_BEGIN);
14153
14195
  } catch {}
14154
14196
  return {
14155
14197
  enabled: shellProfileHasRouting && (existsSync3(join8(binDir, "claude")) || existsSync3(join8(binDir, "codex"))),
@@ -14185,7 +14227,7 @@ async function enableLocalClientRouting(options) {
14185
14227
  proxyKeyFile: options.proxyKeyFile,
14186
14228
  providerPoolWires: options.providerPoolWires ?? Object.keys(new Config().getProviderPools())
14187
14229
  });
14188
- const existingProfile = existsSync3(shellProfile) ? readFileSync3(shellProfile, "utf8") : "";
14230
+ const existingProfile = existsSync3(shellProfile) ? readFileSync4(shellProfile, "utf8") : "";
14189
14231
  writeFileSync2(shellProfile, updateShellProfileForRouting(existingProfile, binDir), { encoding: "utf8", mode: 384 });
14190
14232
  mkdirSync4(dirname4(statePath), { recursive: true, mode: 448 });
14191
14233
  writeFileSync2(statePath, JSON.stringify({ claudePath, codexPath }), {
@@ -14201,7 +14243,7 @@ function disableLocalClientRouting(paths2 = {}) {
14201
14243
  const shellProfile = paths2.shellProfile ?? defaults.shellProfile;
14202
14244
  const statePath = paths2.statePath ?? defaults.statePath;
14203
14245
  if (existsSync3(shellProfile)) {
14204
- writeFileSync2(shellProfile, removeRoutingFromShellProfile(readFileSync3(shellProfile, "utf8")), { encoding: "utf8", mode: 384 });
14246
+ writeFileSync2(shellProfile, removeRoutingFromShellProfile(readFileSync4(shellProfile, "utf8")), { encoding: "utf8", mode: 384 });
14205
14247
  }
14206
14248
  for (const name of ["claude", "codex"]) {
14207
14249
  const wrapper = join8(binDir, name);
@@ -14461,13 +14503,13 @@ __export(exports_theme, {
14461
14503
  NAV_ITEMS: () => NAV_ITEMS,
14462
14504
  C: () => C
14463
14505
  });
14464
- import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
14506
+ import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
14465
14507
  import { homedir as homedir3 } from "os";
14466
14508
  import { join as join9 } from "path";
14467
14509
  function loadPersistedThemeId() {
14468
14510
  try {
14469
14511
  if (existsSync4(CONFIG_FILE)) {
14470
- const data = JSON.parse(readFileSync4(CONFIG_FILE, "utf-8"));
14512
+ const data = JSON.parse(readFileSync5(CONFIG_FILE, "utf-8"));
14471
14513
  if (data?.themeId && getThemeById(data.themeId)) {
14472
14514
  return data.themeId;
14473
14515
  }
@@ -17966,6 +18008,11 @@ Examples:
17966
18008
  if (parsed.installClient) {
17967
18009
  const config2 = new Config;
17968
18010
  const client2 = config2.getClientRouting();
18011
+ if (!client2.enabled) {
18012
+ disableLocalClientRouting();
18013
+ console.log("Remote client routing is disabled (client.enabled=false).");
18014
+ return;
18015
+ }
17969
18016
  if (!client2.baseUrl || !client2.proxyKeyFile) {
17970
18017
  throw new Error("client.base_url and client.proxy_key_file are required before installing client wrappers");
17971
18018
  }
package/dist/edge.js ADDED
@@ -0,0 +1,150 @@
1
+ // ../../packages/runtime-server/src/proxy-edge.ts
2
+ import {
3
+ request
4
+ } from "node:http";
5
+ import { isAbsolute } from "node:path";
6
+
7
+ // ../../packages/runtime-server/src/inference-routes.ts
8
+ var INFERENCE_ROUTES = new Set([
9
+ "POST /v1/claude-code/v1/messages",
10
+ "POST /v1/claude-code/v1/messages/count_tokens",
11
+ "POST /v1/pool/anthropic-messages/v1/messages",
12
+ "POST /v1/pool/anthropic-messages/v1/messages/count_tokens",
13
+ "POST /v1/codex/responses",
14
+ "POST /v1/pool/openai-responses/responses"
15
+ ]);
16
+ for (const route of [...INFERENCE_ROUTES]) {
17
+ if (route.endsWith("/messages") || route.endsWith("/count_tokens")) {
18
+ INFERENCE_ROUTES.add(`${route}?beta=true`);
19
+ }
20
+ }
21
+ function isInferenceRoute(method, path) {
22
+ return INFERENCE_ROUTES.has(`${method} ${path}`);
23
+ }
24
+
25
+ // ../../packages/runtime-server/src/proxy-edge.ts
26
+ var REQUEST_HEADERS = [
27
+ "content-type",
28
+ "accept",
29
+ "accept-encoding",
30
+ "anthropic-version",
31
+ "anthropic-beta",
32
+ "x-api-key",
33
+ "authorization",
34
+ "x-claude-code-session-id",
35
+ "session-id",
36
+ "openai-beta",
37
+ "x-client-request-id",
38
+ "user-agent"
39
+ ];
40
+ var RESPONSE_HEADERS = [
41
+ "content-type",
42
+ "content-encoding",
43
+ "retry-after",
44
+ "request-id",
45
+ "x-request-id",
46
+ "anthropic-ratelimit-requests-limit",
47
+ "anthropic-ratelimit-requests-remaining",
48
+ "anthropic-ratelimit-requests-reset",
49
+ "anthropic-ratelimit-tokens-limit",
50
+ "anthropic-ratelimit-tokens-remaining",
51
+ "anthropic-ratelimit-tokens-reset"
52
+ ];
53
+ function selectHeaders(headers, names) {
54
+ return Object.fromEntries(names.flatMap((name) => typeof headers[name] === "string" ? [[name, headers[name]]] : []));
55
+ }
56
+ function requestFailure(req, origin, maxBodyBytes) {
57
+ const health = req.method === "GET" && req.url === "/pool-health";
58
+ if (!health && !isInferenceRoute(req.method ?? "", req.url ?? ""))
59
+ return 404;
60
+ if (req.headers.host !== new URL(origin).host || req.headers.origin !== undefined && req.headers.origin !== origin || req.headers["sec-fetch-site"] !== undefined && !["none", "same-origin"].includes(String(req.headers["sec-fetch-site"])))
61
+ return 403;
62
+ if (req.headers.upgrade || req.headers.expect)
63
+ return 400;
64
+ if (req.headers["content-length"] !== undefined && (!/^\d+$/.test(req.headers["content-length"]) || Number(req.headers["content-length"]) > maxBodyBytes))
65
+ return 413;
66
+ if (!req.headers["x-api-key"] && !req.headers.authorization)
67
+ return 401;
68
+ return null;
69
+ }
70
+ function createProxyEdgeHandler({
71
+ origin,
72
+ socketPath,
73
+ maxBodyBytes = 64 * 1024 * 1024,
74
+ timeoutMs = 300000
75
+ }) {
76
+ const url = new URL(origin);
77
+ if (url.protocol !== "https:" || url.origin !== origin || !isAbsolute(socketPath) || !Number.isSafeInteger(maxBodyBytes) || maxBodyBytes < 1 || !Number.isSafeInteger(timeoutMs) || timeoutMs < 1) {
78
+ throw new Error("Proxy edge requires an exact HTTPS origin, an absolute socket path and positive limits");
79
+ }
80
+ return (req, res) => {
81
+ const finish = (status) => {
82
+ if (res.writableEnded || res.destroyed)
83
+ return;
84
+ if (res.headersSent) {
85
+ res.destroy();
86
+ return;
87
+ }
88
+ res.writeHead(status, {
89
+ "cache-control": "no-store",
90
+ connection: "close"
91
+ });
92
+ res.end();
93
+ };
94
+ const rejected = requestFailure(req, origin, maxBodyBytes);
95
+ if (rejected)
96
+ return finish(rejected);
97
+ const path = req.method === "GET" && req.url === "/pool-health" ? "/health" : req.url ?? "";
98
+ const headers = selectHeaders(req.headers, REQUEST_HEADERS);
99
+ headers.host = "localhost";
100
+ headers["x-forwarded-for"] = "proxy-edge";
101
+ let upstreamResponse;
102
+ const upstream = request({ socketPath, path, method: req.method, headers, agent: false }, (response) => {
103
+ upstreamResponse = response;
104
+ if (res.writableEnded || res.destroyed) {
105
+ response.destroy();
106
+ return;
107
+ }
108
+ const status = response.statusCode ?? 502;
109
+ if (status >= 300 && status < 400) {
110
+ response.destroy();
111
+ finish(502);
112
+ return;
113
+ }
114
+ res.writeHead(status, {
115
+ ...selectHeaders(response.headers, RESPONSE_HEADERS),
116
+ "cache-control": "no-store",
117
+ "x-content-type-options": "nosniff"
118
+ });
119
+ response.once("error", () => res.destroy());
120
+ response.once("aborted", () => res.destroy());
121
+ response.pipe(res);
122
+ });
123
+ const timer = setTimeout(() => {
124
+ upstreamResponse?.destroy();
125
+ upstream.destroy();
126
+ finish(504);
127
+ }, timeoutMs);
128
+ res.once("close", () => {
129
+ clearTimeout(timer);
130
+ upstreamResponse?.destroy();
131
+ upstream.destroy();
132
+ });
133
+ upstream.once("error", () => finish(502));
134
+ req.once("aborted", () => upstream.destroy());
135
+ req.once("error", () => upstream.destroy());
136
+ let bytes = 0;
137
+ req.on("data", (chunk) => {
138
+ bytes += chunk.length;
139
+ if (bytes > maxBodyBytes) {
140
+ req.unpipe(upstream);
141
+ upstream.destroy();
142
+ finish(413);
143
+ }
144
+ });
145
+ req.pipe(upstream);
146
+ };
147
+ }
148
+ export {
149
+ createProxyEdgeHandler
150
+ };
@@ -1473,6 +1473,8 @@ function sanitizeClientRouting(value) {
1473
1473
  if (!isRecord(value))
1474
1474
  return;
1475
1475
  const client = {};
1476
+ if (typeof value.enabled === "boolean")
1477
+ client.enabled = value.enabled;
1476
1478
  if (typeof value.base_url === "string") {
1477
1479
  try {
1478
1480
  const url = new URL(value.base_url);
@@ -1778,6 +1780,7 @@ var init_src4 = __esm(() => {
1778
1780
  getClientRouting() {
1779
1781
  const client = this.data.client;
1780
1782
  return {
1783
+ enabled: client?.enabled === true,
1781
1784
  ...client?.base_url && { baseUrl: client.base_url },
1782
1785
  ...client?.proxy_key_file && {
1783
1786
  proxyKeyFile: client.proxy_key_file
package/dist/server.js CHANGED
@@ -1459,7 +1459,8 @@ var init_base = __esm(() => {
1459
1459
  TRANSPORT_HEADERS_TO_DELETE = [
1460
1460
  "host",
1461
1461
  "accept-encoding",
1462
- "content-encoding"
1462
+ "content-encoding",
1463
+ "transfer-encoding"
1463
1464
  ];
1464
1465
  CLIENT_CREDENTIAL_HEADERS_TO_DELETE = [
1465
1466
  "api-key",
@@ -3992,6 +3993,8 @@ function sanitizeClientRouting(value) {
3992
3993
  if (!isRecord(value))
3993
3994
  return;
3994
3995
  const client2 = {};
3996
+ if (typeof value.enabled === "boolean")
3997
+ client2.enabled = value.enabled;
3995
3998
  if (typeof value.base_url === "string") {
3996
3999
  try {
3997
4000
  const url = new URL(value.base_url);
@@ -4297,6 +4300,7 @@ var init_src7 = __esm(() => {
4297
4300
  getClientRouting() {
4298
4301
  const client2 = this.data.client;
4299
4302
  return {
4303
+ enabled: client2?.enabled === true,
4300
4304
  ...client2?.base_url && { baseUrl: client2.base_url },
4301
4305
  ...client2?.proxy_key_file && {
4302
4306
  proxyKeyFile: client2.proxy_key_file
@@ -11669,8 +11673,71 @@ var init_src10 = __esm(() => {
11669
11673
  init_websocket_proxy();
11670
11674
  });
11671
11675
 
11676
+ // ../../packages/runtime-server/src/device-keys.ts
11677
+ import { createHash as createHash3, timingSafeEqual } from "crypto";
11678
+ import {
11679
+ closeSync,
11680
+ constants,
11681
+ fstatSync,
11682
+ openSync,
11683
+ readFileSync as readFileSync2
11684
+ } from "fs";
11685
+ import { isAbsolute as isAbsolute2 } from "path";
11686
+ function deviceKeyMatches(key, path) {
11687
+ if (!key || !path || !isAbsolute2(path) || !/^[\x21-\x7e]{32,512}$/.test(key))
11688
+ return false;
11689
+ let fd;
11690
+ try {
11691
+ fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
11692
+ const stat = fstatSync(fd);
11693
+ if (!stat.isFile() || stat.size > MAX_REGISTRY_BYTES || (stat.mode & 63) !== 0 || stat.uid !== process.getuid?.() && stat.uid !== 0)
11694
+ return false;
11695
+ const registry = JSON.parse(readFileSync2(fd, "utf8"));
11696
+ if (!registry || typeof registry !== "object" || Array.isArray(registry))
11697
+ return false;
11698
+ const entries = Object.entries(registry);
11699
+ if (entries.length > MAX_DEVICES || entries.some(([name, digest2]) => !/^[-a-zA-Z0-9_]{1,64}$/.test(name) || typeof digest2 !== "string" || !/^[a-f0-9]{64}$/.test(digest2)))
11700
+ return false;
11701
+ const digest = createHash3("sha256").update(key).digest();
11702
+ return entries.some(([, expected]) => timingSafeEqual(digest, Buffer.from(expected, "hex")));
11703
+ } catch {
11704
+ return false;
11705
+ } finally {
11706
+ if (fd !== undefined)
11707
+ closeSync(fd);
11708
+ }
11709
+ }
11710
+ var MAX_REGISTRY_BYTES, MAX_DEVICES = 128;
11711
+ var init_device_keys = __esm(() => {
11712
+ MAX_REGISTRY_BYTES = 32 * 1024;
11713
+ });
11714
+
11715
+ // ../../packages/runtime-server/src/inference-routes.ts
11716
+ function isInferenceRoute(method, path) {
11717
+ return INFERENCE_ROUTES.has(`${method} ${path}`);
11718
+ }
11719
+ function isDeviceRoute(method, path) {
11720
+ return method === "GET" && path === "/health" || isInferenceRoute(method, path);
11721
+ }
11722
+ var INFERENCE_ROUTES;
11723
+ var init_inference_routes = __esm(() => {
11724
+ INFERENCE_ROUTES = new Set([
11725
+ "POST /v1/claude-code/v1/messages",
11726
+ "POST /v1/claude-code/v1/messages/count_tokens",
11727
+ "POST /v1/pool/anthropic-messages/v1/messages",
11728
+ "POST /v1/pool/anthropic-messages/v1/messages/count_tokens",
11729
+ "POST /v1/codex/responses",
11730
+ "POST /v1/pool/openai-responses/responses"
11731
+ ]);
11732
+ for (const route of [...INFERENCE_ROUTES]) {
11733
+ if (route.endsWith("/messages") || route.endsWith("/count_tokens")) {
11734
+ INFERENCE_ROUTES.add(`${route}?beta=true`);
11735
+ }
11736
+ }
11737
+ });
11738
+
11672
11739
  // ../../packages/runtime-server/src/exposure.ts
11673
- import { timingSafeEqual } from "crypto";
11740
+ import { timingSafeEqual as timingSafeEqual2 } from "crypto";
11674
11741
  function requestAddress(server, req) {
11675
11742
  if (!server || typeof server.requestIP !== "function") {
11676
11743
  return { address: undefined, hasRequestIp: false };
@@ -11683,25 +11750,14 @@ function requestAddress(server, req) {
11683
11750
  function configuredKey(value) {
11684
11751
  return typeof value === "string" && value.length > 0 ? value : undefined;
11685
11752
  }
11686
- function configuredBindHosts(value) {
11687
- if (value === undefined)
11688
- return;
11689
- const bindHosts = [
11690
- ...new Set(value.split(",").map((host) => host.trim()).filter(Boolean))
11691
- ];
11692
- return bindHosts.length > 0 ? bindHosts : undefined;
11693
- }
11694
11753
  function createExposureConfig(config) {
11695
11754
  const configuredHost = configuredKey(process.env.CF_HOST) ?? configuredKey(config.get("host"));
11696
- const bindHosts = configuredBindHosts(process.env.CF_BIND_HOSTS) ?? [
11697
- configuredHost ?? "127.0.0.1"
11698
- ];
11699
11755
  const configuredTrustLoopback = process.env.CF_TRUST_LOOPBACK;
11700
11756
  return {
11701
11757
  adminKey: configuredKey(process.env.CF_ADMIN_KEY),
11702
- bindHost: bindHosts[0],
11703
- bindHosts,
11758
+ bindHost: configuredHost ?? "127.0.0.1",
11704
11759
  proxyKey: configuredKey(process.env.CF_PROXY_KEY),
11760
+ clientKeysFile: configuredKey(process.env.CF_CLIENT_KEYS_FILE),
11705
11761
  trustLoopback: configuredTrustLoopback === undefined ? config.get("trust_loopback") !== false : configuredTrustLoopback !== "false"
11706
11762
  };
11707
11763
  }
@@ -11715,10 +11771,10 @@ function isLoopbackAddress(address) {
11715
11771
  return address === "127.0.0.1" || address === "::1" || address === "::ffff:127.0.0.1";
11716
11772
  }
11717
11773
  function safeKeyEqual(candidate, expected) {
11718
- if (!candidate || !expected || candidate.length !== expected.length) {
11774
+ if (!candidate || !expected || Buffer.byteLength(candidate) !== Buffer.byteLength(expected)) {
11719
11775
  return false;
11720
11776
  }
11721
- return timingSafeEqual(Buffer.from(candidate), Buffer.from(expected));
11777
+ return timingSafeEqual2(Buffer.from(candidate), Buffer.from(expected));
11722
11778
  }
11723
11779
  function bearerToken(req) {
11724
11780
  const authorization = req.headers.get("authorization");
@@ -11739,6 +11795,9 @@ function keyRole(req, url, config) {
11739
11795
  if (isResponsesInferenceRoute(url.pathname) && safeKeyEqual(bearerToken(req), config.proxyKey)) {
11740
11796
  return "proxy";
11741
11797
  }
11798
+ if (deviceKeyMatches(apiKey, config.clientKeysFile) || isResponsesInferenceRoute(url.pathname) && deviceKeyMatches(bearerToken(req), config.clientKeysFile)) {
11799
+ return "device";
11800
+ }
11742
11801
  return null;
11743
11802
  }
11744
11803
  function hostnameFromHostHeader(host) {
@@ -11752,7 +11811,7 @@ function hostnameFromHostHeader(host) {
11752
11811
  function isWildcardHost(host) {
11753
11812
  return host === "0.0.0.0" || host === "::";
11754
11813
  }
11755
- function isLocalHostHeader(hostHeader, bindHosts) {
11814
+ function isLocalHostHeader(hostHeader, bindHost) {
11756
11815
  if (hostHeader === null) {
11757
11816
  return true;
11758
11817
  }
@@ -11760,8 +11819,7 @@ function isLocalHostHeader(hostHeader, bindHosts) {
11760
11819
  if (!hostname) {
11761
11820
  return false;
11762
11821
  }
11763
- const configuredHosts = typeof bindHosts === "string" ? [bindHosts] : bindHosts;
11764
- return LOOPBACK_HOSTS.has(hostname) || configuredHosts.some((bindHost) => !isWildcardHost(bindHost) && hostname === bindHost.toLowerCase());
11822
+ return LOOPBACK_HOSTS.has(hostname) || !isWildcardHost(bindHost) && hostname === bindHost.toLowerCase();
11765
11823
  }
11766
11824
  function isSameOriginManagementRequest(req, url) {
11767
11825
  const fetchSite = req.headers.get("sec-fetch-site");
@@ -11776,12 +11834,15 @@ function jsonError(status, message) {
11776
11834
  }
11777
11835
  function exposureFailure(req, url, server, config) {
11778
11836
  const remote = requestAddress(server, req);
11779
- const loopbackExempt = config.trustLoopback && (remote.hasRequestIp ? isLoopbackAddress(remote.address) : isLocalHostHeader(url.host, config.bindHosts)) && !isForwardedRequest(req.headers);
11837
+ const loopbackExempt = config.trustLoopback && (remote.hasRequestIp ? isLoopbackAddress(remote.address) : isLocalHostHeader(url.host, config.bindHost)) && !isForwardedRequest(req.headers);
11780
11838
  const role = keyRole(req, url, config);
11839
+ if (role === "device" && !isDeviceRoute(req.method, url.pathname + url.search)) {
11840
+ return jsonError(403, "Device keys only allow health and inference");
11841
+ }
11781
11842
  if (!role && !loopbackExempt) {
11782
11843
  return jsonError(401, "A proxy key is required for this request");
11783
11844
  }
11784
- if (!role && !isLocalHostHeader(req.headers.get("host"), config.bindHosts)) {
11845
+ if (!role && !isLocalHostHeader(req.headers.get("host"), config.bindHost)) {
11785
11846
  return jsonError(403, "Host header is not allowed for a loopback request");
11786
11847
  }
11787
11848
  if (url.pathname.startsWith("/api/")) {
@@ -11798,6 +11859,8 @@ function exposureFailure(req, url, server, config) {
11798
11859
  }
11799
11860
  var FORWARDED_HEADERS, LOOPBACK_HOSTS, MUTATING_METHODS;
11800
11861
  var init_exposure = __esm(() => {
11862
+ init_device_keys();
11863
+ init_inference_routes();
11801
11864
  FORWARDED_HEADERS = [
11802
11865
  "forwarded",
11803
11866
  "x-forwarded-for",
@@ -11951,10 +12014,10 @@ var init_bootstrap_runtime = __esm(() => {
11951
12014
  });
11952
12015
 
11953
12016
  // ../../packages/runtime-server/src/dashboard-assets.ts
11954
- import { readFileSync as readFileSync2 } from "fs";
11955
- import { dirname as dirname3, isAbsolute as isAbsolute2, join as join7, resolve as resolve2 } from "path";
12017
+ import { readFileSync as readFileSync3 } from "fs";
12018
+ import { dirname as dirname3, isAbsolute as isAbsolute3, join as join7, resolve as resolve2 } from "path";
11956
12019
  function resolveConfiguredPath(configuredPath) {
11957
- return isAbsolute2(configuredPath) ? configuredPath : resolve2(process.cwd(), configuredPath);
12020
+ return isAbsolute3(configuredPath) ? configuredPath : resolve2(process.cwd(), configuredPath);
11958
12021
  }
11959
12022
  function resolveDashboardManifestPath() {
11960
12023
  const configuredManifestPath = process.env[DASHBOARD_MANIFEST_PATH_ENV]?.trim();
@@ -11976,7 +12039,7 @@ function loadDashboardAssets() {
11976
12039
  }
11977
12040
  const manifestPath = resolveDashboardManifestPath();
11978
12041
  dashboardAssets = {
11979
- manifest: JSON.parse(readFileSync2(manifestPath, "utf8")),
12042
+ manifest: JSON.parse(readFileSync3(manifestPath, "utf8")),
11980
12043
  distDir: dirname3(manifestPath)
11981
12044
  };
11982
12045
  return dashboardAssets;
@@ -12065,7 +12128,6 @@ function createServerFetchHandler({
12065
12128
  withDashboard,
12066
12129
  exposureConfig = {
12067
12130
  bindHost: "127.0.0.1",
12068
- bindHosts: ["127.0.0.1"],
12069
12131
  trustLoopback: true
12070
12132
  },
12071
12133
  handleProxyRequest = handleProxy,
@@ -12186,7 +12248,7 @@ var init_startup_maintenance = __esm(() => {
12186
12248
  });
12187
12249
 
12188
12250
  // ../../packages/runtime-server/src/index.ts
12189
- import { isAbsolute as isAbsolute3 } from "path";
12251
+ import { isAbsolute as isAbsolute4 } from "path";
12190
12252
  var {serve } = globalThis.Bun;
12191
12253
  function stopRetentionMaintenance() {
12192
12254
  if (stopRetentionJob) {
@@ -12212,10 +12274,8 @@ async function stopServerRuntime() {
12212
12274
  serverStopPromise = (async () => {
12213
12275
  const errors2 = [];
12214
12276
  const activeServer = serverInstance;
12215
- const activeAdditionalServers = additionalServerInstances;
12216
12277
  const activeUnixServer = unixServerInstance;
12217
12278
  serverInstance = null;
12218
- additionalServerInstances = [];
12219
12279
  unixServerInstance = null;
12220
12280
  try {
12221
12281
  await activeUnixServer?.stop(true);
@@ -12227,13 +12287,6 @@ async function stopServerRuntime() {
12227
12287
  } catch (error) {
12228
12288
  errors2.push(toError("Failed to stop Bun server", error));
12229
12289
  }
12230
- for (const [index, server] of activeAdditionalServers.entries()) {
12231
- try {
12232
- await server.stop(true);
12233
- } catch (error) {
12234
- errors2.push(toError(`Failed to stop additional Bun server ${index + 1}`, error));
12235
- }
12236
- }
12237
12290
  stopRetentionMaintenance();
12238
12291
  try {
12239
12292
  await waitForProxyBackgroundTasks();
@@ -12266,7 +12319,7 @@ async function stopServerRuntime() {
12266
12319
  }
12267
12320
  }
12268
12321
  function startServer(options) {
12269
- if (options?.additionalUnixSocket !== undefined && !isAbsolute3(options.additionalUnixSocket)) {
12322
+ if (options?.additionalUnixSocket !== undefined && !isAbsolute4(options.additionalUnixSocket)) {
12270
12323
  throw new Error("Additional Unix socket must be an absolute path");
12271
12324
  }
12272
12325
  if (serverInstance) {
@@ -12312,16 +12365,6 @@ function startServer(options) {
12312
12365
  fetch: fetchHandler,
12313
12366
  websocket: websocketProxyHandler
12314
12367
  });
12315
- const activePort2 = serverInstance.port ?? runtimeConfig2.port;
12316
- for (const hostname of exposureConfig.bindHosts.slice(1)) {
12317
- additionalServerInstances.push(serve({
12318
- hostname,
12319
- port: activePort2,
12320
- idleTimeout: NETWORK.IDLE_TIMEOUT_MAX,
12321
- fetch: fetchHandler,
12322
- websocket: websocketProxyHandler
12323
- }));
12324
- }
12325
12368
  } catch (error) {
12326
12369
  stopServerRuntime().catch(() => {
12327
12370
  lifecycleLog.error("Failed to clean up after listener startup failure");
@@ -12357,7 +12400,7 @@ async function handleGracefulShutdown(signal) {
12357
12400
  process.exit(1);
12358
12401
  }
12359
12402
  }
12360
- var serverLog, lifecycleLog, serverInstance = null, additionalServerInstances, unixServerInstance = null, stopRetentionJob = null, serverStopPromise = null;
12403
+ var serverLog, lifecycleLog, serverInstance = null, unixServerInstance = null, stopRetentionJob = null, serverStopPromise = null;
12361
12404
  var init_src11 = __esm(() => {
12362
12405
  init_src9();
12363
12406
  init_src2();
@@ -12375,7 +12418,6 @@ var init_src11 = __esm(() => {
12375
12418
  lifecycleLog = new Logger("ServerLifecycle", 1 /* INFO */, {
12376
12419
  silentConsole: false
12377
12420
  });
12378
- additionalServerInstances = [];
12379
12421
  process.on("SIGINT", () => handleGracefulShutdown("SIGINT"));
12380
12422
  process.on("SIGTERM", () => handleGracefulShutdown("SIGTERM"));
12381
12423
  if (false) {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certalis/agent-smith",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "PROOF OF CONCEPT for ideation only: an experimental local proxy and provider pool for Claude Code and Codex",
5
5
  "license": "MIT",
6
6
  "author": "Certalis",
@@ -16,6 +16,7 @@
16
16
  "agent-smith": "dist/bin.js"
17
17
  },
18
18
  "exports": {
19
+ "./edge": "./dist/edge.js",
19
20
  "./server": "./dist/server.js",
20
21
  "./package.json": "./package.json"
21
22
  },