Files
agent/scripts/start-private-server.mjs

38 lines
1.9 KiB
JavaScript

import { createInterface } from "node:readline";
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
// Run from an interactive terminal with echo disabled. Never pass secrets in argv.
console.log('Provide one JSON line on hidden stdin: {"swadsToken":"…","llmKey":"…"}. Credentials stay in process memory.');
const reader = createInterface({ input: process.stdin });
let credentials;
try {
const line = await reader[Symbol.asyncIterator]().next();
credentials = JSON.parse(line.value);
if (typeof credentials.swadsToken !== "string" || !credentials.swadsToken || typeof credentials.llmKey !== "string" || !credentials.llmKey) throw new Error();
} catch {
console.error("Invalid credential input; nothing was written.");
process.exit(1);
} finally { reader.close(); }
const server = spawn(process.execPath, [fileURLToPath(new URL("../apps/server/dist/index.js", import.meta.url))], {
stdio: ["ignore", "inherit", "inherit"],
env: {
...process.env,
SWADS_MCP_TOKEN: credentials.swadsToken,
OPENAI_API_KEY: credentials.llmKey,
CMS_SUPABASE_PUBLISHABLE_KEY: typeof credentials.cmsPublishableKey === "string" ? credentials.cmsPublishableKey : "",
AGENT_PROVIDER: "compatible", AGENT_MODEL: "Qwen3.8-27B-FP8",
// This gateway recovered Skill/tool calls with Chat Completions during the live repair test.
LLM_API: "openai-completions", LLM_BASE_URL: "https://gateway.pencil-stub.com/v1",
// Verified against this gateway/model using synthetic image inputs.
AGENT_MODEL_SUPPORTS_IMAGES: "true", AGENT_MODEL_MAX_TOKENS: "8192",
SESSION_RUN_TIMEOUT_MS: "600000", APPROVAL_TIMEOUT_MS: "180000",
HOST: "127.0.0.1", PORT: "3001",
},
});
credentials = undefined;
console.log("Starting local server with private in-memory connections.");
for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => server.kill(signal));
server.on("exit", (code) => { process.exitCode = code ?? 0; });