agent-office-cli 0.1.3 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-office-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Run and manage AI agent sessions locally, with optional relay to agentoffice.top",
5
5
  "license": "MIT",
6
6
  "engines": {
package/src/tunnel.js CHANGED
@@ -3,6 +3,42 @@ const { toSessionSummary } = require("./core");
3
3
 
4
4
  const RECONNECT_BASE_MS = 1000;
5
5
  const RECONNECT_MAX_MS = 30000;
6
+ const LOCAL_PROXY_STRIP_HEADERS = new Set([
7
+ "accept-encoding",
8
+ "connection",
9
+ "content-length",
10
+ "cookie",
11
+ "origin",
12
+ "referer",
13
+ "te",
14
+ "trailer",
15
+ "transfer-encoding",
16
+ "upgrade"
17
+ ]);
18
+
19
+ function shouldStripLocalProxyHeader(name) {
20
+ return (
21
+ LOCAL_PROXY_STRIP_HEADERS.has(name) ||
22
+ name.startsWith("proxy-") ||
23
+ name.startsWith("sec-") ||
24
+ name.startsWith("x-forwarded-")
25
+ );
26
+ }
27
+
28
+ function buildLocalRequestHeaders(headers, localServerUrl) {
29
+ const nextHeaders = {};
30
+
31
+ for (const [name, rawValue] of Object.entries(headers || {})) {
32
+ const key = String(name).toLowerCase();
33
+ if (shouldStripLocalProxyHeader(key) || rawValue == null) {
34
+ continue;
35
+ }
36
+ nextHeaders[key] = Array.isArray(rawValue) ? rawValue.join(", ") : String(rawValue);
37
+ }
38
+
39
+ nextHeaders.host = new URL(localServerUrl).host;
40
+ return nextHeaders;
41
+ }
6
42
 
7
43
  function createTunnelClient({ key, relayUrl, localServerUrl }) {
8
44
  let ws = null;
@@ -116,7 +152,7 @@ function createTunnelClient({ key, relayUrl, localServerUrl }) {
116
152
  const fetchUrl = `${localServerUrl}${msg.path}`;
117
153
  const fetchOptions = {
118
154
  method: msg.method || "GET",
119
- headers: { ...msg.headers, host: new URL(localServerUrl).host }
155
+ headers: buildLocalRequestHeaders(msg.headers, localServerUrl)
120
156
  };
121
157
  if (msg.body && msg.method !== "GET" && msg.method !== "HEAD") {
122
158
  fetchOptions.body = msg.body;
@@ -220,5 +256,6 @@ function createTunnelClient({ key, relayUrl, localServerUrl }) {
220
256
  }
221
257
 
222
258
  module.exports = {
259
+ buildLocalRequestHeaders,
223
260
  createTunnelClient
224
261
  };
@@ -0,0 +1,31 @@
1
+ const test = require("node:test");
2
+ const assert = require("node:assert/strict");
3
+
4
+ const { buildLocalRequestHeaders } = require("./tunnel");
5
+
6
+ test("buildLocalRequestHeaders strips browser-only proxy headers and rewrites host", () => {
7
+ const next = buildLocalRequestHeaders(
8
+ {
9
+ authorization: "Bearer token",
10
+ accept: "*/*",
11
+ "content-type": "application/json",
12
+ host: "agentoffice.top",
13
+ connection: "keep-alive",
14
+ "accept-encoding": "gzip, deflate, br, zstd",
15
+ "content-length": "123",
16
+ origin: "https://agentoffice.top",
17
+ referer: "https://agentoffice.top/office",
18
+ "sec-ch-ua": "\"Chromium\";v=\"146\"",
19
+ "sec-fetch-mode": "cors",
20
+ "x-forwarded-for": "203.0.113.10"
21
+ },
22
+ "http://127.0.0.1:8765"
23
+ );
24
+
25
+ assert.deepEqual(next, {
26
+ authorization: "Bearer token",
27
+ accept: "*/*",
28
+ "content-type": "application/json",
29
+ host: "127.0.0.1:8765"
30
+ });
31
+ });