@wrongstack/acp 0.296.2 → 0.296.4

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/index.js CHANGED
@@ -1206,8 +1206,9 @@ function toolToPriority(tool) {
1206
1206
 
1207
1207
  // src/agent/wrongstack-acp-agent.ts
1208
1208
  import { createServer } from "node:http";
1209
+ import { isIP } from "node:net";
1209
1210
  import { fileURLToPath } from "node:url";
1210
- import { writeErr as writeErr2 } from "@wrongstack/core/utils";
1211
+ import { expandIPv6, writeErr as writeErr2 } from "@wrongstack/core/utils";
1211
1212
  var WrongStackACPServer = class {
1212
1213
  transport;
1213
1214
  handler;
@@ -1263,7 +1264,10 @@ var WrongStackACPServer = class {
1263
1264
  async startHttp(port) {
1264
1265
  const host = this.options.host ?? "127.0.0.1";
1265
1266
  const handler = this.handler;
1266
- const authToken = this.options.authToken;
1267
+ const authToken = this.options.authToken?.trim();
1268
+ if (!authToken && !isLoopbackHost(host)) {
1269
+ throw new Error("ACP HTTP transport requires authToken for non-loopback hosts");
1270
+ }
1267
1271
  let httpChain = Promise.resolve();
1268
1272
  this.httpServer = createServer(async (req, res) => {
1269
1273
  if (authToken) {
@@ -1391,6 +1395,16 @@ function headerValue(value) {
1391
1395
  function requestPath(value) {
1392
1396
  return value ?? "/";
1393
1397
  }
1398
+ function isLoopbackHost(host) {
1399
+ const normalized = host.trim().toLowerCase();
1400
+ if (normalized === "localhost") return true;
1401
+ const literal = normalized.startsWith("[") && normalized.endsWith("]") ? normalized.slice(1, -1) : normalized;
1402
+ const version = isIP(literal);
1403
+ if (version === 4) return literal.startsWith("127.");
1404
+ if (version !== 6) return false;
1405
+ const groups = expandIPv6(literal);
1406
+ return groups !== null && groups.slice(0, 7).every((group) => group === 0) && groups[7] === 1;
1407
+ }
1394
1408
  async function main() {
1395
1409
  const server = new WrongStackACPServer();
1396
1410
  await server.start();