// Shared config + session storage for the agent sidecar. // // The session file holds the agent's device token and its ECDH private key — it // IS the agent's identity, and (like the ANTHROPIC_API_KEY) it lives only on the // agent host, never on the lchat server. Keep it secret; back it up. import { readFileSync, writeFileSync, existsSync } from "node:fs"; import { fileURLToPath } from "node:url"; // The instance base URL, e.g. https://test.example.com. WS base is derived // (https -> wss, http -> ws). export const BASE = (process.env.LCHAT_BASE || "").replace(/\/$/, ""); export const WS_BASE = BASE.replace(/^http/, "ws"); // Whether the model brain is available. With no key the sidecar still runs its // deterministic side (welcomes + slash commands), so a helper "upgrades" from // BOT to AI exactly when a key is present — the badge follows this (runtime.mjs // self-declares kind), and non-command messages degrade to a commands hint. export const AI_ENABLED = !!(process.env.ANTHROPIC_API_KEY || "").trim(); export const AGENT_NAME = process.env.LCHAT_AGENT_NAME || "Claude"; // The app's user-facing name (the product is called Eleven; lchat is the // project/repo name). Bots refer to the app by this. export const APP_NAME = process.env.LCHAT_APP_NAME || "Eleven"; export const MODEL = process.env.LCHAT_MODEL || "claude-sonnet-5"; // The bare-name "am I being addressed?" gate in runtime.mjs — a tiny yes/no // call, so it always uses the cheapest model regardless of the bot's MODEL. export const CLASSIFIER_MODEL = process.env.LCHAT_CLASSIFIER_MODEL || "claude-haiku-4-5"; // Session lives next to this module by default so `node agent.mjs` works from // any cwd; override with LCHAT_SESSION. export const SESSION_PATH = process.env.LCHAT_SESSION || fileURLToPath(new URL("./session.json", import.meta.url)); export function requireBase() { if (!BASE) { console.error("Set LCHAT_BASE to your instance URL, e.g. https://test.example.com"); process.exit(1); } } export function loadSession() { return existsSync(SESSION_PATH) ? JSON.parse(readFileSync(SESSION_PATH, "utf8")) : null; } export function saveSession(s) { writeFileSync(SESSION_PATH, JSON.stringify(s, null, 2)); }