@wrongstack/acp 0.295.1 → 0.296.3

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.
@@ -1,7 +1,8 @@
1
1
  // src/agent/wrongstack-acp-agent.ts
2
2
  import { createServer } from "node:http";
3
+ import { isIP } from "node:net";
3
4
  import { fileURLToPath } from "node:url";
4
- import { writeErr as writeErr2 } from "@wrongstack/core/utils";
5
+ import { expandIPv6, writeErr as writeErr2 } from "@wrongstack/core/utils";
5
6
 
6
7
  // src/types/acp-v1.ts
7
8
  var ACP_PROTOCOL_VERSION = 1;
@@ -920,7 +921,10 @@ var WrongStackACPServer = class {
920
921
  async startHttp(port) {
921
922
  const host = this.options.host ?? "127.0.0.1";
922
923
  const handler = this.handler;
923
- const authToken = this.options.authToken;
924
+ const authToken = this.options.authToken?.trim();
925
+ if (!authToken && !isLoopbackHost(host)) {
926
+ throw new Error("ACP HTTP transport requires authToken for non-loopback hosts");
927
+ }
924
928
  let httpChain = Promise.resolve();
925
929
  this.httpServer = createServer(async (req, res) => {
926
930
  if (authToken) {
@@ -1048,7 +1052,22 @@ function headerValue(value) {
1048
1052
  function requestPath(value) {
1049
1053
  return value ?? "/";
1050
1054
  }
1051
- var wrongStackACPServerCoverage = { defaultEchoRunTurn, headerValue, requestPath };
1055
+ function isLoopbackHost(host) {
1056
+ const normalized = host.trim().toLowerCase();
1057
+ if (normalized === "localhost") return true;
1058
+ const literal = normalized.startsWith("[") && normalized.endsWith("]") ? normalized.slice(1, -1) : normalized;
1059
+ const version = isIP(literal);
1060
+ if (version === 4) return literal.startsWith("127.");
1061
+ if (version !== 6) return false;
1062
+ const groups = expandIPv6(literal);
1063
+ return groups !== null && groups.slice(0, 7).every((group) => group === 0) && groups[7] === 1;
1064
+ }
1065
+ var wrongStackACPServerCoverage = {
1066
+ defaultEchoRunTurn,
1067
+ headerValue,
1068
+ isLoopbackHost,
1069
+ requestPath
1070
+ };
1052
1071
  async function main() {
1053
1072
  const server = new WrongStackACPServer();
1054
1073
  await server.start();