Skip to content

A local plugin for image-heavy chats in Codex, Claude Code and other agents: earlier images stop going out with every message, and the model fetches the one it needs by its ID, also after compaction.

1.3 KB
Raw Blame
// A test-only transport: run the real engine against a plaintext loopback upstream.
// No credentials, real conversations, external TLS connections, or production hooks are used.
import net from "node:net";
import tls from "node:tls";
import { fileURLToPath } from "node:url";

const upstreamPort = Number(process.env.CAM_TEST_UPSTREAM_PORT);
if (!upstreamPort) throw new Error("missing synthetic upstream port");
// The proxy uses http.request over an already-connected TLS socket. A plain local socket exercises the same HTTP
// lifecycle; only the TLS handshake is replaced, in this isolated child process.
tls.connect = ((_options: unknown, callback: () => void) => net.connect(upstreamPort, "127.0.0.1", () => {
  const delay = Number(process.env.CAM_TEST_CONNECT_DELAY ?? 0);
  if (delay) setTimeout(callback, delay).unref(); else callback();
})) as typeof tls.connect;
const scriptUrl = new URL("../../plugin/src/proxy.ts", import.meta.url);
const script = fileURLToPath(scriptUrl);
// CAM_TEST_ENGINE_ARGS: more of the engine's own flags, e.g. --force-http.
const more = (process.env.CAM_TEST_ENGINE_ARGS ?? "").split(" ").filter(Boolean);
process.argv = [process.execPath, script, "--stay", "--port", process.env.CAM_TEST_PROXY_PORT!, ...more];
await import(scriptUrl.href);